Skip to content
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

Add Namespaces management #989

Merged
merged 31 commits into from
Aug 23, 2023
Merged

Add Namespaces management #989

merged 31 commits into from
Aug 23, 2023

Conversation

Torch3333
Copy link
Contributor

@Torch3333 Torch3333 commented Aug 3, 2023

Context
ScalarDB did not manage namespaces so we could not retrieve the names of existing namespaces. We could only retrieve the tables of a given namespace.

Changes
ScalarDB is now managing namespace metadata in addition to the table metadata. At the moment, the namespace metadata is only the namespace name. With the Admin API admin.getNamespaceNames(), the list of namespaces names created through ScalarDB can be retrieved.
To manage the created namespace metadata, a new table called namespace is added to the same namespace which contains the metadata table.

The namespace name containing namespace and table metadata can be set via the configuration :

  • Cassandra : created the new scalar.db.cassandra.metadata.keyspace configuration.
  • CosmosDB: we deprecated the current scalar.db.cosmos.table_metadata.database to rename it to scalar.db.cosmos.metadata.database
  • DynamoDB: we deprecated the existing scalar.db.dynamo.table_metadata.namespace to rename it to scalar.db.dynamo.metadata.namespace
  • JDBC: we deprecated the existing scalar.db.jdbc.table_metadata.schema to rename it to scalar.db.jdbc.metadata.schema

Future related changes
We will also add two related features to the Admin API and the Schema Loader tool :

  • upgrade allows the users to update their existing environment to be compatible with the new Scalar DB version using the namespace table
  • repair the namespace allows the users to repair the namespaces metadata. If for some reason, a namespace exists in the underlying storage, but its metadata is missing from the namespaces metadata managed by ScalarDB (because the namespaces table was deleted or its data is corrupted), this method will re-add the namespace to the ScalarDB namespaces metadata.

Torch3333 and others added 23 commits September 7, 2022 16:44
…mespaces_management

# Conflicts:
#	core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosAdminTestUtils.java
#	core/src/integration-test/java/com/scalar/db/storage/dynamo/ConsensusCommitAdminIntegrationTestWithDynamo.java
#	core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoAdminIntegrationTest.java
#	core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoAdminTestUtils.java
#	server/src/integration-test/java/com/scalar/db/server/ServerAdminTestUtils.java
…mespaces_management

# Conflicts:
#	core/src/main/java/com/scalar/db/storage/cosmos/CosmosConfig.java
…mespace_management_merge_master

# Conflicts:
#	core/src/integration-test/java/com/scalar/db/storage/dynamo/ConsensusCommitAdminIntegrationTestWithDynamo.java
#	core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoAdminIntegrationTest.java
#	core/src/integration-test/java/com/scalar/db/storage/jdbc/ConsensusCommitAdminIntegrationTestWithJdbcDatabase.java
#	core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminIntegrationTest.java
#	core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminTestUtils.java
#	core/src/integration-test/java/com/scalar/db/storage/multistorage/MultiStorageAdminTestUtils.java
#	core/src/integration-test/java/com/scalar/db/transaction/jdbc/JdbcTransactionAdminIntegrationTest.java
#	core/src/main/java/com/scalar/db/api/Admin.java
#	core/src/main/java/com/scalar/db/storage/cosmos/CosmosAdmin.java
#	core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java
#	core/src/main/java/com/scalar/db/storage/jdbc/JdbcAdmin.java
#	core/src/test/java/com/scalar/db/storage/cosmos/CosmosAdminTestBase.java
#	core/src/test/java/com/scalar/db/storage/dynamo/DynamoAdminTestBase.java
#	core/src/test/java/com/scalar/db/storage/dynamo/DynamoConfigTest.java
#	core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTestBase.java
#	core/src/test/java/com/scalar/db/storage/jdbc/JdbcConfigTest.java
#	integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java
#	integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java
#	schema-loader/src/test/java/com/scalar/db/schemaloader/SchemaOperatorTest.java
#	server/src/integration-test/java/com/scalar/db/server/ConsensusCommitAdminIntegrationTestWithServer.java
#	server/src/integration-test/java/com/scalar/db/server/DistributedStorageAdminIntegrationTestWithServer.java
#	server/src/integration-test/java/com/scalar/db/server/ServerAdminTestUtils.java
…mespace_management_merge_master

