Skip to content

Commit 4601164

Browse files
feeblefakieKodaiD
andauthored
Backport to branch(3) : Add wait for cache expiry (#3044)
Co-authored-by: Kodai Doki <[email protected]>
1 parent 2cf23f1 commit 4601164

17 files changed

+155
-110
lines changed

core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraEnv.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public static Properties getProperties(@SuppressWarnings("unused") String testNa
3131
props.setProperty(DatabaseConfig.CROSS_PARTITION_SCAN, "true");
3232
props.setProperty(DatabaseConfig.CROSS_PARTITION_SCAN_FILTERING, "true");
3333
props.setProperty(DatabaseConfig.CROSS_PARTITION_SCAN_ORDERING, "false");
34+
35+
// Metadata cache expiration time
36+
props.setProperty(DatabaseConfig.METADATA_CACHE_EXPIRATION_TIME_SECS, "1");
37+
3438
return props;
3539
}
3640

core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosEnv.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public static Properties getProperties(String testName) {
3232
CosmosConfig.TABLE_METADATA_DATABASE,
3333
DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME + "_" + testName);
3434

35+
// Metadata cache expiration time
36+
props.setProperty(DatabaseConfig.METADATA_CACHE_EXPIRATION_TIME_SECS, "1");
37+
3538
return props;
3639
}
3740

core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoEnv.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public static Properties getProperties(String testName) {
5252
DynamoConfig.TABLE_METADATA_NAMESPACE,
5353
DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME + "_" + testName);
5454

55+
// Metadata cache expiration time
56+
properties.setProperty(DatabaseConfig.METADATA_CACHE_EXPIRATION_TIME_SECS, "1");
57+
5558
return properties;
5659
}
5760

core/src/integration-test/java/com/scalar/db/storage/jdbc/ConsensusCommitAdminIntegrationTestWithJdbcDatabase.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.assertj.core.api.Assertions.assertThatCode;
55
import static org.assertj.core.api.Assertions.catchThrowable;
66

