Search in sources :

Example 1 with InvalidRoutingDataException

use of org.apache.helix.msdcommon.exception.InvalidRoutingDataException in project helix by apache.

the class ZKHelixManager method resolveZkClient.

/*
   * Resolves what type of ZkClient this HelixManager should use based on whether MULTI_ZK_ENABLED
   * System config is set or not. Two types of ZkClients are available:
   * 1) If MULTI_ZK_ENABLED is set to true or zkAddress is null, we create a dedicated
   * RealmAwareZkClient that provides full ZkClient functionalities and connects to the correct ZK
   * by querying MetadataStoreDirectoryService.
   * 2) Otherwise, we create a dedicated HelixZkClient which plainly connects to
   * the ZK address given.
   */
private RealmAwareZkClient resolveZkClient(HelixZkClientFactory zkClientFactory, RealmAwareZkClient.RealmAwareZkConnectionConfig connectionConfig, RealmAwareZkClient.RealmAwareZkClientConfig clientConfig) {
    if (Boolean.getBoolean(SystemPropertyKeys.MULTI_ZK_ENABLED) || _zkAddress == null) {
        try {
            // Create realm-aware ZkClient.
            return zkClientFactory.buildZkClient(connectionConfig, clientConfig);
        } catch (IllegalArgumentException | IOException | InvalidRoutingDataException e) {
            throw new HelixException("Not able to connect on realm-aware mode for sharding key: " + connectionConfig.getZkRealmShardingKey(), e);
        }
    }
    // If multi-zk mode is not enabled, create HelixZkClient with the provided zk address.
    HelixZkClient.ZkClientConfig helixZkClientConfig = clientConfig.createHelixZkClientConfig();
    HelixZkClient.ZkConnectionConfig helixZkConnectionConfig = new HelixZkClient.ZkConnectionConfig(_zkAddress).setSessionTimeout(connectionConfig.getSessionTimeout());
    return zkClientFactory.buildZkClient(helixZkConnectionConfig, helixZkClientConfig);
}
Also used : HelixException(org.apache.helix.HelixException) HelixZkClient(org.apache.helix.zookeeper.api.client.HelixZkClient) IOException(java.io.IOException) InvalidRoutingDataException(org.apache.helix.msdcommon.exception.InvalidRoutingDataException)

Example 2 with InvalidRoutingDataException

use of org.apache.helix.msdcommon.exception.InvalidRoutingDataException in project helix by apache.

the class ZKUtil method getHelixZkClient.

/**
 * Returns a dedicated ZkClient. A federatedZkClient will be used on multi-zk mode.
 * WARNING: ephemeral operations will not be supported on multi-zk mode!
 * @return
 */
private static RealmAwareZkClient getHelixZkClient(String zkAddr) {
    if (Boolean.getBoolean(SystemPropertyKeys.MULTI_ZK_ENABLED) || zkAddr == null) {
        try {
            // Create realm-aware ZkClient.
            RealmAwareZkClient.RealmAwareZkConnectionConfig connectionConfig = new RealmAwareZkClient.RealmAwareZkConnectionConfig.Builder().build();
            RealmAwareZkClient.RealmAwareZkClientConfig clientConfig = new RealmAwareZkClient.RealmAwareZkClientConfig();
            return new FederatedZkClient(connectionConfig, clientConfig);
        } catch (IllegalArgumentException | InvalidRoutingDataException e) {
            throw new HelixException("Not able to connect on realm-aware mode", e);
        }
    }
    if (zkAddr.isEmpty()) {
        throw new HelixException("ZK Address given is empty!");
    }
    HelixZkClient.ZkClientConfig clientConfig = new HelixZkClient.ZkClientConfig();
    clientConfig.setZkSerializer(new ZNRecordSerializer());
    return DedicatedZkClientFactory.getInstance().buildZkClient(new HelixZkClient.ZkConnectionConfig(zkAddr), clientConfig);
}
Also used : HelixZkClient(org.apache.helix.zookeeper.api.client.HelixZkClient) FederatedZkClient(org.apache.helix.zookeeper.impl.client.FederatedZkClient) HelixException(org.apache.helix.HelixException) InvalidRoutingDataException(org.apache.helix.msdcommon.exception.InvalidRoutingDataException) RealmAwareZkClient(org.apache.helix.zookeeper.api.client.RealmAwareZkClient)

Example 3 with InvalidRoutingDataException

use of org.apache.helix.msdcommon.exception.InvalidRoutingDataException in project helix by apache.

the class ZkBucketDataAccessor method createRealmAwareZkClient.

private static RealmAwareZkClient createRealmAwareZkClient(String zkAddr) {
    RealmAwareZkClient zkClient;
    if (Boolean.getBoolean(SystemPropertyKeys.MULTI_ZK_ENABLED) || zkAddr == null) {
        LOG.warn("ZkBucketDataAccessor: either multi-zk enabled or zkAddr is null - " + "starting ZkBucketDataAccessor in multi-zk mode!");
        try {
            // Create realm-aware ZkClient.
            RealmAwareZkClient.RealmAwareZkConnectionConfig connectionConfig = new RealmAwareZkClient.RealmAwareZkConnectionConfig.Builder().build();
            RealmAwareZkClient.RealmAwareZkClientConfig clientConfig = new RealmAwareZkClient.RealmAwareZkClientConfig();
            zkClient = new FederatedZkClient(connectionConfig, clientConfig);
        } catch (IllegalArgumentException | InvalidRoutingDataException e) {
            throw new HelixException("Not able to connect on realm-aware mode", e);
        }
    } else {
        zkClient = DedicatedZkClientFactory.getInstance().buildZkClient(new HelixZkClient.ZkConnectionConfig(zkAddr));
    }
    return zkClient;
}
Also used : FederatedZkClient(org.apache.helix.zookeeper.impl.client.FederatedZkClient) HelixException(org.apache.helix.HelixException) InvalidRoutingDataException(org.apache.helix.msdcommon.exception.InvalidRoutingDataException) RealmAwareZkClient(org.apache.helix.zookeeper.api.client.RealmAwareZkClient)

