This is an automated email from the ASF dual-hosted git repository. sankarh pushed a commit to branch branch-3 in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/branch-3 by this push: new fe844e8950b HIVE-27548: Backport HIVE-22275: OperationManager.queryIdOperation does not properly clean up multiple queryIds fe844e8950b is described below commit fe844e8950b8b69999c493c551b69af790d68e01 Author: Aman Raj <104416558+amanraj2...@users.noreply.github.com> AuthorDate: Mon Aug 14 12:56:02 2023 +0530 HIVE-27548: Backport HIVE-22275: OperationManager.queryIdOperation does not properly clean up multiple queryIds Signed-off-by: Sankar Hariappan <sank...@apache.org> Closes (#4531) --- .../service/cli/session/TestSessionCleanup.java | 36 +++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/service/src/test/org/apache/hive/service/cli/session/TestSessionCleanup.java b/service/src/test/org/apache/hive/service/cli/session/TestSessionCleanup.java index 487a5d492d5..51ce2c2426d 100644 --- a/service/src/test/org/apache/hive/service/cli/session/TestSessionCleanup.java +++ b/service/src/test/org/apache/hive/service/cli/session/TestSessionCleanup.java @@ -25,22 +25,38 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; -import junit.framework.TestCase; + import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.conf.HiveConf.ConfVars; +import org.apache.hive.service.cli.CLIService; +import org.apache.hive.service.cli.OperationHandle; import org.apache.hive.service.cli.SessionHandle; import org.apache.hive.service.cli.thrift.EmbeddedThriftBinaryCLIService; import org.apache.hive.service.cli.thrift.ThriftCLIServiceClient; import org.junit.Assert; import org.junit.Test; -public class TestSessionCleanup extends TestCase { +/** + * TestSessionCleanup. + */ +public class TestSessionCleanup { + // Create subclass of EmbeddedThriftBinaryCLIService, just so we can get an accessor to the CLIService. + // Needed for access to the OperationManager. + private class MyEmbeddedThriftBinaryCLIService extends EmbeddedThriftBinaryCLIService { + public MyEmbeddedThriftBinaryCLIService() { + super(); + } + + public CLIService getCliService() { + return cliService; + } + } @Test // This is to test session temporary files are cleaned up after HIVE-11768 public void testTempSessionFileCleanup() throws Exception { - EmbeddedThriftBinaryCLIService service = new EmbeddedThriftBinaryCLIService(); + MyEmbeddedThriftBinaryCLIService service = new MyEmbeddedThriftBinaryCLIService(); HiveConf hiveConf = new HiveConf(); hiveConf .setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, @@ -51,7 +67,12 @@ public class TestSessionCleanup extends TestCase { Set<String> existingPipeoutFiles = new HashSet<String>(Arrays.asList(getPipeoutFiles())); SessionHandle sessionHandle = client.openSession("user1", "foobar", Collections.<String, String>emptyMap()); - client.executeStatement(sessionHandle, "set a=b", null); + OperationHandle opHandle1 = client.executeStatement(sessionHandle, "set a=b", null); + String queryId1 = service.getCliService().getQueryId(opHandle1.toTOperationHandle()); + Assert.assertNotNull(queryId1); + OperationHandle opHandle2 = client.executeStatement(sessionHandle, "set b=c", null); + String queryId2 = service.getCliService().getQueryId(opHandle2.toTOperationHandle()); + Assert.assertNotNull(queryId2); File operationLogRootDir = new File( new HiveConf().getVar(ConfVars.HIVE_SERVER2_LOGGING_OPERATION_LOG_LOCATION)); Assert.assertNotEquals(operationLogRootDir.list().length, 0); @@ -64,6 +85,13 @@ public class TestSessionCleanup extends TestCase { Set<String> finalPipeoutFiles = new HashSet<String>(Arrays.asList(getPipeoutFiles())); finalPipeoutFiles.removeAll(existingPipeoutFiles); Assert.assertTrue(finalPipeoutFiles.isEmpty()); + + // Verify both operationHandles are no longer held by the OperationManager + Assert.assertEquals(0, service.getCliService().getSessionManager().getOperations().size()); + + // Verify both queryIds are no longer held by the OperationManager + Assert.assertNull(service.getCliService().getSessionManager().getOperationManager().getOperationByQueryId(queryId2)); + Assert.assertNull(service.getCliService().getSessionManager().getOperationManager().getOperationByQueryId(queryId1)); } private String[] getPipeoutFiles() {