narendly commented on a change in pull request #788: Implement request
forwarding for ZkRoutingDataWriter
URL: https://github.com/apache/helix/pull/788#discussion_r384310461
##########
File path:
helix-rest/src/main/java/org/apache/helix/rest/metadatastore/ZkMetadataStoreDirectory.java
##########
@@ -42,49 +42,77 @@
/**
+ * NOTE: This is a singleton class. DO NOT EXTEND!
* ZK-based MetadataStoreDirectory that listens on the routing data in routing
ZKs with a update
* callback.
*/
public class ZkMetadataStoreDirectory implements MetadataStoreDirectory,
RoutingDataListener {
private static final Logger LOG =
LoggerFactory.getLogger(ZkMetadataStoreDirectory.class);
- // TODO: enable the line below when implementation is complete
// The following maps' keys represent the namespace
- private final Map<String, MetadataStoreRoutingDataReader>
_routingDataReaderMap;
- private final Map<String, MetadataStoreRoutingDataWriter>
_routingDataWriterMap;
- private final Map<String, MetadataStoreRoutingData> _routingDataMap;
- private final Map<String, String> _routingZkAddressMap;
+ // NOTE: made protected for testing reasons. DO NOT MODIFY!
+ protected final Map<String, MetadataStoreRoutingDataReader>
_routingDataReaderMap;
+ protected final Map<String, MetadataStoreRoutingDataWriter>
_routingDataWriterMap;
+ protected final Map<String, MetadataStoreRoutingData> _routingDataMap;
+ protected final Map<String, String> _routingZkAddressMap;
// <namespace, <realm, <list of sharding keys>> mappings
- private final Map<String, Map<String, List<String>>> _realmToShardingKeysMap;
+ protected final Map<String, Map<String, List<String>>>
_realmToShardingKeysMap;
- /**
- * Creates a ZkMetadataStoreDirectory based on the given routing ZK
addresses.
- * @param routingZkAddressMap (namespace, routing ZK connect string)
- * @throws InvalidRoutingDataException
- */
- public ZkMetadataStoreDirectory(Map<String, String> routingZkAddressMap)
+ private static volatile ZkMetadataStoreDirectory
_zkMetadataStoreDirectoryInstance;
+
+ public static ZkMetadataStoreDirectory getInstance() {
+ if (_zkMetadataStoreDirectoryInstance == null) {
+ synchronized (ZkMetadataStoreDirectory.class) {
+ if (_zkMetadataStoreDirectoryInstance == null) {
+ _zkMetadataStoreDirectoryInstance = new ZkMetadataStoreDirectory();
+ }
+ }
+ }
+
+ return _zkMetadataStoreDirectoryInstance;
+ }
+
+ public static ZkMetadataStoreDirectory getInstance(String namespace, String
zkAddress)
throws InvalidRoutingDataException {
- if (routingZkAddressMap == null || routingZkAddressMap.isEmpty()) {
- throw new InvalidRoutingDataException("Routing ZK Addresses given are
invalid!");
+ if (_zkMetadataStoreDirectoryInstance == null) {
+ synchronized (ZkMetadataStoreDirectory.class) {
+ if (_zkMetadataStoreDirectoryInstance == null) {
+ _zkMetadataStoreDirectoryInstance = new ZkMetadataStoreDirectory();
+ }
+ }
}
- _routingDataReaderMap = new HashMap<>();
- _routingDataWriterMap = new HashMap<>();
- _routingZkAddressMap = routingZkAddressMap;
+ _zkMetadataStoreDirectoryInstance.init(namespace, zkAddress);
Review comment:
Can you do
`getInstance().init(namespace, zkAddress); `here to cut down on duplicate
code?
----------------------------------------------------------------
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]