Example 4 with InvalidRoutingDataException

use of org.apache.helix.msdcommon.exception.InvalidRoutingDataException in project helix by apache.

the class TestZkRoutingDataReader method testGetRoutingDataMSRDChildEmptyValue.

@Test(dependsOnMethods = "testGetRoutingData")
public void testGetRoutingDataMSRDChildEmptyValue() {
    ZNRecord testZnRecord1 = new ZNRecord("testZnRecord1");
    testZnRecord1.setListField(MetadataStoreRoutingConstants.ZNRECORD_LIST_FIELD_KEY, Collections.emptyList());
    _gZkClientTestNS.createPersistent(MetadataStoreRoutingConstants.ROUTING_DATA_PATH + "/testRealmAddress1", testZnRecord1);
    try {
        Map<String, List<String>> routingData = _zkRoutingDataReader.getRoutingData();
        Assert.assertEquals(routingData.size(), 1);
        Assert.assertTrue(routingData.get("testRealmAddress1").isEmpty());
    } catch (InvalidRoutingDataException e) {
        Assert.fail("Not expecting InvalidRoutingDataException");
    }
}
Also used : List(java.util.List) ZNRecord(org.apache.helix.zookeeper.datamodel.ZNRecord) InvalidRoutingDataException(org.apache.helix.msdcommon.exception.InvalidRoutingDataException) Test(org.testng.annotations.Test)

Example 5 with InvalidRoutingDataException

use of org.apache.helix.msdcommon.exception.InvalidRoutingDataException in project helix by apache.

the class ZkRoutingDataReader method getRoutingData.

/**
 * Returns (realm, list of ZK path sharding keys) mappings.
 * @return Map <realm, list of ZK path sharding keys>
 * @throws InvalidRoutingDataException - when the node on
 *           MetadataStoreRoutingConstants.ROUTING_DATA_PATH is missing
 */
public Map<String, List<String>> getRoutingData() throws InvalidRoutingDataException {
    Map<String, List<String>> routingData = new HashMap<>();
    List<String> allRealmAddresses;
    try {
        allRealmAddresses = _zkClient.getChildren(MetadataStoreRoutingConstants.ROUTING_DATA_PATH);
    } catch (ZkNoNodeException e) {
        throw new InvalidRoutingDataException("Routing data directory ZNode " + MetadataStoreRoutingConstants.ROUTING_DATA_PATH + " does not exist. Routing ZooKeeper address: " + _zkAddress);
    }
    if (allRealmAddresses != null) {
        for (String realmAddress : allRealmAddresses) {
            ZNRecord record = _zkClient.readData(MetadataStoreRoutingConstants.ROUTING_DATA_PATH + "/" + realmAddress, true);
            if (record != null) {
                List<String> shardingKeys = record.getListField(MetadataStoreRoutingConstants.ZNRECORD_LIST_FIELD_KEY);
                routingData.put(realmAddress, shardingKeys != null ? shardingKeys : Collections.emptyList());
            }
        }
    }
    return routingData;
}
Also used : ZkNoNodeException(org.apache.helix.zookeeper.zkclient.exception.ZkNoNodeException) HashMap(java.util.HashMap) List(java.util.List) InvalidRoutingDataException(org.apache.helix.msdcommon.exception.InvalidRoutingDataException) ZNRecord(org.apache.helix.zookeeper.datamodel.ZNRecord)

Aggregations

InvalidRoutingDataException (org.apache.helix.msdcommon.exception.InvalidRoutingDataException)15 HelixException (org.apache.helix.HelixException)8 HelixZkClient (org.apache.helix.zookeeper.api.client.HelixZkClient)8 RealmAwareZkClient (org.apache.helix.zookeeper.api.client.RealmAwareZkClient)8 FederatedZkClient (org.apache.helix.zookeeper.impl.client.FederatedZkClient)6 List (java.util.List)5 ZNRecordSerializer (org.apache.helix.zookeeper.datamodel.serializer.ZNRecordSerializer)4 IOException (java.io.IOException)3 ZNRecord (org.apache.helix.zookeeper.datamodel.ZNRecord)3 CloudConfig (org.apache.helix.model.CloudConfig)2 TrieRoutingData (org.apache.helix.msdcommon.datamodel.TrieRoutingData)2 Test (org.testng.annotations.Test)2 HashMap (java.util.HashMap)1 ZKHelixManager (org.apache.helix.manager.zk.ZKHelixManager)1 ZkRoutingDataReader (org.apache.helix.rest.metadatastore.accessor.ZkRoutingDataReader)1 ZkRoutingDataWriter (org.apache.helix.rest.metadatastore.accessor.ZkRoutingDataWriter)1 ZkNoNodeException (org.apache.helix.zookeeper.zkclient.exception.ZkNoNodeException)1