ashutosh-bapat commented on a change in pull request #669: HIVE-21864:
LlapBaseInputFormat#closeAll() throws ConcurrentModificationException
URL: https://github.com/apache/hive/pull/669#discussion_r293660724
##########
File path:
itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniLlapArrow.java
##########
@@ -427,5 +437,85 @@ public void testKillQueryByTagOwner() throws Exception {
assertNotNull("tExecute", tExecuteHolder.throwable);
assertNull("tCancel", tKillHolder.throwable);
}
+
+ @Test
+ public void testAddCloseCloseAllConnections() throws Exception {
+ System.out.println("BaseJdbcWithMiniLlap.testAddCloseCloseAllConnections");
+
+ createTestTable("testtab1");
+
+ String url = miniHS2.getJdbcURL();
+ String user = System.getProperty("user.name");
+ String pwd = user;
+
+ InputFormat<NullWritable, Row> inputFormat = getInputFormat();
+
+ // Get splits
+ JobConf job = new JobConf(conf);
+ job.set(LlapBaseInputFormat.URL_KEY, url);
+ job.set(LlapBaseInputFormat.USER_KEY, user);
+ job.set(LlapBaseInputFormat.PWD_KEY, pwd);
+ job.set(LlapBaseInputFormat.QUERY_KEY, "select * from testtab1");
+
+ final String[] handleIds = IntStream.range(0, 20).boxed().map(i ->
"handleId-" + i).toArray(String[]::new);
+ final Iterator<String> handleIdsItr =
Iterables.cycle(handleIds).iterator();
+
+ final ExceptionHolder exceptionHolder = new ExceptionHolder();
+
+ // addConnThread thread will keep adding connections
+ // closeConnThread thread tries close connection(s) associated to
handleIds, one at a time
+ // closeAllConnThread thread tries to close All at once.
+
+ final int numIterations = 100;
+ Thread addConnThread = new Thread(() -> executeNTimes(() -> {
+ String handleId = handleIdsItr.next();
+ job.set(LlapBaseInputFormat.HANDLE_ID, handleId);
+ InputSplit[] splits = inputFormat.getSplits(job, 1);
+ assertTrue(splits.length > 0);
+ return null;
+ }, numIterations, 1, exceptionHolder));
+
+ Thread closeConnThread = new Thread(() -> executeNTimes(() -> {
+ String handleId = handleIdsItr.next();
+ LlapBaseInputFormat.close(handleId);
+ return null;
+ }, numIterations, 2, exceptionHolder));
+
Review comment:
Shouldn't you use two separate iterators on handleIds one for addConn and
other for closeConn? The code here is using the same iterator which means two
consecutive handleIds.next() one in addConn and other in closeConn will return
different ids, thus trying to close a connection which wasn't created. Given
the infinite cycle nature of iterator, that may not be seen as a problem but
it's better to use two different iterators.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]