-
Notifications
You must be signed in to change notification settings - Fork 40
Create index if not exists in repairTable of CosmosAdmin and DynamoAdmin #2800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures that existing tables are updated with secondary indexes during repairTable operations across different storage backends and adds corresponding unit tests.
- Added calls to create indexes when a table already exists in
DynamoAdminandCosmosAdmin - Exposed
createIndexinJdbcAdminfor testing and added a parameterized JDBC test - Introduced new unit tests for index creation in JDBC, DynamoDB, Cosmos DB, and Cassandra
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| core/src/main/java/com/scalar/db/storage/jdbc/JdbcAdmin.java | Made createIndex visible for testing |
| core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java | Added loop to create secondary indexes in repairTable |
| core/src/main/java/com/scalar/db/storage/cosmos/CosmosAdmin.java | Added updateIndexingPolicy call in repairTable |
| core/src/main/java/com/scalar/db/storage/cassandra/CassandraAdmin.java | (No production code change—needs index creation logic) |
| core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTest.java | Added parameterized test for index creation |
| core/src/test/java/com/scalar/db/storage/dynamo/DynamoAdminTestBase.java | Added test for existing table index creation |
| core/src/test/java/com/scalar/db/storage/cosmos/CosmosAdminTest.java | Added test for existing container index creation |
| core/src/test/java/com/scalar/db/storage/cassandra/CassandraAdminTest.java | Added test for existing table index creation |
Comments suppressed due to low confidence (3)
core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java:1344
- The
repairTableJavadoc should be updated to mention that it now also creates secondary indexes when the table already exists, reflecting the new loop overmetadata.getSecondaryIndexNames().
for (String indexColumnName : metadata.getSecondaryIndexNames()) {
core/src/main/java/com/scalar/db/storage/cosmos/CosmosAdmin.java:591
- Please update the method-level Javadoc for
repairTableto note that it now callsupdateIndexingPolicyto apply secondary indexes on existing containers.
updateIndexingPolicy(namespace, table, metadata);
core/src/main/java/com/scalar/db/storage/jdbc/JdbcAdmin.java:892
- Ensure that the
@VisibleForTestingannotation is imported (e.g.,com.google.common.annotations.VisibleForTesting) or use your project’s standard testing-visibility annotation to avoid compilation issues.
@VisibleForTesting
| if (!indexExistsInternal(nonPrefixedNamespace, table, indexColumnName)) { | ||
| createIndex(nonPrefixedNamespace, table, indexColumnName, options); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extending createIndex to createIndexIfNotExists did not seem straightforward, as an "Index already exists" exception is not defined in DynamoDB. Therefore, indexExistsInternal was prepared to execute createIndex only after confirming that the index does not exist.
| // Existing container properties | ||
| CosmosContainerResponse response = mock(CosmosContainerResponse.class); | ||
| when(database.createContainerIfNotExists(table, "/concatenatedPartitionKey")) | ||
| .thenReturn(response); | ||
| CosmosContainerProperties properties = mock(CosmosContainerProperties.class); | ||
| when(response.getProperties()).thenReturn(properties); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines are prepared to handle the addition of updateIndexingPolicy.
| // Existing container properties | ||
| CosmosContainerResponse response = mock(CosmosContainerResponse.class); | ||
| when(database.createContainerIfNotExists(table, "/concatenatedPartitionKey")) | ||
| .thenReturn(response); | ||
| CosmosContainerProperties properties = mock(CosmosContainerProperties.class); | ||
| when(response.getProperties()).thenReturn(properties); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
| // Existing container properties | ||
| CosmosContainerResponse response = mock(CosmosContainerResponse.class); | ||
| when(database.createContainerIfNotExists(table, "/concatenatedPartitionKey")) | ||
| .thenReturn(response); | ||
| CosmosContainerProperties properties = mock(CosmosContainerProperties.class); | ||
| when(response.getProperties()).thenReturn(properties); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
| // Arrange | ||
| admin.dropIndex(getNamespace(), getTable(), COL_NAME5); | ||
|
|
||
| // Act | ||
| admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prepare a situation where the index does not exist in the actual table, but the index is specified in the table metadata given when repairTable is executed.
core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java
Outdated
Show resolved
Hide resolved
komamitsu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 👍
Torch3333
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
feeblefakie
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I left one suggestion for naming, LGTM! Thank you!
| TableMetadata.newBuilder(tableMetadata).addSecondaryIndex(columnName).build()); | ||
| } | ||
|
|
||
| private boolean rawIndexExists(String nonPrefixedNamespace, String table, String indexName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| private boolean rawIndexExists(String nonPrefixedNamespace, String table, String indexName) { | |
| private boolean nativeIndexExists(String nonPrefixedNamespace, String table, String indexName) { |
I felt raw sounds misleading. How about native?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your comment! It seems that the prefix "Raw" is used to refer to things not managed by ScalarDB metadata, such as addRawColumnToTable. Therefore, the name rawIndexExists is being used for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! OK, let's keep it as is for this PR.
@brfrn169 It's very minor, but I think raw sounds misleading , so let's revisit the naming at some point.
| assertThatCode(() -> admin.dropIndex(getNamespace(), getTable(), COL_NAME5)) | ||
| .doesNotThrowAnyException(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the fact that admin.dropIndex() doesn’t throw an exception really confirm that the index has been created?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brfrn169 admin.dropIndex drops an index in the underlying storage and updates the metadata. Therefore, if the method succeeds, my thinking is that the index can be considered to have been deleted. What do you think?
brfrn169
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you!
Description
This PR fixes an issue where the
repairTableoperation inDynamoAdminandCosmosAdmindid not create indexes when the table already existed. Also, to ensure therepairTablecreates indexes when the table metadata specifies them, this PR adds tests for therepairTable.Related issues and/or PRs
N/A
Changes made
repairTablemethod inDynamoAdminandCosmosAdminto create indexes when the table metadata specifies them.repairTablemethod to ensure indexes are created when specified in the metadata.repairTablemethod to ensure indexes are created when specified in the metadata.Checklist
Additional notes (optional)
N/A
Release notes
N/A