Skip to content

Conversation

@KodaiD
Copy link
Contributor

@KodaiD KodaiD commented Jun 20, 2025

Description

This PR fixes an issue where the repairTable operation in DynamoAdmin and CosmosAdmin did not create indexes when the table already existed. Also, to ensure the repairTable creates indexes when the table metadata specifies them, this PR adds tests for the repairTable.

Related issues and/or PRs

N/A

Changes made

  • Updated the repairTable method in DynamoAdmin and CosmosAdmin to create indexes when the table metadata specifies them.
  • Added unit tests for the repairTable method to ensure indexes are created when specified in the metadata.
  • Added an integration test for the repairTable method to ensure indexes are created when specified in the metadata.

Checklist

  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation to reflect the changes.
  • I have considered whether similar issues could occur in other products, components, or modules if this PR is for bug fixes.
  • Any remaining open issues linked to this PR are documented and up-to-date (Jira, GitHub, etc.).
  • Tests (unit, integration, etc.) have been added for the changes.
  • My changes generate no new warnings.
  • Any dependent changes in other PRs have been merged and published.

Additional notes (optional)

N/A

Release notes

N/A

@KodaiD KodaiD requested a review from Copilot June 20, 2025 01:33
@KodaiD KodaiD self-assigned this Jun 20, 2025
@KodaiD KodaiD added the bugfix label Jun 20, 2025
Copy link
Contributor

Copilot AI left a 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 DynamoAdmin and CosmosAdmin
  • Exposed createIndex in JdbcAdmin for 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 repairTable Javadoc should be updated to mention that it now also creates secondary indexes when the table already exists, reflecting the new loop over metadata.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 repairTable to note that it now calls updateIndexingPolicy to 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 @VisibleForTesting annotation is imported (e.g., com.google.common.annotations.VisibleForTesting) or use your project’s standard testing-visibility annotation to avoid compilation issues.
  @VisibleForTesting

Comment on lines 1394 to 1396
if (!indexExistsInternal(nonPrefixedNamespace, table, indexColumnName)) {
createIndex(nonPrefixedNamespace, table, indexColumnName, options);
}
Copy link
Contributor Author

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.

Comment on lines +896 to +902
// 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);

Copy link
Contributor Author

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.

Comment on lines +953 to +959
// 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);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Comment on lines +1013 to +1019
// 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);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Comment on lines +220 to +224
// Arrange
admin.dropIndex(getNamespace(), getTable(), COL_NAME5);

// Act
admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions());
Copy link
Contributor Author

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.

@KodaiD KodaiD marked this pull request as ready for review June 23, 2025 00:14
@KodaiD KodaiD requested a review from komamitsu June 23, 2025 05:21
Copy link
Contributor

@komamitsu komamitsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

Copy link
Contributor

@Torch3333 Torch3333 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

Copy link
Contributor

@feeblefakie feeblefakie left a 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) {
Copy link
Contributor

@feeblefakie feeblefakie Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Comment on lines +227 to +228
assertThatCode(() -> admin.dropIndex(getNamespace(), getTable(), COL_NAME5))
.doesNotThrowAnyException();
Copy link
Collaborator

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?

Copy link
Contributor Author

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?

@KodaiD KodaiD requested a review from brfrn169 June 25, 2025 10:31
Copy link
Collaborator

@brfrn169 brfrn169 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@brfrn169 brfrn169 merged commit 54ab4e6 into master Jun 26, 2025
57 checks passed
@brfrn169 brfrn169 deleted the fix-nosql-admin-repair branch June 26, 2025 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants