Search in sources :

Example 1 with TrieRoutingData

use of org.apache.helix.msdcommon.datamodel.TrieRoutingData in project helix by apache.

the class RoutingDataManager method getMetadataStoreRoutingData.

/**
 * Returns the routing data read from MSDS as a MetadataStoreRoutingData object.
 * @param routingDataReaderType
 * @param endpoint
 * @return
 * @throws IOException
 * @throws InvalidRoutingDataException
 */
public MetadataStoreRoutingData getMetadataStoreRoutingData(RoutingDataReaderType routingDataReaderType, String endpoint) throws InvalidRoutingDataException {
    String routingDataCacheKey = getRoutingDataCacheKey(routingDataReaderType, endpoint);
    MetadataStoreRoutingData metadataStoreRoutingData = _metadataStoreRoutingDataMap.get(routingDataCacheKey);
    if (metadataStoreRoutingData == null) {
        synchronized (RoutingDataManager.class) {
            metadataStoreRoutingData = _metadataStoreRoutingDataMap.get(routingDataCacheKey);
            if (metadataStoreRoutingData == null) {
                metadataStoreRoutingData = new TrieRoutingData(getRawRoutingData(routingDataReaderType, endpoint));
                _metadataStoreRoutingDataMap.put(routingDataCacheKey, metadataStoreRoutingData);
            }
        }
    }
    return metadataStoreRoutingData;
}
Also used : MetadataStoreRoutingData(org.apache.helix.msdcommon.datamodel.MetadataStoreRoutingData) TrieRoutingData(org.apache.helix.msdcommon.datamodel.TrieRoutingData)

Example 2 with TrieRoutingData

use of org.apache.helix.msdcommon.datamodel.TrieRoutingData in project helix by apache.

the class ZkMetadataStoreDirectory method refreshRoutingData.

/**
 * Callback for updating the cached routing data.
 * Note: this method should not synchronize on the class or the map. We do not want namespaces
 * blocking each other.
 * Threadsafe map is used for _realmToShardingKeysMap.
 * The global consistency of the in-memory routing data is not a requirement (eventual consistency
 * is enough).
 * @param namespace
 */
@Override
public void refreshRoutingData(String namespace) {
    // Check if namespace exists; otherwise, return as a NOP and log it
    if (!_routingZkAddressMap.containsKey(namespace)) {
        LOG.error("Failed to refresh internally-cached routing data! Namespace not found: " + namespace);
        return;
    }
    Map<String, List<String>> rawRoutingData;
    try {
        rawRoutingData = _routingDataReaderMap.get(namespace).getRoutingData();
    } catch (InvalidRoutingDataException e) {
        LOG.error("Failed to refresh cached routing data for namespace {}", namespace, e);
        _realmToShardingKeysMap.put(namespace, Collections.emptyMap());
        _routingDataMap.remove(namespace);
        return;
    }
    _realmToShardingKeysMap.put(namespace, rawRoutingData);
    TrieRoutingData trieRoutingData;
    try {
        trieRoutingData = new TrieRoutingData(rawRoutingData);
    } catch (InvalidRoutingDataException e) {
        LOG.warn("TrieRoutingData is not created for namespace {}", namespace, e);
        _routingDataMap.remove(namespace);
        return;
    }
    _routingDataMap.put(namespace, trieRoutingData);
}
Also used : TrieRoutingData(org.apache.helix.msdcommon.datamodel.TrieRoutingData) List(java.util.List) InvalidRoutingDataException(org.apache.helix.msdcommon.exception.InvalidRoutingDataException)

Example 3 with TrieRoutingData

use of org.apache.helix.msdcommon.datamodel.TrieRoutingData 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)

Aggregations

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