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

Support namespace mappings in MultiStorage #207

Merged
merged 6 commits into from
May 31, 2021

Conversation

brfrn169
Copy link
Collaborator

Currently, we only have a table mapping support in MultiStorage as follows:

# Define table mappings from table names to storages. The format is “<table name>:<storage name>,...”
scalar.db.multi_storage.table_mapping=user.ORDER:cassandra,user.CUSTOMER:mysql,coordinator.state:cassandra

This PR adds a namespace mapping support where we can define namespace mappings as follows:

# Define namespace mappings from namespace names to storages. The format is “<namespace name>:<storage name>,...”
scalar.db.multi_storage.namespace_mapping=user:cassandra,coordinator:mysql

Please take a look!

@brfrn169 brfrn169 requested a review from feeblefakie May 29, 2021 16:11
@brfrn169 brfrn169 self-assigned this May 29, 2021
@brfrn169 brfrn169 force-pushed the support-namespace-mappings-in-multi-storage branch from 82f5103 to 4ecb62a Compare May 30, 2021 14:43
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 a minor question and comments.


checkIfStorageExists(storage);
builder.put(table, storage);
if (tableMapping != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It is a minor style thing, but I feel the following is slightly better since less indenting.

if (tableMapping == null) {
  return null;
}
for (String tableAndStorage : tableMapping.split(",")) {
  // ...
}

Builder<String, String> builder = ImmutableMap.builder();

String namespaceMapping = props.getProperty(NAMESPACE_MAPPING);
if (namespaceMapping != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

}
return storage;
String namespace = operation.forNamespace().get();
storage = namespaceStorageMap.get(namespace);
Copy link
Contributor

Choose a reason for hiding this comment

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

So, if conflicting mapping like below is given, it prefers namespace mapping, right? Or we shouldn't use both mapping format together?

scalar.db.multi_storage.table_mapping=user.ORDER:cassandra,user.CUSTOMER:mysql,coordinator.state:cassandra
scalar.db.multi_storage.namespace_mapping=user:cassandra

Anyway, I think it would be great if we note it somewhere.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you for reviewing this!

If conflicting mapping between a table mapping and a namespace mapping, it prefers the table mapping because table mappings are more specific than namespace mappings.

Sure, I will add it to the Javadoc. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, sorry, I meant table mapping is preferred. Thank you!

@brfrn169 brfrn169 requested a review from feeblefakie May 31, 2021 02:36
feeblefakie
feeblefakie previously approved these changes May 31, 2021
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! Thanks!
I left minor suggestions on the English comments.

}
return storage;
String namespace = operation.forNamespace().get();
storage = namespaceStorageMap.get(namespace);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, sorry, I meant table mapping is preferred. Thank you!

@brfrn169 brfrn169 requested a review from feeblefakie May 31, 2021 05:17
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.

LGMT!

@feeblefakie feeblefakie merged commit e05ef3e into master May 31, 2021
@feeblefakie feeblefakie deleted the support-namespace-mappings-in-multi-storage branch May 31, 2021 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants