From 2be6caa554e9cac115668d82d6893f9a1f69c197 Mon Sep 17 00:00:00 2001 From: datomo Date: Tue, 10 Dec 2024 09:14:18 +0100 Subject: [PATCH] added executor pool for concurrently setting the poly algebra, and added handling for concurrent delays for testing --- .../db/routing/UiRoutingPageUtil.java | 6 +++- .../db/polyalg/PolyAlgParsingTest.java | 33 ++++++++++++------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/dbms/src/main/java/org/polypheny/db/routing/UiRoutingPageUtil.java b/dbms/src/main/java/org/polypheny/db/routing/UiRoutingPageUtil.java index 21604a8922..c3f366bb56 100644 --- a/dbms/src/main/java/org/polypheny/db/routing/UiRoutingPageUtil.java +++ b/dbms/src/main/java/org/polypheny/db/routing/UiRoutingPageUtil.java @@ -21,6 +21,8 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.collect.ImmutableList; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import lombok.extern.slf4j.Slf4j; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.AlgRoot; @@ -50,6 +52,8 @@ @Slf4j public class UiRoutingPageUtil { + private static final ExecutorService executorService = Executors.newFixedThreadPool( 10 ); + public static void outputSingleResult( Plan plan, InformationManager queryAnalyzer, long stmtIdx, boolean attachTextualPlan ) { addPhysicalPlanPage( plan.optimalNode(), queryAnalyzer, stmtIdx, attachTextualPlan ); @@ -65,7 +69,7 @@ public static void outputSingleResult( Plan plan, InformationManager queryAnalyz public static void addPhysicalPlanPage( AlgNode optimalNode, InformationManager queryAnalyzer, long stmtIdx, boolean attachTextualPlan ) { - new Thread( () -> addRoutedPolyPlanPage( optimalNode, queryAnalyzer, stmtIdx, true, attachTextualPlan ) ).start(); + executorService.submit( () -> addRoutedPolyPlanPage( optimalNode, queryAnalyzer, stmtIdx, true, attachTextualPlan ) ); } diff --git a/dbms/src/test/java/org/polypheny/db/polyalg/PolyAlgParsingTest.java b/dbms/src/test/java/org/polypheny/db/polyalg/PolyAlgParsingTest.java index 26fab3cd67..8896b940f2 100644 --- a/dbms/src/test/java/org/polypheny/db/polyalg/PolyAlgParsingTest.java +++ b/dbms/src/test/java/org/polypheny/db/polyalg/PolyAlgParsingTest.java @@ -48,7 +48,6 @@ import org.polypheny.db.algebra.polyalg.parser.nodes.PolyAlgNode; import org.polypheny.db.algebra.type.AlgDataTypeFactory; import org.polypheny.db.catalog.Catalog; -import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.cypher.CypherTestTemplate; @@ -85,7 +84,6 @@ public class PolyAlgParsingTest { @BeforeAll public static void start() throws SQLException { - //noinspection ResultOfMethodCallIgnored testHelper = TestHelper.getInstance(); addTestData(); @@ -187,21 +185,33 @@ private static void testQueryRoundTrip( String query, QueryLanguage ql, String n String result = getResultAsString( executedContexts, ql.dataModel() ); String logical = null, allocation = null, physical = null; - for ( Information info : transaction.getQueryAnalyzer().getInformationArray() ) { - if ( info instanceof InformationPolyAlg polyInfo ) { - switch ( PlanType.valueOf( polyInfo.planType ) ) { - case LOGICAL -> logical = polyInfo.getTextualPolyAlg(); - case ALLOCATION -> allocation = polyInfo.getTextualPolyAlg(); - case PHYSICAL -> physical = polyInfo.getTextualPolyAlg(); + + int tries = 3; + try { + // plans are serialized in a separate thread, which might take some time + for ( int i = 0; i < tries; i++ ) { + for ( Information info : transaction.getQueryAnalyzer().getInformationArray() ) { + if ( info instanceof InformationPolyAlg polyInfo ) { + switch ( PlanType.valueOf( polyInfo.planType ) ) { + case LOGICAL -> logical = polyInfo.getTextualPolyAlg(); + case ALLOCATION -> allocation = polyInfo.getTextualPolyAlg(); + case PHYSICAL -> physical = polyInfo.getTextualPolyAlg(); + } + } } + if ( logical != null && allocation != null && physical != null ) { + break; + } + Thread.sleep( 500 ); } - } - try { + assertNotNull( logical ); assertNotNull( allocation ); assertNotNull( physical ); // Physical is not yet tested further since it is only partially implemented - }finally { + } catch ( InterruptedException e ) { + throw new RuntimeException( e ); + } finally { transaction.commit(); // execute PolyAlg creates new transaction, as long as only DQLs are tested like this } if ( transactionManager.getNumberOfActiveTransactions() > 0 ) { @@ -215,7 +225,6 @@ private static void testQueryRoundTrip( String query, QueryLanguage ql, String n String resultFromAllocation = executePolyAlg( allocation, PlanType.ALLOCATION, ql ); assertEquals( result, resultFromAllocation, "Result from query does not match result when executing the allocation plan." ); - }