Search in sources :

Example 1 with ZkRoutingDataReader

use of org.apache.helix.rest.metadatastore.accessor.ZkRoutingDataReader 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);
                }
            }
        }
    }
}
Also used : HelixZkClient(org.apache.helix.zookeeper.api.client.HelixZkClient) ZkRoutingDataReader(org.apache.helix.rest.metadatastore.accessor.ZkRoutingDataReader) TrieRoutingData(org.apache.helix.msdcommon.datamodel.TrieRoutingData) ZkRoutingDataWriter(org.apache.helix.rest.metadatastore.accessor.ZkRoutingDataWriter) List(java.util.List) InvalidRoutingDataException(org.apache.helix.msdcommon.exception.InvalidRoutingDataException) ZNRecordSerializer(org.apache.helix.zookeeper.datamodel.serializer.ZNRecordSerializer)

Example 2 with ZkRoutingDataReader

use of org.apache.helix.rest.metadatastore.accessor.ZkRoutingDataReader in project helix by apache.

the class MetadataStoreDirectoryAccessorTestBase method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    _zkList = new ArrayList<>(ZK_SERVER_MAP.keySet());
    clearRoutingData();
    // Write dummy mappings in ZK
    // Create a node that represents a realm address and add 3 sharding keys to it
    ZNRecord znRecord = new ZNRecord("RoutingInfo");
    _zkList.forEach(zk -> {
        ZK_SERVER_MAP.get(zk).getZkClient().setZkSerializer(new ZNRecordSerializer());
        // Write first realm and sharding keys pair
        znRecord.setListField(MetadataStoreRoutingConstants.ZNRECORD_LIST_FIELD_KEY, TEST_SHARDING_KEYS_1);
        ZK_SERVER_MAP.get(zk).getZkClient().createPersistent(MetadataStoreRoutingConstants.ROUTING_DATA_PATH + "/" + TEST_REALM_1, true);
        ZK_SERVER_MAP.get(zk).getZkClient().writeData(MetadataStoreRoutingConstants.ROUTING_DATA_PATH + "/" + TEST_REALM_1, znRecord);
        // Create another realm and sharding keys pair
        znRecord.setListField(MetadataStoreRoutingConstants.ZNRECORD_LIST_FIELD_KEY, TEST_SHARDING_KEYS_2);
        ZK_SERVER_MAP.get(zk).getZkClient().createPersistent(MetadataStoreRoutingConstants.ROUTING_DATA_PATH + "/" + TEST_REALM_2, true);
        ZK_SERVER_MAP.get(zk).getZkClient().writeData(MetadataStoreRoutingConstants.ROUTING_DATA_PATH + "/" + TEST_REALM_2, znRecord);
    });
    _routingDataReader = new ZkRoutingDataReader(TEST_NAMESPACE, _zkAddrTestNS, null);
    System.setProperty(MetadataStoreRoutingConstants.MSDS_SERVER_HOSTNAME_KEY, getBaseUri().getHost());
    System.setProperty(MetadataStoreRoutingConstants.MSDS_SERVER_PORT_KEY, Integer.toString(getBaseUri().getPort()));
}
Also used : ZkRoutingDataReader(org.apache.helix.rest.metadatastore.accessor.ZkRoutingDataReader) ZNRecord(org.apache.helix.zookeeper.datamodel.ZNRecord) ZNRecordSerializer(org.apache.helix.zookeeper.datamodel.serializer.ZNRecordSerializer) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

ZkRoutingDataReader (org.apache.helix.rest.metadatastore.accessor.ZkRoutingDataReader)2 ZNRecordSerializer (org.apache.helix.zookeeper.datamodel.serializer.ZNRecordSerializer)2 List (java.util.List)1 TrieRoutingData (org.apache.helix.msdcommon.datamodel.TrieRoutingData)1 InvalidRoutingDataException (org.apache.helix.msdcommon.exception.InvalidRoutingDataException)1 ZkRoutingDataWriter (org.apache.helix.rest.metadatastore.accessor.ZkRoutingDataWriter)1 HelixZkClient (org.apache.helix.zookeeper.api.client.HelixZkClient)1 ZNRecord (org.apache.helix.zookeeper.datamodel.ZNRecord)1 BeforeClass (org.testng.annotations.BeforeClass)1