pkuwm commented on a change in pull request #844: Implement setRoutingData for
MetadataStoreDirectoryService
URL: https://github.com/apache/helix/pull/844#discussion_r386716142
##########
File path:
helix-rest/src/main/java/org/apache/helix/rest/metadatastore/ZkMetadataStoreDirectory.java
##########
@@ -169,72 +186,102 @@ private void init(String namespace, String zkAddress)
throws InvalidRoutingDataE
@Override
public Map<String, String> getAllMappingUnderPath(String namespace, String
path) {
- if (!_routingDataMap.containsKey(namespace)) {
+ // Check _routingZkAddressMap first to see if namespace is included
+ if (!_routingZkAddressMap.containsKey(namespace)) {
throw new NoSuchElementException(
"Failed to get all mapping under path: Namespace " + namespace + "
is not found!");
}
+ // If namespace is included but not routing data, it means the routing
data is invalid
+ if (!_routingDataMap.containsKey(namespace)) {
+ throw new IllegalStateException("Failed to get all mapping under path:
Namespace " + namespace
+ + " contains invalid routing data!");
+ }
return _routingDataMap.get(namespace).getAllMappingUnderPath(path);
}
@Override
public String getMetadataStoreRealm(String namespace, String shardingKey) {
- if (!_routingDataMap.containsKey(namespace)) {
+ // Check _routingZkAddressMap first to see if namespace is included
+ if (!_routingZkAddressMap.containsKey(namespace)) {
throw new NoSuchElementException(
"Failed to get metadata store realm: Namespace " + namespace + " is
not found!");
}
+ // If namespace is included but not routing data, it means the routing
data is invalid
+ if (!_routingDataMap.containsKey(namespace)) {
+ throw new IllegalStateException("Failed to get metadata store realm:
Namespace " + namespace
+ + " contains invalid routing data!");
+ }
return _routingDataMap.get(namespace).getMetadataStoreRealm(shardingKey);
}
@Override
public boolean addMetadataStoreRealm(String namespace, String realm) {
- if (!_routingDataWriterMap.containsKey(namespace)) {
- // throwing NoSuchElementException instead of IllegalArgumentException
to differentiate the
- // status code in the Accessor level
- throw new NoSuchElementException(
- "Failed to add metadata store realm: Namespace " + namespace + " is
not found!");
+ synchronized (this) {
+ if (!_routingDataWriterMap.containsKey(namespace)) {
+ // throwing NoSuchElementException instead of IllegalArgumentException
to differentiate the
+ // status code in the Accessor level
+ throw new NoSuchElementException(
+ "Failed to add metadata store realm: Namespace " + namespace + "
is not found!");
+ }
+ boolean result =
_routingDataWriterMap.get(namespace).addMetadataStoreRealm(realm);
+ refreshRoutingData(namespace);
+ return result;
}
- return _routingDataWriterMap.get(namespace).addMetadataStoreRealm(realm);
}
@Override
public boolean deleteMetadataStoreRealm(String namespace, String realm) {
- if (!_routingDataWriterMap.containsKey(namespace)) {
- // throwing NoSuchElementException instead of IllegalArgumentException
to differentiate the
- // status code in the Accessor level
- throw new NoSuchElementException(
- "Failed to delete metadata store realm: Namespace " + namespace + "
is not found!");
+ synchronized (this) {
+ if (!_routingDataWriterMap.containsKey(namespace)) {
+ // throwing NoSuchElementException instead of IllegalArgumentException
to differentiate the
+ // status code in the Accessor level
+ throw new NoSuchElementException(
+ "Failed to delete metadata store realm: Namespace " + namespace +
" is not found!");
+ }
+ boolean result =
_routingDataWriterMap.get(namespace).deleteMetadataStoreRealm(realm);
+ refreshRoutingData(namespace);
+ return result;
}
- return
_routingDataWriterMap.get(namespace).deleteMetadataStoreRealm(realm);
}
@Override
public boolean addShardingKey(String namespace, String realm, String
shardingKey) {
- if (!_routingDataWriterMap.containsKey(namespace) ||
!_routingDataMap.containsKey(namespace)) {
- // throwing NoSuchElementException instead of IllegalArgumentException
to differentiate the
- // status code in the Accessor level
- throw new NoSuchElementException(
- "Failed to add sharding key: Namespace " + namespace + " is not
found!");
- }
- if (_routingDataMap.get(namespace).containsKeyRealmPair(shardingKey,
realm)) {
- return true;
- }
- if
(!_routingDataMap.get(namespace).isShardingKeyInsertionValid(shardingKey)) {
- throw new IllegalArgumentException(
- "Failed to add sharding key: Adding sharding key " + shardingKey
- + " makes routing data invalid!");
+ synchronized (this) {
+ if (!_routingDataWriterMap.containsKey(namespace)) {
+ // throwing NoSuchElementException instead of IllegalArgumentException
to differentiate the
+ // status code in the Accessor level
+ throw new NoSuchElementException(
+ "Failed to add sharding key: Namespace " + namespace + " is not
found!");
+ }
+ if (_routingDataMap.containsKey(namespace) &&
_routingDataMap.get(namespace)
+ .containsKeyRealmPair(shardingKey, realm)) {
+ return true;
+ }
+ if (_routingDataMap.containsKey(namespace) &&
!_routingDataMap.get(namespace)
+ .isShardingKeyInsertionValid(shardingKey)) {
+ throw new IllegalArgumentException(
+ "Failed to add sharding key: Adding sharding key " + shardingKey
+ + " makes routing data invalid!");
+ }
+ boolean result =
_routingDataWriterMap.get(namespace).addShardingKey(realm, shardingKey);
+ refreshRoutingData(namespace);
+ return result;
}
- return _routingDataWriterMap.get(namespace).addShardingKey(realm,
shardingKey);
}
@Override
public boolean deleteShardingKey(String namespace, String realm, String
shardingKey) {
- if (!_routingDataWriterMap.containsKey(namespace)) {
- // throwing NoSuchElementException instead of IllegalArgumentException
to differentiate the
- // status code in the Accessor level
- throw new NoSuchElementException(
- "Failed to delete sharding key: Namespace " + namespace + " is not
found!");
+ synchronized (this) {
+ if (!_routingDataWriterMap.containsKey(namespace)) {
Review comment:
move it before synchronized
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]