diff --git a/core/src/integration-test/java/com/scalar/db/storage/objectstorage/ConsensusCommitAdminIntegrationTestWithObjectStorage.java b/core/src/integration-test/java/com/scalar/db/storage/objectstorage/ConsensusCommitAdminIntegrationTestWithObjectStorage.java index c8fdd98764..45ab83ef8e 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/objectstorage/ConsensusCommitAdminIntegrationTestWithObjectStorage.java +++ b/core/src/integration-test/java/com/scalar/db/storage/objectstorage/ConsensusCommitAdminIntegrationTestWithObjectStorage.java @@ -1,5 +1,6 @@ package com.scalar.db.storage.objectstorage; +import com.scalar.db.api.TableMetadata; import com.scalar.db.config.DatabaseConfig; import com.scalar.db.transaction.consensuscommit.ConsensusCommitAdminIntegrationTestBase; import com.scalar.db.transaction.consensuscommit.ConsensusCommitConfig; @@ -15,6 +16,14 @@ protected Properties getProps(String testName) { return ObjectStorageEnv.getProperties(testName); } + @Override + protected TableMetadata getTableMetadata() { + return TableMetadata.newBuilder(TABLE_METADATA) + .removeSecondaryIndex(COL_NAME5) + .removeSecondaryIndex(COL_NAME6) + .build(); + } + @Override protected String getSystemNamespaceName(Properties properties) { return ObjectStorageUtils.getObjectStorageConfig(new DatabaseConfig(properties)) diff --git a/core/src/integration-test/java/com/scalar/db/storage/objectstorage/ObjectStorageAdminCaseSensitivityIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/objectstorage/ObjectStorageAdminCaseSensitivityIntegrationTest.java index 41f474c60b..1732437acc 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/objectstorage/ObjectStorageAdminCaseSensitivityIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/objectstorage/ObjectStorageAdminCaseSensitivityIntegrationTest.java @@ -1,7 +1,10 @@ package com.scalar.db.storage.objectstorage; import com.scalar.db.api.DistributedStorageAdminCaseSensitivityIntegrationTestBase; +import com.scalar.db.api.Scan; +import com.scalar.db.api.TableMetadata; import com.scalar.db.config.DatabaseConfig; +import com.scalar.db.io.DataType; import com.scalar.db.util.AdminTestUtils; import java.util.Map; import java.util.Properties; @@ -21,6 +24,30 @@ protected String getSystemNamespaceName(Properties properties) { .getMetadataNamespace(); } + @Override + protected TableMetadata getTableMetadata() { + return TableMetadata.newBuilder() + .addColumn(getColumnName1(), DataType.INT) + .addColumn(getColumnName2(), DataType.TEXT) + .addColumn(getColumnName3(), DataType.TEXT) + .addColumn(getColumnName4(), DataType.INT) + .addColumn(getColumnName5(), DataType.INT) + .addColumn(getColumnName6(), DataType.TEXT) + .addColumn(getColumnName7(), DataType.BIGINT) + .addColumn(getColumnName8(), DataType.FLOAT) + .addColumn(getColumnName9(), DataType.DOUBLE) + .addColumn(getColumnName10(), DataType.BOOLEAN) + .addColumn(getColumnName11(), DataType.BLOB) + .addColumn(getColumnName12(), DataType.DATE) + .addColumn(getColumnName13(), DataType.TIME) + .addColumn(getColumnName14(), DataType.TIMESTAMPTZ) + .addPartitionKey(getColumnName2()) + .addPartitionKey(getColumnName1()) + .addClusteringKey(getColumnName4(), Scan.Ordering.Order.ASC) + .addClusteringKey(getColumnName3(), Scan.Ordering.Order.DESC) + .build(); + } + @Override protected Map getCreationOptions() { return ObjectStorageEnv.getCreationOptions(); diff --git a/core/src/integration-test/java/com/scalar/db/storage/objectstorage/ObjectStorageAdminIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/objectstorage/ObjectStorageAdminIntegrationTest.java index 8e5b59fbed..9f6c520ad1 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/objectstorage/ObjectStorageAdminIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/objectstorage/ObjectStorageAdminIntegrationTest.java @@ -1,7 +1,10 @@ package com.scalar.db.storage.objectstorage; import com.scalar.db.api.DistributedStorageAdminIntegrationTestBase; +import com.scalar.db.api.Scan; +import com.scalar.db.api.TableMetadata; import com.scalar.db.config.DatabaseConfig; +import com.scalar.db.io.DataType; import com.scalar.db.util.AdminTestUtils; import java.util.Properties; import org.junit.jupiter.api.Disabled; @@ -19,6 +22,30 @@ protected String getSystemNamespaceName(Properties properties) { .getMetadataNamespace(); } + @Override + protected TableMetadata getTableMetadata() { + return TableMetadata.newBuilder() + .addColumn(getColumnName1(), DataType.INT) + .addColumn(getColumnName2(), DataType.TEXT) + .addColumn(getColumnName3(), DataType.TEXT) + .addColumn(getColumnName4(), DataType.INT) + .addColumn(getColumnName5(), DataType.INT) + .addColumn(getColumnName6(), DataType.TEXT) + .addColumn(getColumnName7(), DataType.BIGINT) + .addColumn(getColumnName8(), DataType.FLOAT) + .addColumn(getColumnName9(), DataType.DOUBLE) + .addColumn(getColumnName10(), DataType.BOOLEAN) + .addColumn(getColumnName11(), DataType.BLOB) + .addColumn(getColumnName12(), DataType.DATE) + .addColumn(getColumnName13(), DataType.TIME) + .addColumn(getColumnName14(), DataType.TIMESTAMPTZ) + .addPartitionKey(getColumnName2()) + .addPartitionKey(getColumnName1()) + .addClusteringKey(getColumnName4(), Scan.Ordering.Order.ASC) + .addClusteringKey(getColumnName3(), Scan.Ordering.Order.DESC) + .build(); + } + @Override protected boolean isIndexOnBooleanColumnSupported() { return false; diff --git a/core/src/integration-test/java/com/scalar/db/storage/objectstorage/SingleCrudOperationTransactionAdminIntegrationTestWithObjectStorage.java b/core/src/integration-test/java/com/scalar/db/storage/objectstorage/SingleCrudOperationTransactionAdminIntegrationTestWithObjectStorage.java index 18da22a7ff..0b1ed72726 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/objectstorage/SingleCrudOperationTransactionAdminIntegrationTestWithObjectStorage.java +++ b/core/src/integration-test/java/com/scalar/db/storage/objectstorage/SingleCrudOperationTransactionAdminIntegrationTestWithObjectStorage.java @@ -1,5 +1,6 @@ package com.scalar.db.storage.objectstorage; +import com.scalar.db.api.TableMetadata; import com.scalar.db.config.DatabaseConfig; import com.scalar.db.transaction.singlecrudoperation.SingleCrudOperationTransactionAdminIntegrationTestBase; import java.util.Properties; @@ -19,6 +20,14 @@ protected String getSystemNamespaceName(Properties properties) { .getMetadataNamespace(); } + @Override + protected TableMetadata getTableMetadata() { + return TableMetadata.newBuilder(TABLE_METADATA) + .removeSecondaryIndex(COL_NAME5) + .removeSecondaryIndex(COL_NAME6) + .build(); + } + @Override @Disabled("Temporarily disabled because it includes DML operations") public void truncateTable_ShouldTruncateProperly() {} diff --git a/core/src/main/java/com/scalar/db/storage/objectstorage/ObjectStorageAdmin.java b/core/src/main/java/com/scalar/db/storage/objectstorage/ObjectStorageAdmin.java index 937e9702f7..926889a02f 100644 --- a/core/src/main/java/com/scalar/db/storage/objectstorage/ObjectStorageAdmin.java +++ b/core/src/main/java/com/scalar/db/storage/objectstorage/ObjectStorageAdmin.java @@ -88,6 +88,7 @@ public void createTable( String namespace, String table, TableMetadata metadata, Map options) throws ExecutionException { try { + checkTableMetadata(metadata); // Insert the table metadata String tableMetadataKey = getTableMetadataKey(namespace, table); Map readVersionMap = new HashMap<>(); @@ -246,6 +247,7 @@ public void repairTable( String namespace, String table, TableMetadata metadata, Map options) throws ExecutionException { try { + checkTableMetadata(metadata); // Upsert the table metadata String tableMetadataKey = getTableMetadataKey(namespace, table); Map readVersionMap = new HashMap<>(); @@ -445,4 +447,12 @@ private static String getTableNameFromTableMetadataKey(String tableMetadataKey) } return parts.get(1); } + + private void checkTableMetadata(TableMetadata metadata) { + Set secondaryIndexNames = metadata.getSecondaryIndexNames(); + if (!secondaryIndexNames.isEmpty()) { + throw new IllegalArgumentException( + CoreError.OBJECT_STORAGE_INDEX_NOT_SUPPORTED.buildMessage()); + } + } } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java index 72ef92a454..12da4c9a41 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java @@ -331,9 +331,9 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() assertThat(tableMetadata.getClusteringOrder(getColumnName14())).isNull(); assertThat(tableMetadata.getClusteringOrder(getColumnName15())).isNull(); - assertThat(tableMetadata.getSecondaryIndexNames().size()).isEqualTo(2); - assertThat(tableMetadata.getSecondaryIndexNames().contains(getColumnName5())).isTrue(); - assertThat(tableMetadata.getSecondaryIndexNames().contains(getColumnName6())).isTrue(); + Set expectedSecondaryIndexNames = getTableMetadata().getSecondaryIndexNames(); + assertThat(tableMetadata.getSecondaryIndexNames()) + .containsExactlyInAnyOrderElementsOf(expectedSecondaryIndexNames); } @Test diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminRepairTableIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminRepairTableIntegrationTestBase.java index b7f03bd38e..9454cc0402 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminRepairTableIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminRepairTableIntegrationTestBase.java @@ -28,21 +28,21 @@ public abstract class DistributedStorageAdminRepairTableIntegrationTestBase { private static final String NAMESPACE = "int_test_" + TEST_NAME; private static final String TABLE = "test_table"; - private static final String COL_NAME1 = "c1"; - private static final String COL_NAME2 = "c2"; - private static final String COL_NAME3 = "c3"; - private static final String COL_NAME4 = "c4"; - private static final String COL_NAME5 = "c5"; - private static final String COL_NAME6 = "c6"; - private static final String COL_NAME7 = "c7"; - private static final String COL_NAME8 = "c8"; - private static final String COL_NAME9 = "c9"; - private static final String COL_NAME10 = "c10"; - private static final String COL_NAME11 = "c11"; - private static final String COL_NAME12 = "c12"; - private static final String COL_NAME13 = "c13"; - private static final String COL_NAME14 = "c14"; - private static final String COL_NAME15 = "c15"; + protected static final String COL_NAME1 = "c1"; + protected static final String COL_NAME2 = "c2"; + protected static final String COL_NAME3 = "c3"; + protected static final String COL_NAME4 = "c4"; + protected static final String COL_NAME5 = "c5"; + protected static final String COL_NAME6 = "c6"; + protected static final String COL_NAME7 = "c7"; + protected static final String COL_NAME8 = "c8"; + protected static final String COL_NAME9 = "c9"; + protected static final String COL_NAME10 = "c10"; + protected static final String COL_NAME11 = "c11"; + protected static final String COL_NAME12 = "c12"; + protected static final String COL_NAME13 = "c13"; + protected static final String COL_NAME14 = "c14"; + protected static final String COL_NAME15 = "c15"; protected DistributedStorageAdmin admin; @@ -73,8 +73,6 @@ protected TableMetadata getTableMetadata() { .addPartitionKey(COL_NAME1) .addClusteringKey(COL_NAME4, Scan.Ordering.Order.ASC) .addClusteringKey(COL_NAME3, Scan.Ordering.Order.DESC) - .addSecondaryIndex(COL_NAME5) - .addSecondaryIndex(COL_NAME6) .build(); return builder.build(); } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java index 9705940202..21e64ef658 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java @@ -111,6 +111,10 @@ protected void initialize(String testName) throws Exception {} protected abstract Properties getProperties(String testName); + protected TableMetadata getTableMetadata() { + return TABLE_METADATA; + } + protected String getNamespaceBaseName() { return NAMESPACE_BASE_NAME; } @@ -130,7 +134,7 @@ private void createTables() throws ExecutionException { for (String namespace : Arrays.asList(namespace1, namespace2)) { admin.createNamespace(namespace, true, options); for (String table : Arrays.asList(TABLE1, TABLE2, TABLE3)) { - admin.createTable(namespace, table, TABLE_METADATA, true, options); + admin.createTable(namespace, table, getTableMetadata(), true, options); } } admin.createCoordinatorTables(true, options); @@ -248,9 +252,9 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() assertThat(tableMetadata.getClusteringOrder(COL_NAME14)).isNull(); assertThat(tableMetadata.getClusteringOrder(COL_NAME15)).isNull(); - assertThat(tableMetadata.getSecondaryIndexNames().size()).isEqualTo(2); - assertThat(tableMetadata.getSecondaryIndexNames().contains(COL_NAME5)).isTrue(); - assertThat(tableMetadata.getSecondaryIndexNames().contains(COL_NAME6)).isTrue(); + Set expectedSecondaryIndexNames = getTableMetadata().getSecondaryIndexNames(); + assertThat(tableMetadata.getSecondaryIndexNames()) + .containsExactlyInAnyOrderElementsOf(expectedSecondaryIndexNames); } @Test @@ -329,7 +333,7 @@ public void dropNamespace_ForNonEmptyNamespace_ShouldThrowIllegalArgumentExcepti try { // Arrange admin.createNamespace(namespace3); - admin.createTable(namespace3, TABLE1, TABLE_METADATA); + admin.createTable(namespace3, TABLE1, getTableMetadata()); // Act Assert assertThatThrownBy(() -> admin.dropNamespace(namespace3)) @@ -356,7 +360,7 @@ public void createTable_ForNonExistingTable_ShouldCreateTableProperly() Map options = getCreationOptions(); // Act - admin.createTable(namespace1, TABLE4, TABLE_METADATA, options); + admin.createTable(namespace1, TABLE4, getTableMetadata(), options); // Assert assertThat(admin.tableExists(namespace1, TABLE4)).isTrue(); @@ -370,7 +374,7 @@ public void createTable_ForExistingTable_ShouldThrowIllegalArgumentException() { // Arrange // Act Assert - assertThatThrownBy(() -> admin.createTable(namespace1, TABLE1, TABLE_METADATA)) + assertThatThrownBy(() -> admin.createTable(namespace1, TABLE1, getTableMetadata())) .isInstanceOf(IllegalArgumentException.class); } @@ -379,7 +383,7 @@ public void createTable_ForNonExistingNamespace_ShouldThrowIllegalArgumentExcept // Arrange // Act Assert - assertThatThrownBy(() -> admin.createTable(namespace3, TABLE1, TABLE_METADATA)) + assertThatThrownBy(() -> admin.createTable(namespace3, TABLE1, getTableMetadata())) .isInstanceOf(IllegalArgumentException.class); } @@ -388,7 +392,7 @@ public void createTable_IfNotExists_ForExistingNamespace_ShouldNotThrowAnyExcept // Arrange // Act Assert - assertThatCode(() -> admin.createTable(namespace1, TABLE1, TABLE_METADATA, true)) + assertThatCode(() -> admin.createTable(namespace1, TABLE1, getTableMetadata(), true)) .doesNotThrowAnyException(); } @@ -397,7 +401,7 @@ public void dropTable_ForExistingTable_ShouldDropTableProperly() throws Executio try { // Arrange Map options = getCreationOptions(); - admin.createTable(namespace1, TABLE4, TABLE_METADATA, options); + admin.createTable(namespace1, TABLE4, getTableMetadata(), options); // Act admin.dropTable(namespace1, TABLE4); @@ -436,7 +440,7 @@ public void truncateTable_ShouldTruncateProperly() try { // Arrange Map options = getCreationOptions(); - admin.createTable(namespace1, table, TABLE_METADATA, true, options); + admin.createTable(namespace1, table, getTableMetadata(), true, options); Key partitionKey = Key.of(COL_NAME2, "aaa", COL_NAME1, 1); Key clusteringKey = Key.of(COL_NAME4, 2, COL_NAME3, "bbb"); transactionalInsert( diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminRepairTableIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminRepairTableIntegrationTestBase.java index 223771e42f..32b756cb92 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminRepairTableIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminRepairTableIntegrationTestBase.java @@ -68,8 +68,6 @@ protected TableMetadata getTableMetadata() { .addPartitionKey(COL_NAME1) .addClusteringKey(COL_NAME4, Scan.Ordering.Order.ASC) .addClusteringKey(COL_NAME3, Scan.Ordering.Order.DESC) - .addSecondaryIndex(COL_NAME5) - .addSecondaryIndex(COL_NAME6) .build(); return builder.build(); }