7+
import com.google.common.util.concurrent.Uninterruptibles;
78
import com.scalar.db.api.DistributedTransactionManager;
89
import com.scalar.db.api.Insert;
910
import com.scalar.db.api.InsertBuilder;
@@ -29,6 +30,7 @@
2930
import java.util.List;
3031
import java.util.Map;
3132
import java.util.Properties;
33+
import java.util.concurrent.TimeUnit;
3234
import org.junit.jupiter.api.Test;
3335
import org.junit.jupiter.api.condition.DisabledIf;
3436
import org.junit.jupiter.api.condition.EnabledIf;
@@ -415,8 +417,8 @@ public void alterColumnType_WideningConversion_ShouldAlterColumnTypesCorrectly()
415417
@Test
416418
@EnabledIf("isOracle")
417419
public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorrectly()
418-
throws ExecutionException, IOException, TransactionException {
419-
try {
420+
throws ExecutionException, TransactionException {
421+
try (DistributedTransactionManager manager = transactionFactory.getTransactionManager()) {
420422
// Arrange
421423
Map<String, String> options = getCreationOptions();
422424
TableMetadata.Builder currentTableMetadataBuilder =
@@ -432,23 +434,24 @@ public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorr
432434

433435
int expectedColumn3Value = 1;
434436
float expectedColumn4Value = 4.0f;
435-
try (DistributedTransactionManager manager = transactionFactory.getTransactionManager()) {
436-
InsertBuilder.Buildable insert =
437-
Insert.newBuilder()
438-
.namespace(namespace1)
439-
.table(TABLE4)
440-
.partitionKey(Key.ofInt("c1", 1))
441-
.clusteringKey(Key.ofInt("c2", 2))
442-
.intValue("c3", expectedColumn3Value)
443-
.floatValue("c4", expectedColumn4Value);
444-
transactionalInsert(manager, insert.build());
445-
}
437+
InsertBuilder.Buildable insert =
438+
Insert.newBuilder()
439+
.namespace(namespace1)
440+
.table(TABLE4)
441+
.partitionKey(Key.ofInt("c1", 1))
442+
.clusteringKey(Key.ofInt("c2", 2))
443+
.intValue("c3", expectedColumn3Value)
444+
.floatValue("c4", expectedColumn4Value);
445+
transactionalInsert(manager, insert.build());
446446

447447
// Act
448448
admin.alterColumnType(namespace1, TABLE4, "c3", DataType.BIGINT);
449449
Throwable exception =
450450
catchThrowable(() -> admin.alterColumnType(namespace1, TABLE4, "c4", DataType.DOUBLE));
451451

452+
// Wait for cache expiry
453+
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
454+
452455
// Assert
453456
assertThat(exception).isInstanceOf(UnsupportedOperationException.class);
454457
TableMetadata.Builder expectedTableMetadataBuilder =
@@ -462,18 +465,16 @@ public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorr
462465
TableMetadata expectedTableMetadata = expectedTableMetadataBuilder.build();
463466
assertThat(admin.getTableMetadata(namespace1, TABLE4)).isEqualTo(expectedTableMetadata);
464467

465-
try (DistributedTransactionManager manager = transactionFactory.getTransactionManager()) {
466-
Scan scan =
467-
Scan.newBuilder()
468-
.namespace(namespace1)
469-
.table(TABLE4)
470-
.partitionKey(Key.ofInt("c1", 1))
471-
.build();
472-
List<Result> results = transactionalScan(manager, scan);
473-
assertThat(results).hasSize(1);
474-
Result result = results.get(0);
475-
assertThat(result.getBigInt("c3")).isEqualTo(expectedColumn3Value);
476-
}
468+
Scan scan =
469+
Scan.newBuilder()
470+
.namespace(namespace1)
471+
.table(TABLE4)
472+
.partitionKey(Key.ofInt("c1", 1))
473+
.build();
474+
List<Result> results = transactionalScan(manager, scan);
475+
assertThat(results).hasSize(1);
476+
Result result = results.get(0);
477+
assertThat(result.getBigInt("c3")).isEqualTo(expectedColumn3Value);
477478
} finally {
478479
admin.dropTable(namespace1, TABLE4, true);
479480
}

core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminIntegrationTest.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.assertj.core.api.Assertions.assertThatCode;
55
import static org.assertj.core.api.Assertions.catchThrowable;
66

7+
import com.google.common.util.concurrent.Uninterruptibles;
78
import com.scalar.db.api.DistributedStorage;
89
import com.scalar.db.api.DistributedStorageAdminIntegrationTestBase;
910
import com.scalar.db.api.Put;
@@ -27,6 +28,7 @@
2728
import java.util.List;
2829
import java.util.Map;
2930
import java.util.Properties;
31+
import java.util.concurrent.TimeUnit;
3032
import org.junit.jupiter.api.Test;
3133
import org.junit.jupiter.api.condition.DisabledIf;
3234
import org.junit.jupiter.api.condition.EnabledIf;
@@ -468,7 +470,7 @@ public void alterColumnType_WideningConversion_ShouldAlterColumnTypesCorrectly()
468470
@EnabledIf("isOracle")
469471
public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorrectly()
470472
throws ExecutionException, IOException {
471-
try {
473+
try (DistributedStorage storage = storageFactory.getStorage()) {
472474
// Arrange
473475
Map<String, String> options = getCreationOptions();
474476
TableMetadata.Builder currentTableMetadataBuilder =
@@ -484,17 +486,15 @@ public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorr
484486

485487
int expectedColumn3Value = 1;
486488
float expectedColumn4Value = 4.0f;
487-
try (DistributedStorage storage = storageFactory.getStorage()) {
488-
PutBuilder.Buildable put =
489-
Put.newBuilder()
490-
.namespace(getNamespace1())
491-
.table(getTable4())
492-
.partitionKey(Key.ofInt(getColumnName1(), 1))
493-
.clusteringKey(Key.ofInt(getColumnName2(), 2))
494-
.intValue(getColumnName3(), expectedColumn3Value)
495-
.floatValue(getColumnName4(), expectedColumn4Value);
496-
storage.put(put.build());
497-
}
489+
PutBuilder.Buildable put =
490+
Put.newBuilder()
491+
.namespace(getNamespace1())
492+
.table(getTable4())
493+
.partitionKey(Key.ofInt(getColumnName1(), 1))
494+
.clusteringKey(Key.ofInt(getColumnName2(), 2))
495+
.intValue(getColumnName3(), expectedColumn3Value)
496+
.floatValue(getColumnName4(), expectedColumn4Value);
497+
storage.put(put.build());
498498

499499
// Act
500500
admin.alterColumnType(getNamespace1(), getTable4(), getColumnName3(), DataType.BIGINT);
@@ -504,6 +504,9 @@ public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorr
504504
admin.alterColumnType(
505505
getNamespace1(), getTable4(), getColumnName4(), DataType.DOUBLE));
506506

507+
// Wait for cache expiry
508+
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
509+
507510
// Assert
508511
assertThat(exception).isInstanceOf(UnsupportedOperationException.class);
509512
TableMetadata.Builder expectedTableMetadataBuilder =
@@ -518,19 +521,17 @@ public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorr
518521
assertThat(admin.getTableMetadata(getNamespace1(), getTable4()))
519522
.isEqualTo(expectedTableMetadata);
520523

521-
try (DistributedStorage storage = storageFactory.getStorage()) {
522-
Scan scan =
523-
Scan.newBuilder()
524-
.namespace(getNamespace1())
525-
.table(getTable4())
526-
.partitionKey(Key.ofInt(getColumnName1(), 1))
527-
.build();
528-
try (Scanner scanner = storage.scan(scan)) {
529-
List<Result> results = scanner.all();
530-
assertThat(results).hasSize(1);
531-
Result result = results.get(0);
532-
assertThat(result.getBigInt(getColumnName3())).isEqualTo(expectedColumn3Value);
533-
}
524+
Scan scan =
525+
Scan.newBuilder()
526+
.namespace(getNamespace1())
527+
.table(getTable4())
528+
.partitionKey(Key.ofInt(getColumnName1(), 1))
529+
.build();
530+
try (Scanner scanner = storage.scan(scan)) {
531+
List<Result> results = scanner.all();
532+
assertThat(results).hasSize(1);
533+
Result result = results.get(0);
534+
assertThat(result.getBigInt(getColumnName3())).isEqualTo(expectedColumn3Value);
534535
}
535536
} finally {
536537
admin.dropTable(getNamespace1(), getTable4(), true);

core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcEnv.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public static Properties getProperties(String testName) {
3737
JdbcConfig.TABLE_METADATA_SCHEMA,
3838
DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME + "_" + testName);
3939

40+
// Metadata cache expiration time
41+
props.setProperty(DatabaseConfig.METADATA_CACHE_EXPIRATION_TIME_SECS, "1");
42+
4043
return props;
4144
}
4245

core/src/integration-test/java/com/scalar/db/storage/jdbc/SingleCrudOperationTransactionAdminIntegrationTestWithJdbcDatabase.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.assertj.core.api.Assertions.assertThatCode;
55
import static org.assertj.core.api.Assertions.catchThrowable;
66

7+
import com.google.common.util.concurrent.Uninterruptibles;
78
import com.scalar.db.api.DistributedTransactionManager;
89
import com.scalar.db.api.Insert;
910
import com.scalar.db.api.InsertBuilder;
@@ -27,6 +28,7 @@
2728
import java.util.List;
2829
import java.util.Map;
2930
import java.util.Properties;
31+
import java.util.concurrent.TimeUnit;
3032
import org.junit.jupiter.api.Test;
3133
import org.junit.jupiter.api.condition.DisabledIf;
3234
import org.junit.jupiter.api.condition.EnabledIf;
@@ -399,8 +401,8 @@ public void alterColumnType_WideningConversion_ShouldAlterColumnTypesCorrectly()
399401
@Test
400402
@EnabledIf("isOracle")
401403
public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorrectly()
402-
throws ExecutionException, IOException, TransactionException {
403-
try {
404+
throws ExecutionException, TransactionException {
405+
try (DistributedTransactionManager manager = transactionFactory.getTransactionManager()) {
404406
// Arrange
405407
Map<String, String> options = getCreationOptions();
406408
TableMetadata.Builder currentTableMetadataBuilder =
@@ -416,23 +418,24 @@ public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorr
416418

417419
int expectedColumn3Value = 1;
418420
float expectedColumn4Value = 4.0f;
419-
try (DistributedTransactionManager manager = transactionFactory.getTransactionManager()) {
420-
InsertBuilder.Buildable insert =
421-
Insert.newBuilder()
422-
.namespace(namespace1)
423-
.table(TABLE4)
424-
.partitionKey(Key.ofInt("c1", 1))
425-
.clusteringKey(Key.ofInt("c2", 2))
426-
.intValue("c3", expectedColumn3Value)
427-
.floatValue("c4", expectedColumn4Value);
428-
transactionalInsert(manager, insert.build());
429-
}
421+
InsertBuilder.Buildable insert =
422+
Insert.newBuilder()
423+
.namespace(namespace1)
424+
.table(TABLE4)
425+
.partitionKey(Key.ofInt("c1", 1))
426+
.clusteringKey(Key.ofInt("c2", 2))
427+
.intValue("c3", expectedColumn3Value)
428+
.floatValue("c4", expectedColumn4Value);
429+
transactionalInsert(manager, insert.build());
430430

431431
// Act
432432
admin.alterColumnType(namespace1, TABLE4, "c3", DataType.BIGINT);
433433
Throwable exception =
434434
catchThrowable(() -> admin.alterColumnType(namespace1, TABLE4, "c4", DataType.DOUBLE));
435435

436+
// Wait for cache expiry
437+
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
438+
436439
// Assert
437440
assertThat(exception).isInstanceOf(UnsupportedOperationException.class);
438441
TableMetadata.Builder expectedTableMetadataBuilder =
@@ -446,18 +449,16 @@ public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorr
446449
TableMetadata expectedTableMetadata = expectedTableMetadataBuilder.build();
447450
assertThat(admin.getTableMetadata(namespace1, TABLE4)).isEqualTo(expectedTableMetadata);
448451

449-
try (DistributedTransactionManager manager = transactionFactory.getTransactionManager()) {
450-
Scan scan =
451-
Scan.newBuilder()
452-
.namespace(namespace1)
453-
.table(TABLE4)
454-
.partitionKey(Key.ofInt("c1", 1))
455-
.build();
456-
List<Result> results = transactionalScan(manager, scan);
457-
assertThat(results).hasSize(1);
458-
Result result = results.get(0);
459-
assertThat(result.getBigInt("c3")).isEqualTo(expectedColumn3Value);
460-
}
452+
Scan scan =
453+
Scan.newBuilder()
454+
.namespace(namespace1)
455+
.table(TABLE4)
456+
.partitionKey(Key.ofInt("c1", 1))
457+
.build();
458+
List<Result> results = transactionalScan(manager, scan);
459+
assertThat(results).hasSize(1);
460+
Result result = results.get(0);
461+
assertThat(result.getBigInt("c3")).isEqualTo(expectedColumn3Value);
461462
} finally {
462463
admin.dropTable(namespace1, TABLE4, true);
463464
}

core/src/integration-test/java/com/scalar/db/storage/multistorage/ConsensusCommitNullMetadataIntegrationTestWithMultiStorage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ protected Properties getProperties(String testName) {
4949
// The default storage is cassandra
5050
props.setProperty(MultiStorageConfig.DEFAULT_STORAGE, "cassandra");
5151

52+
// Metadata cache expiration time
53+
props.setProperty(DatabaseConfig.METADATA_CACHE_EXPIRATION_TIME_SECS, "1");
54+
5255
return ConsensusCommitTestUtils.loadConsensusCommitProperties(props);
5356
}
5457
}

core/src/integration-test/java/com/scalar/db/storage/multistorage/ConsensusCommitSpecificIntegrationTestWithMultiStorage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ protected Properties getProperties(String testName) {
4949
// The default storage is cassandra
5050
props.setProperty(MultiStorageConfig.DEFAULT_STORAGE, "cassandra");
5151

52+
// Metadata cache expiration time
53+
props.setProperty(DatabaseConfig.METADATA_CACHE_EXPIRATION_TIME_SECS, "1");
54+
5255
return ConsensusCommitTestUtils.loadConsensusCommitProperties(props);
5356
}
5457
}

core/src/integration-test/java/com/scalar/db/storage/multistorage/MultiStorageAdminIntegrationTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ private void initMultiStorageAdmin() {
136136
// The default storage is cassandra
137137
props.setProperty(MultiStorageConfig.DEFAULT_STORAGE, "cassandra");
138138

139+
// Metadata cache expiration time
140+
props.setProperty(DatabaseConfig.METADATA_CACHE_EXPIRATION_TIME_SECS, "1");
141+
139142
multiStorageAdmin = new MultiStorageAdmin(new DatabaseConfig(props));
140143
}
141144

0 commit comments

Comments
 (0)