use of org.apache.helix.rest.metadatastore.accessor.ZkRoutingDataWriter in project helix by apache.
the class ZkMetadataStoreDirectory method init.
private void init(String namespace, String zkAddress) throws InvalidRoutingDataException {
if (!_routingZkAddressMap.containsKey(namespace)) {
synchronized (_routingZkAddressMap) {
if (!_routingZkAddressMap.containsKey(namespace)) {
HelixZkClient zkClient = null;
try {
// Ensure that ROUTING_DATA_PATH exists in ZK.
zkClient = DedicatedZkClientFactory.getInstance().buildZkClient(new HelixZkClient.ZkConnectionConfig(zkAddress), new HelixZkClient.ZkClientConfig().setZkSerializer(new ZNRecordSerializer()));
createRoutingDataPath(zkClient, zkAddress);
} finally {
if (zkClient != null && !zkClient.isClosed()) {
zkClient.close();
}
}
try {
_routingZkAddressMap.put(namespace, zkAddress);
_routingDataReaderMap.put(namespace, new ZkRoutingDataReader(namespace, zkAddress, this));
_routingDataWriterMap.put(namespace, new ZkRoutingDataWriter(namespace, zkAddress));
} catch (IllegalArgumentException | IllegalStateException e) {
LOG.error("ZkMetadataStoreDirectory: initializing ZkRoutingDataReader/Writer failed!", e);
}
// Populate realmToShardingKeys with ZkRoutingDataReader
Map<String, List<String>> rawRoutingData = _routingDataReaderMap.get(namespace).getRoutingData();
_realmToShardingKeysMap.put(namespace, rawRoutingData);
try {
_routingDataMap.put(namespace, new TrieRoutingData(rawRoutingData));
} catch (InvalidRoutingDataException e) {
LOG.warn("ZkMetadataStoreDirectory: TrieRoutingData is not created for namespace {}", namespace, e);
}
}
}
}
}
Aggregations