@@ -649,81 +649,86 @@ public void testRetryRetainsFinalProfileAboveStatementThreshold(TStatusCode fina
649649 @ Test
650650 @ ResourceLock ("global" )
651651 public void testSuccessfulRetryRendersMergedProfileAndActualRows (@ TempDir Path profileDirectory ) throws Exception {
652- ProfileManager manager = ProfileManager .getInstance ();
653- connectContext .getSessionVariable ().enableProfile = true ;
654- connectContext .getSessionVariable ().autoProfileThresholdMs = 0 ;
655- TUniqueId firstQueryId = new TUniqueId (0x22040L , 5L );
656- TUniqueId retryQueryId = new TUniqueId (0x22040L , 6L );
657- connectContext .setQueryId (firstQueryId );
658- connectContext .setStartTime ();
659- StmtExecutor executor = new StmtExecutor (connectContext ,
660- analyzeAndGetStmtByNereids ("select 1" , connectContext ));
661- executor .getSummaryProfile ().setQueryBeginTime (System .currentTimeMillis ());
662- Profile profile = executor .getProfile ();
663- Statistics statistics = new Statistics (0 , Collections .emptyMap ());
664- PhysicalEmptyRelation physicalPlan = new PhysicalEmptyRelation (new RelationId (0 ), Collections .emptyList (),
665- Optional .empty (), null , PhysicalProperties .ANY , statistics );
666- int planNodeId = physicalPlan .getId ();
667- profile .setPhysicalPlan (physicalPlan );
668- ExecutionProfile failedExecution = new ExecutionProfile (firstQueryId , Collections .singletonList (0 ));
669- ExecutionProfile successfulExecution = new ExecutionProfile (retryQueryId , Collections .singletonList (0 ));
670- TQueryOptions queryOptions = new TQueryOptions ();
671- queryOptions .enable_profile = true ;
672-
673- try {
674- Coordinator firstCoord = Mockito .mock (Coordinator .class );
675- Mockito .when (firstCoord .getQueryOptions ()).thenReturn (queryOptions );
676- Mockito .when (firstCoord .getExecutionProfile ()).thenReturn (failedExecution );
677- profile .addExecutionProfile (failedExecution );
678- QeProcessorImpl .INSTANCE .registerQuery (firstQueryId , new QeProcessorImpl .QueryInfo (firstCoord ));
679- Assertions .assertTrue (failedExecution .updateProfile (
680- createBackendRowsProfile (firstQueryId , planNodeId , 1000 ),
681- new TNetworkAddress ("127.0.0.1" , 9060 ), true ).ok ());
682- executor .updateProfile (false );
683- executor .finalizeQuery (true );
652+ // Exercise storage synchronously: the global daemon can spill and release this completed
653+ // profile while the test is writing or reading it from its temporary directory.
654+ ProfileManager manager = new ProfileManager () { };
655+ try (MockedStatic <ProfileManager > managers = Mockito .mockStatic (ProfileManager .class )) {
656+ managers .when (ProfileManager ::getInstance ).thenReturn (manager );
657+ connectContext .getSessionVariable ().enableProfile = true ;
658+ connectContext .getSessionVariable ().autoProfileThresholdMs = 0 ;
659+ TUniqueId firstQueryId = new TUniqueId (0x22040L , 5L );
660+ TUniqueId retryQueryId = new TUniqueId (0x22040L , 6L );
661+ connectContext .setQueryId (firstQueryId );
662+ connectContext .setStartTime ();
663+ StmtExecutor executor = new StmtExecutor (connectContext ,
664+ analyzeAndGetStmtByNereids ("select 1" , connectContext ));
665+ executor .getSummaryProfile ().setQueryBeginTime (System .currentTimeMillis ());
666+ Profile profile = executor .getProfile ();
667+ Statistics statistics = new Statistics (0 , Collections .emptyMap ());
668+ PhysicalEmptyRelation physicalPlan = new PhysicalEmptyRelation (new RelationId (0 ), Collections .emptyList (),
669+ Optional .empty (), null , PhysicalProperties .ANY , statistics );
670+ int planNodeId = physicalPlan .getId ();
671+ profile .setPhysicalPlan (physicalPlan );
672+ ExecutionProfile failedExecution = new ExecutionProfile (firstQueryId , Collections .singletonList (0 ));
673+ ExecutionProfile successfulExecution = new ExecutionProfile (retryQueryId , Collections .singletonList (0 ));
674+ TQueryOptions queryOptions = new TQueryOptions ();
675+ queryOptions .enable_profile = true ;
684676
685- connectContext .setQueryId (retryQueryId );
686- Coordinator retryCoord = Mockito .mock (Coordinator .class );
687- Mockito .when (retryCoord .getQueryOptions ()).thenReturn (queryOptions );
688- Mockito .when (retryCoord .getExecutionProfile ()).thenReturn (successfulExecution );
689- Mockito .when (retryCoord .getExecStatus ()).thenReturn (Status .OK );
690- executor .setCoord (retryCoord );
691- profile .addExecutionProfile (successfulExecution );
692- QeProcessorImpl .INSTANCE .registerQuery (retryQueryId , new QeProcessorImpl .QueryInfo (retryCoord ));
693- successfulExecution .addFragmentBackend (0 , 1L );
694- successfulExecution .addFragmentBackend (0 , 2L );
695- Assertions .assertTrue (successfulExecution .updateProfile (
696- createBackendRowsProfile (retryQueryId , planNodeId , 17 ),
697- new TNetworkAddress ("127.0.0.1" , 9060 ), true ).ok ());
698- Assertions .assertTrue (successfulExecution .updateProfile (
699- createBackendRowsProfile (retryQueryId , planNodeId , 25 ),
700- new TNetworkAddress ("127.0.0.2" , 9060 ), true ).ok ());
701- Assertions .assertTrue (successfulExecution .isCompleted ());
702- executor .updateProfile (false );
703- executor .finalizeQuery ();
704- Assertions .assertNotNull (manager .findProfileElementObject (profile .getId ()));
705-
706- String profileText = profile .getProfileByLevel ();
707- Assertions .assertTrue (profileText .contains ("MergedProfile:" ));
708- Assertions .assertTrue (profileText .contains ("Pipeline 0(instance_num=2)" ));
709- Assertions .assertTrue (profileText .contains ("RowsProduced: sum 42" ));
710- Assertions .assertFalse (profileText .contains ("build merged simple profile failed" ));
711- Assertions .assertFalse (profileText .contains ("DetailProfile(" + DebugUtil .printId (firstQueryId ) + ")" ));
712- Assertions .assertTrue (profileText .contains ("DetailProfile(" + DebugUtil .printId (retryQueryId ) + ")" ));
713- Assertions .assertEquals (42L , profile .rowsProducedMap .get (String .valueOf (planNodeId )));
714- Assertions .assertEquals (42L , statistics .getActualRowCount ());
677+ try {
678+ Coordinator firstCoord = Mockito .mock (Coordinator .class );
679+ Mockito .when (firstCoord .getQueryOptions ()).thenReturn (queryOptions );
680+ Mockito .when (firstCoord .getExecutionProfile ()).thenReturn (failedExecution );
681+ profile .addExecutionProfile (failedExecution );
682+ QeProcessorImpl .INSTANCE .registerQuery (firstQueryId , new QeProcessorImpl .QueryInfo (firstCoord ));
683+ Assertions .assertTrue (failedExecution .updateProfile (
684+ createBackendRowsProfile (firstQueryId , planNodeId , 1000 ),
685+ new TNetworkAddress ("127.0.0.1" , 9060 ), true ).ok ());
686+ executor .updateProfile (false );
687+ executor .finalizeQuery (true );
688+
689+ connectContext .setQueryId (retryQueryId );
690+ Coordinator retryCoord = Mockito .mock (Coordinator .class );
691+ Mockito .when (retryCoord .getQueryOptions ()).thenReturn (queryOptions );
692+ Mockito .when (retryCoord .getExecutionProfile ()).thenReturn (successfulExecution );
693+ Mockito .when (retryCoord .getExecStatus ()).thenReturn (Status .OK );
694+ executor .setCoord (retryCoord );
695+ profile .addExecutionProfile (successfulExecution );
696+ QeProcessorImpl .INSTANCE .registerQuery (retryQueryId , new QeProcessorImpl .QueryInfo (retryCoord ));
697+ successfulExecution .addFragmentBackend (0 , 1L );
698+ successfulExecution .addFragmentBackend (0 , 2L );
699+ Assertions .assertTrue (successfulExecution .updateProfile (
700+ createBackendRowsProfile (retryQueryId , planNodeId , 17 ),
701+ new TNetworkAddress ("127.0.0.1" , 9060 ), true ).ok ());
702+ Assertions .assertTrue (successfulExecution .updateProfile (
703+ createBackendRowsProfile (retryQueryId , planNodeId , 25 ),
704+ new TNetworkAddress ("127.0.0.2" , 9060 ), true ).ok ());
705+ Assertions .assertTrue (successfulExecution .isCompleted ());
706+ executor .updateProfile (false );
707+ executor .finalizeQuery ();
708+ Assertions .assertNotNull (manager .findProfileElementObject (profile .getId ()));
715709
716- profile .writeToStorage (profileDirectory .toString ());
717- Profile storedProfile = Profile .read (profile .getProfileStoragePath ());
718- Assertions .assertNotNull (storedProfile );
719- String storedText = storedProfile .getProfileByLevel ();
720- Assertions .assertTrue (storedText .contains ("MergedProfile:" ));
721- Assertions .assertTrue (storedText .contains ("RowsProduced: sum 42" ));
722- Assertions .assertFalse (storedText .contains ("DetailProfile(" + DebugUtil .printId (firstQueryId ) + ")" ));
723- } finally {
724- QeProcessorImpl .INSTANCE .unregisterQuery (firstQueryId );
725- QeProcessorImpl .INSTANCE .unregisterQuery (retryQueryId );
726- manager .removeProfile (profile );
710+ String profileText = profile .getProfileByLevel ();
711+ Assertions .assertTrue (profileText .contains ("MergedProfile:" ));
712+ Assertions .assertTrue (profileText .contains ("Pipeline 0(instance_num=2)" ));
713+ Assertions .assertTrue (profileText .contains ("RowsProduced: sum 42" ));
714+ Assertions .assertFalse (profileText .contains ("build merged simple profile failed" ));
715+ Assertions .assertFalse (profileText .contains ("DetailProfile(" + DebugUtil .printId (firstQueryId ) + ")" ));
716+ Assertions .assertTrue (profileText .contains ("DetailProfile(" + DebugUtil .printId (retryQueryId ) + ")" ));
717+ Assertions .assertEquals (42L , profile .rowsProducedMap .get (String .valueOf (planNodeId )));
718+ Assertions .assertEquals (42L , statistics .getActualRowCount ());
719+
720+ profile .writeToStorage (profileDirectory .toString ());
721+ Profile storedProfile = Profile .read (profile .getProfileStoragePath ());
722+ Assertions .assertNotNull (storedProfile );
723+ String storedText = storedProfile .getProfileByLevel ();
724+ Assertions .assertTrue (storedText .contains ("MergedProfile:" ), storedText );
725+ Assertions .assertTrue (storedText .contains ("RowsProduced: sum 42" ));
726+ Assertions .assertFalse (storedText .contains ("DetailProfile(" + DebugUtil .printId (firstQueryId ) + ")" ));
727+ } finally {
728+ QeProcessorImpl .INSTANCE .unregisterQuery (firstQueryId );
729+ QeProcessorImpl .INSTANCE .unregisterQuery (retryQueryId );
730+ manager .removeProfile (profile );
731+ }
727732 }
728733 }
729734
0 commit comments