From 47b9f7753015136ad7cdb3dba0a9771e771c9e11 Mon Sep 17 00:00:00 2001 From: Mitsunori Komatsu Date: Wed, 19 Jun 2024 18:27:08 +0900 Subject: [PATCH] Backport to branch(3.11): Reduce the number of concurrent DDLs from 10 to 1 for Cosmos DB in the integration tests (#1931) Co-authored-by: Toshihiro Suzuki --- ...tipleClusteringKeyScanIntegrationTest.java | 5 ++++ ...osMultiplePartitionKeyIntegrationTest.java | 5 ++++ ...eClusteringKeyScanIntegrationTestBase.java | 28 ++++++++++++++++--- ...ltiplePartitionKeyIntegrationTestBase.java | 28 ++++++++++++++++--- 4 files changed, 58 insertions(+), 8 deletions(-) diff --git a/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosMultipleClusteringKeyScanIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosMultipleClusteringKeyScanIntegrationTest.java index fe6be83529..080653ee4a 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosMultipleClusteringKeyScanIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosMultipleClusteringKeyScanIntegrationTest.java @@ -46,6 +46,11 @@ protected int getThreadNum() { return 3; } + @Override + protected boolean isParallelDdlSupported() { + return false; + } + @Override protected Map getCreationOptions() { return CosmosEnv.getCreationOptions(); diff --git a/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosMultiplePartitionKeyIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosMultiplePartitionKeyIntegrationTest.java index 3cff4464e6..0d7e4309b7 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosMultiplePartitionKeyIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosMultiplePartitionKeyIntegrationTest.java @@ -24,6 +24,11 @@ protected int getThreadNum() { return 3; } + @Override + protected boolean isParallelDdlSupported() { + return false; + } + @Override protected Map getCreationOptions() { return CosmosEnv.getCreationOptions(); diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultipleClusteringKeyScanIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultipleClusteringKeyScanIntegrationTestBase.java index bc46e9fa33..24a39e5355 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultipleClusteringKeyScanIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultipleClusteringKeyScanIntegrationTestBase.java @@ -110,6 +110,10 @@ protected int getThreadNum() { return THREAD_NUM; } + protected boolean isParallelDdlSupported() { + return true; + } + private void createTables() throws java.util.concurrent.ExecutionException, InterruptedException { List> testCallables = new ArrayList<>(); @@ -139,8 +143,8 @@ private void createTables() throws java.util.concurrent.ExecutionException, Inte // We firstly execute the first one and then the rest. This is because the first table creation // creates the metadata table, and this process can't be handled in multiple threads/processes // at the same time. - executeInParallel(testCallables.subList(0, 1)); - executeInParallel(testCallables.subList(1, testCallables.size())); + executeDdls(testCallables.subList(0, 1)); + executeDdls(testCallables.subList(1, testCallables.size())); } protected Map getCreationOptions() { @@ -210,8 +214,8 @@ private void dropTables() throws java.util.concurrent.ExecutionException, Interr // We firstly execute the callables without the last one. And then we execute the last one. This // is because the last table deletion deletes the metadata table, and this process can't be // handled in multiple threads/processes at the same time. - executeInParallel(testCallables.subList(0, testCallables.size() - 1)); - executeInParallel(testCallables.subList(testCallables.size() - 1, testCallables.size())); + executeDdls(testCallables.subList(0, testCallables.size() - 1)); + executeDdls(testCallables.subList(testCallables.size() - 1, testCallables.size())); } private void truncateTable( @@ -2025,6 +2029,22 @@ private void executeInParallel(TestForSecondClusteringKeyScan test) executeInParallel(testCallables); } + private void executeDdls(List> ddls) + throws InterruptedException, java.util.concurrent.ExecutionException { + if (isParallelDdlSupported()) { + executeInParallel(ddls); + } else { + ddls.forEach( + ddl -> { + try { + ddl.call(); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } + } + private void executeInParallel(List> testCallables) throws InterruptedException, java.util.concurrent.ExecutionException { List> futures = executorService.invokeAll(testCallables); diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java index dbfdba548e..690b6c76db 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java @@ -92,6 +92,10 @@ protected int getThreadNum() { return THREAD_NUM; } + protected boolean isParallelDdlSupported() { + return true; + } + private void createTables() throws java.util.concurrent.ExecutionException, InterruptedException { List> testCallables = new ArrayList<>(); @@ -111,8 +115,8 @@ private void createTables() throws java.util.concurrent.ExecutionException, Inte // We firstly execute the first one and then the rest. This is because the first table creation // creates the metadata table, and this process can't be handled in multiple threads/processes // at the same time. - executeInParallel(testCallables.subList(0, 1)); - executeInParallel(testCallables.subList(1, testCallables.size())); + executeDdls(testCallables.subList(0, 1)); + executeDdls(testCallables.subList(1, testCallables.size())); } protected Map getCreationOptions() { @@ -162,8 +166,8 @@ private void dropTables() throws java.util.concurrent.ExecutionException, Interr // We firstly execute the callables without the last one. And then we execute the last one. This // is because the last table deletion deletes the metadata table, and this process can't be // handled in multiple threads/processes at the same time. - executeInParallel(testCallables.subList(0, testCallables.size() - 1)); - executeInParallel(testCallables.subList(testCallables.size() - 1, testCallables.size())); + executeDdls(testCallables.subList(0, testCallables.size() - 1)); + executeDdls(testCallables.subList(testCallables.size() - 1, testCallables.size())); } private void truncateTable(DataType firstPartitionKeyType, DataType secondPartitionKeyType) @@ -181,6 +185,22 @@ private String getNamespaceName(DataType firstPartitionKeyType) { return namespaceBaseName + firstPartitionKeyType; } + private void executeDdls(List> ddls) + throws InterruptedException, java.util.concurrent.ExecutionException { + if (isParallelDdlSupported()) { + executeInParallel(ddls); + } else { + ddls.forEach( + ddl -> { + try { + ddl.call(); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } + } + private void executeInParallel(List> testCallables) throws InterruptedException, java.util.concurrent.ExecutionException { List> futures = executorService.invokeAll(testCallables);