DomGarguilo commented on code in PR #5801: URL: https://github.com/apache/accumulo/pull/5801#discussion_r2279656077
########## test/src/main/java/org/apache/accumulo/test/TableOperationsIT.java: ########## @@ -202,6 +204,60 @@ public void createTable() throws TableExistsException, AccumuloException, accumuloClient.tableOperations().delete(tableName); } + @Test + public void testDefendAgainstThreadsCreateSameTableNameConcurrently() + throws ExecutionException, InterruptedException { + + ExecutorService pool = Executors.newFixedThreadPool(64); Review Comment: Good idea then could use this constant for the inner loop iteration count, thread pool size and the CountDownLatch size ########## test/src/main/java/org/apache/accumulo/test/TableOperationsIT.java: ########## @@ -202,6 +204,60 @@ public void createTable() throws TableExistsException, AccumuloException, accumuloClient.tableOperations().delete(tableName); } + @Test + public void testDefendAgainstThreadsCreateSameTableNameConcurrently() + throws ExecutionException, InterruptedException { + + ExecutorService pool = Executors.newFixedThreadPool(64); + + for (int i = 0; i < 30; i++) { + String tablename = "t" + i; + List<Future<String>> futureList = new ArrayList<>(); + + CountDownLatch startSignal = new CountDownLatch(1); + CountDownLatch doneSignal = new CountDownLatch(10); + + for (int j = 0; j < 10; j++) { + Future<String> future = pool.submit(() -> { + String result; + try { + startSignal.await(); + accumuloClient.tableOperations().create(tablename); + result = "success"; + } catch (TableExistsException e) { + result = "fail"; + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + result = "fail"; + } finally { + doneSignal.countDown(); + } + return result; + }); + futureList.add(future); + } + + startSignal.countDown(); + + doneSignal.await(); + + int taskSucceeded = 0; + int taskFailed = 0; + for (Future<String> result : futureList) { + if (result.get().equals("success")) { + taskSucceeded++; + } else { + taskFailed++; + } + } Review Comment: This could probably be simplified by returning a boolean instead of a string from the Future tasks ########## test/src/main/java/org/apache/accumulo/test/TableOperationsIT.java: ########## @@ -202,6 +204,60 @@ public void createTable() throws TableExistsException, AccumuloException, accumuloClient.tableOperations().delete(tableName); } + @Test + public void testDefendAgainstThreadsCreateSameTableNameConcurrently() + throws ExecutionException, InterruptedException { + + ExecutorService pool = Executors.newFixedThreadPool(64); + + for (int i = 0; i < 30; i++) { + String tablename = "t" + i; + List<Future<String>> futureList = new ArrayList<>(); + + CountDownLatch startSignal = new CountDownLatch(1); + CountDownLatch doneSignal = new CountDownLatch(10); + + for (int j = 0; j < 10; j++) { + Future<String> future = pool.submit(() -> { + String result; + try { + startSignal.await(); + accumuloClient.tableOperations().create(tablename); + result = "success"; + } catch (TableExistsException e) { + result = "fail"; + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + result = "fail"; + } finally { + doneSignal.countDown(); + } + return result; + }); + futureList.add(future); + } + + startSignal.countDown(); Review Comment: I think things might be okay here actually. I think once we get to `startSignal.countDown()` all of the 10 threads are guarenteed to be waiting at `await()` ########## test/src/main/java/org/apache/accumulo/test/TableOperationsIT.java: ########## @@ -202,6 +204,60 @@ public void createTable() throws TableExistsException, AccumuloException, accumuloClient.tableOperations().delete(tableName); } + @Test + public void testDefendAgainstThreadsCreateSameTableNameConcurrently() + throws ExecutionException, InterruptedException { + + ExecutorService pool = Executors.newFixedThreadPool(64); + + for (int i = 0; i < 30; i++) { + String tablename = "t" + i; Review Comment: Could simplify with: ```suggestion for (String tablename : getUniqueNames(30)) { ``` -- 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. To unsubscribe, e-mail: notifications-unsubscr...@accumulo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org