# Conflicts:
#	core/src/main/java/com/scalar/db/api/Admin.java
#	core/src/main/java/com/scalar/db/common/CheckedDistributedStorageAdmin.java
#	core/src/main/java/com/scalar/db/service/AdminService.java
#	core/src/main/java/com/scalar/db/storage/cosmos/CosmosAdmin.java
#	core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java
#	core/src/main/java/com/scalar/db/storage/jdbc/JdbcAdmin.java
#	core/src/main/java/com/scalar/db/storage/multistorage/MultiStorageAdmin.java
#	core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitAdmin.java
#	core/src/main/java/com/scalar/db/transaction/rpc/GrpcTransactionAdmin.java
#	core/src/test/java/com/scalar/db/storage/cassandra/CassandraAdminTestBase.java
#	core/src/test/java/com/scalar/db/storage/cosmos/CosmosAdminTestBase.java
#	core/src/test/java/com/scalar/db/storage/dynamo/DynamoAdminTestBase.java
#	core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTestBase.java
#	core/src/test/java/com/scalar/db/storage/rpc/GrpcAdminTest.java
#	core/src/test/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitAdminTestBase.java
#	core/src/test/java/com/scalar/db/transaction/jdbc/JdbcTransactionAdminTest.java
#	rpc/src/main/java/com/scalar/db/rpc/ScalarDbProto.java
#	schema-loader/src/main/java/com/scalar/db/schemaloader/command/SchemaLoaderCommand.java
#	schema-loader/src/test/java/com/scalar/db/schemaloader/SchemaLoaderTest.java
#	schema-loader/src/test/java/com/scalar/db/schemaloader/SchemaOperatorTest.java
#	schema-loader/src/test/java/com/scalar/db/schemaloader/command/SchemaLoaderCommandTest.java
…nd admin.upgrade() is executed on ScalarDB server
…mespaceNames_on_ScalarDB_server' into feat/namespaces_management
@Torch3333 Torch3333 force-pushed the namespaces_management branch from 703ec87 to d382b29 Compare August 7, 2023 00:28
Comment on lines +416 to +423

/**
* Returns the names of the existing namespaces created through Scalar DB.
*
* @return a set of namespaces names, an empty set if no namespaces exist
* @throws ExecutionException if the operation fails
*/
Set<String> getNamespaceNames() throws ExecutionException;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The new admin.getNamespaceNames() interface.

Comment on lines +214 to +221
### Get the tables of a namespace

You can get the tables of a namespace as follows:

```java
// Get the tables of the namespace "ns"
Set<String> tables = admin.getNamespaceTableNames("ns");
```
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add the doc for admin.getNamespaceTableNames("ns") since it was missing.

Comment on lines -17 to -21
/**
* Whether to check if the namespace exists or not. Set false when the storage does not support
* namespaces.
*/
private final boolean checkNamespace;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All storages support namespace now so it is not needed anymore.

