-
Notifications
You must be signed in to change notification settings - Fork 37
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
Conversation
…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
…mespaces_management # Conflicts: # core/src/main/java/com/scalar/db/storage/cosmos/CosmosConfig.java
…inator namespace name (#732)
…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
703ec87
to
d382b29
Compare
|
||
/** | ||
* 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; |
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.
The new admin.getNamespaceNames()
interface.
### 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"); | ||
``` |
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.
Add the doc for admin.getNamespaceTableNames("ns")
since it was missing.
/** | ||
* Whether to check if the namespace exists or not. Set false when the storage does not support | ||
* namespaces. | ||
*/ | ||
private final boolean checkNamespace; |
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.
All storages support namespace now so it is not needed anymore.
/** | ||
* 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 { |
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.
Abstracted the unit test for Cassandra to be able to test with different values for the metadata keyspace.
### Get the namespaces | ||
|
||
You can get the existing namespaces as follows: | ||
|
||
```java | ||
Set<String> namespaces = admin.getNamespaceNames(); | ||
``` |
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.
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: | |||
|
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.
Updated the documentation for the configuration
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); | ||
} | ||
} |
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.
For each admin, the implementation of admin.namespaceExists()
is now uniformized and checks if the given namespace is contained in the namespace metadata table.
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.
Left several comments. Actually, I haven't finished this review yet. I'll continue with it later. Thanks.
core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosAdminTestUtils.java
Outdated
Show resolved
Hide resolved
...ntegration-test/java/com/scalar/db/transaction/jdbc/JdbcTransactionAdminIntegrationTest.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/scalar/db/storage/cassandra/CassandraAdmin.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/scalar/db/storage/cassandra/CassandraAdmin.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/scalar/db/storage/multistorage/MultiStorageAdmin.java
Outdated
Show resolved
Hide resolved
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.
Left some additional comments. Please take a look when you have time!
schema-loader/src/test/java/com/scalar/db/schemaloader/SchemaOperatorTest.java
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
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.
Left a comment. But LGTM, Thank you!
} | ||
|
||
private void dropNamespacesTableIfEmpty() throws ExecutionException { | ||
String NamespaceTableFullName = |
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:
String NamespaceTableFullName = | |
String namespaceTableFullName = |
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, I revised it in 38bd49d
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.
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 |
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.
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.
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.
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.
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.
@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.
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.
In this case, app1 returns ns1 and ns2, and app2 returns ns3 and ns4 by getNamespaceNames?
Correct. Yes, that is the expected behavior.
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!
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!
@brfrn169 @Torch3333 It's OK to merge, but I left one additional comment. |
@feeblefakie @Torch3333 Merging this for now. If we have problems with the behavior of |
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 :
scalar.db.cassandra.metadata.keyspace
configuration.scalar.db.cosmos.table_metadata.database
to rename it toscalar.db.cosmos.metadata.database
scalar.db.dynamo.table_metadata.namespace
to rename it toscalar.db.dynamo.metadata.namespace
scalar.db.jdbc.table_metadata.schema
to rename it toscalar.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 tablerepair 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.