From 855de30da1e3065ea7994614175448972b13620b Mon Sep 17 00:00:00 2001 From: datomo Date: Tue, 10 Dec 2024 14:35:30 +0100 Subject: [PATCH] added better tracking of concurrent alg serialization --- .../db/routing/UiRoutingPageUtil.java | 23 +++++++++++++-- .../db/polyalg/PolyAlgParsingTest.java | 29 ++++++++++--------- 2 files changed, 37 insertions(+), 15 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 c3f366bb56..2c8b30ce62 100644 --- a/dbms/src/main/java/org/polypheny/db/routing/UiRoutingPageUtil.java +++ b/dbms/src/main/java/org/polypheny/db/routing/UiRoutingPageUtil.java @@ -21,8 +21,12 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.collect.ImmutableList; import java.util.List; +import java.util.concurrent.CompletionService; +import java.util.concurrent.ExecutorCompletionService; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.atomic.AtomicInteger; import lombok.extern.slf4j.Slf4j; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.AlgRoot; @@ -52,7 +56,13 @@ @Slf4j public class UiRoutingPageUtil { - private static final ExecutorService executorService = Executors.newFixedThreadPool( 10 ); + private static final int RUNNERS = 10; + private static final ExecutorService executorService = Executors.newFixedThreadPool( RUNNERS ); + private static final AtomicInteger counter = new AtomicInteger( 0 ); + + public static int runningTasks() { + return counter.get(); + } public static void outputSingleResult( Plan plan, InformationManager queryAnalyzer, long stmtIdx, boolean attachTextualPlan ) { @@ -69,7 +79,16 @@ public static void outputSingleResult( Plan plan, InformationManager queryAnalyz public static void addPhysicalPlanPage( AlgNode optimalNode, InformationManager queryAnalyzer, long stmtIdx, boolean attachTextualPlan ) { - executorService.submit( () -> addRoutedPolyPlanPage( optimalNode, queryAnalyzer, stmtIdx, true, attachTextualPlan ) ); + executorService.submit( () -> { + UiRoutingPageUtil.counter.incrementAndGet(); + try { + addRoutedPolyPlanPage( optimalNode, queryAnalyzer, stmtIdx, true, attachTextualPlan ); + }finally { + UiRoutingPageUtil.counter.decrementAndGet(); + } + + + } ); } 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 f3c2aabeef..2f75621657 100644 --- a/dbms/src/test/java/org/polypheny/db/polyalg/PolyAlgParsingTest.java +++ b/dbms/src/test/java/org/polypheny/db/polyalg/PolyAlgParsingTest.java @@ -64,12 +64,14 @@ import org.polypheny.db.processing.QueryContext; import org.polypheny.db.processing.QueryContext.TranslatedQueryContext; import org.polypheny.db.rex.RexBuilder; +import org.polypheny.db.routing.UiRoutingPageUtil; import org.polypheny.db.transaction.Statement; import org.polypheny.db.transaction.Transaction; import org.polypheny.db.transaction.TransactionException; import org.polypheny.db.transaction.TransactionManager; import org.polypheny.db.transaction.TransactionManagerImpl; import org.polypheny.db.type.entity.PolyValue; +import org.polypheny.db.webui.UiTestingConfigPage; @SuppressWarnings("SqlNoDataSourceInspection") @@ -186,23 +188,24 @@ private static void testQueryRoundTrip( String query, QueryLanguage ql, String n String logical = null, allocation = null, physical = null; - int tries = 3; + int tries = 5; 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(); - } + while ( UiRoutingPageUtil.runningTasks() > 0 && tries-- > 0 ) { + Thread.sleep( 2000 ); + } + if( tries == 0 ) { + throw new RuntimeException( "Took too long to set all plans" ); + } + + 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( 2000 ); } assertNotNull( logical );