Comment on lines +56 to +61
/**
* Abstraction that defines unit tests for the {@link CassandraAdmin}. The class purpose is to be
* able to run the {@link CassandraAdmin} unit tests with different values for the {@link
* CassandraAdmin}, notably {@link CassandraAdmin#METADATA_KEYSPACE}.
*/
public abstract class CassandraAdminTestBase {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Abstracted the unit test for Cassandra to be able to test with different values for the metadata keyspace.

Comment on lines +206 to +212
### Get the namespaces

You can get the existing namespaces as follows:

```java
Set<String> namespaces = admin.getNamespaceNames();
```
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the new API to the documentation.

@@ -49,34 +49,35 @@ The following describes the configurations available for each storage.

- For Cassandra, the following configurations are available:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the documentation for the configuration

Comment on lines 486 to 498
public boolean namespaceExists(String namespace) throws ExecutionException {
return databaseExists(namespace);
try {
getNamespacesContainer()
.readItem(namespace, new PartitionKey(namespace), CosmosNamespace.class);
return true;
} catch (RuntimeException e) {
if (e instanceof CosmosException
&& ((CosmosException) e).getStatusCode() == CosmosErrorCode.NOT_FOUND.get()) {
return false;
}
throw new ExecutionException("Checking if the namespace exists failed", e);
}
}
Copy link
Contributor Author

@Torch3333 Torch3333 Aug 7, 2023

Choose a reason for hiding this comment

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

For each admin, the implementation of admin.namespaceExists() is now uniformized and checks if the given namespace is contained in the namespace metadata table.

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.

Left several comments. Actually, I haven't finished this review yet. I'll continue with it later. Thanks.

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.

Left some additional comments. Please take a look when you have time!

docs/schema-loader.md Outdated Show resolved Hide resolved
…ces_management

# Conflicts:
#	core/src/main/java/com/scalar/db/storage/cassandra/CassandraAdmin.java
#	core/src/main/java/com/scalar/db/storage/cosmos/CosmosAdmin.java
#	core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java
#	core/src/main/java/com/scalar/db/storage/jdbc/JdbcAdmin.java
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.

Left a comment. But LGTM, Thank you!

}

private void dropNamespacesTableIfEmpty() throws ExecutionException {
String NamespaceTableFullName =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto:

Suggested change
String NamespaceTableFullName =
String namespaceTableFullName =

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, I revised it in 38bd49d

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.

Overall, looking good! Thank you!
Left one question.

// The reasoning is:
// - ns1 is present in the mysql storage and listed in the mapping belonging to mysql
// => returned
// - ns2 is present in the mysql storage but listed in the mapping belonging to cassandra
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I don't fully get this.
Is this a misconfiguration by users? (ns2 is defined in MySQL but the namespace mapping says it's mapped to Cassandra?)
It would be great if you could elaborate on this.

Copy link
Contributor Author

@Torch3333 Torch3333 Aug 16, 2023

Choose a reason for hiding this comment

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

Is this a misconfiguration by users? (ns2 is defined in MySQL but the namespace mapping says it's mapped to Cassandra?)

It can be a misconfiguration or a deliberate action to do some testing for another ScalarDB app(even though it's probably not wise to do so).

This is a corner case that is probably unlikely to happen, but I included it in this explanation to highlight only namespaces strictly defined in the configuration are returned by this method.

Copy link
Contributor

@feeblefakie feeblefakie Aug 21, 2023

Choose a reason for hiding this comment

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

@Torch3333
Let me clarify.
So, there are two apps that share the same ScalarDB Cluster.
One app (app1) defines ns1 and ns2 in its config, and the other (app2) defines ns3 and ns4 in its config.
But, the actual database defines ns1, ns2, ns3, and ns4.
In this case, app1 returns ns1 and ns2, and app2 returns ns3 and ns4 by getNamespaceNames?
I'm not sure if it is an expected behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case, app1 returns ns1 and ns2, and app2 returns ns3 and ns4 by getNamespaceNames?

Correct. Yes, that is the expected behavior.

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! 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.

LGTM! Thank you!

@feeblefakie
Copy link
Contributor

@brfrn169 @Torch3333 It's OK to merge, but I left one additional comment.
#989 (comment)

@brfrn169
Copy link
Collaborator

brfrn169 commented Aug 23, 2023

@feeblefakie @Torch3333 Merging this for now. If we have problems with the behavior of MultiStorageAdmin. getNamespaceNames(), let's fix it at that time. Thanks!

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.

4 participants