Search in sources :

Example 1 with ZKDiscoveryService

use of org.apache.twill.discovery.ZKDiscoveryService in project phoenix by apache.

the class ConnectionQueryServicesImpl method initTxServiceClient.

private void initTxServiceClient() {
    String zkQuorumServersString = this.getProps().get(TxConstants.Service.CFG_DATA_TX_ZOOKEEPER_QUORUM);
    if (zkQuorumServersString == null) {
        zkQuorumServersString = connectionInfo.getZookeeperQuorum() + ":" + connectionInfo.getPort();
    }
    int timeOut = props.getInt(HConstants.ZK_SESSION_TIMEOUT, HConstants.DEFAULT_ZK_SESSION_TIMEOUT);
    // Create instance of the tephra zookeeper client
    txZKClientService = ZKClientServices.delegate(ZKClients.reWatchOnExpire(ZKClients.retryOnFailure(new TephraZKClientService(zkQuorumServersString, timeOut, null, ArrayListMultimap.<String, byte[]>create()), RetryStrategies.exponentialDelay(500, 2000, TimeUnit.MILLISECONDS))));
    txZKClientService.startAndWait();
    ZKDiscoveryService zkDiscoveryService = new ZKDiscoveryService(txZKClientService);
    PooledClientProvider pooledClientProvider = new PooledClientProvider(config, zkDiscoveryService);
    this.txServiceClient = new TransactionServiceClient(config, pooledClientProvider);
}
Also used : ZKDiscoveryService(org.apache.twill.discovery.ZKDiscoveryService) PTinyint(org.apache.phoenix.schema.types.PTinyint) PUnsignedTinyint(org.apache.phoenix.schema.types.PUnsignedTinyint) MultiRowMutationEndpoint(org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint) TephraZKClientService(org.apache.tephra.zookeeper.TephraZKClientService) PooledClientProvider(org.apache.tephra.distributed.PooledClientProvider) TransactionServiceClient(org.apache.tephra.distributed.TransactionServiceClient)

Example 2 with ZKDiscoveryService

use of org.apache.twill.discovery.ZKDiscoveryService in project phoenix by apache.

the class BaseTest method setupTxManager.

protected static void setupTxManager() throws SQLException, IOException {
    ConnectionInfo connInfo = ConnectionInfo.create(getUrl());
    zkClient = ZKClientServices.delegate(ZKClients.reWatchOnExpire(ZKClients.retryOnFailure(ZKClientService.Builder.of(connInfo.getZookeeperConnectionString()).setSessionTimeout(config.getInt(HConstants.ZK_SESSION_TIMEOUT, HConstants.DEFAULT_ZK_SESSION_TIMEOUT)).build(), RetryStrategies.exponentialDelay(500, 2000, TimeUnit.MILLISECONDS))));
    zkClient.startAndWait();
    DiscoveryService discovery = new ZKDiscoveryService(zkClient);
    txManager = new TransactionManager(config, new HDFSTransactionStateStorage(config, new SnapshotCodecProvider(config), new TxMetricsCollector()), new TxMetricsCollector());
    txService = new TransactionService(config, zkClient, discovery, Providers.of(txManager));
    txService.startAndWait();
}
Also used : ZKDiscoveryService(org.apache.twill.discovery.ZKDiscoveryService) HDFSTransactionStateStorage(org.apache.tephra.persist.HDFSTransactionStateStorage) TransactionService(org.apache.tephra.distributed.TransactionService) TransactionManager(org.apache.tephra.TransactionManager) TxMetricsCollector(org.apache.tephra.metrics.TxMetricsCollector) ConnectionInfo(org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo) DiscoveryService(org.apache.twill.discovery.DiscoveryService) ZKDiscoveryService(org.apache.twill.discovery.ZKDiscoveryService) SnapshotCodecProvider(org.apache.tephra.snapshot.SnapshotCodecProvider)

Example 3 with ZKDiscoveryService

use of org.apache.twill.discovery.ZKDiscoveryService in project cdap by caskdata.

the class ResourceBalancerServiceTest method testResourceBalancerService.

@Test
public void testResourceBalancerService() throws Exception {
    // Simple test for resource balancer does react to discovery changes correct
    // More detailed tests are in ResourceCoordinatorTest, which the ResourceBalancerService depends on
    ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
    zkClient.startAndWait();
    try (ZKDiscoveryService discoveryService = new ZKDiscoveryService(zkClient)) {
        // Test the failure on stop case
        final TestBalancerService stopFailureService = new TestBalancerService("test", 4, zkClient, discoveryService, discoveryService, false, false);
        stopFailureService.startAndWait();
        // Should get all four partitions
        Tasks.waitFor(ImmutableSet.of(0, 1, 2, 3), new Callable<Set<Integer>>() {

            @Override
            public Set<Integer> call() throws Exception {
                return stopFailureService.getPartitions();
            }
        }, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
        // Register a new discoverable, this should trigger a partition change in the resource balancer service
        Cancellable cancellable = discoveryService.register(new Discoverable("test", new InetSocketAddress(InetAddress.getLoopbackAddress(), 1234)));
        try {
            // Should get reduced to two partitions
            Tasks.waitFor(2, new Callable<Integer>() {

                @Override
                public Integer call() throws Exception {
                    return stopFailureService.getPartitions().size();
                }
            }, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
        } finally {
            cancellable.cancel();
        }
    } finally {
        zkClient.stopAndWait();
    }
}
Also used : ZKDiscoveryService(org.apache.twill.discovery.ZKDiscoveryService) Discoverable(org.apache.twill.discovery.Discoverable) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ZKClientService(org.apache.twill.zookeeper.ZKClientService) Cancellable(org.apache.twill.common.Cancellable) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with ZKDiscoveryService

use of org.apache.twill.discovery.ZKDiscoveryService in project cdap by caskdata.

the class ResourceBalancerServiceTest method testServiceStopFailure.

@Test
public void testServiceStopFailure() throws Exception {
    ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
    zkClient.startAndWait();
    try (ZKDiscoveryService discoveryService = new ZKDiscoveryService(zkClient)) {
        // Test the failure on stop case
        final TestBalancerService stopFailureService = new TestBalancerService("test", 4, zkClient, discoveryService, discoveryService, false, true);
        stopFailureService.startAndWait();
        // Should get four partitions
        Tasks.waitFor(ImmutableSet.of(0, 1, 2, 3), new Callable<Set<Integer>>() {

            @Override
            public Set<Integer> call() throws Exception {
                return stopFailureService.getPartitions();
            }
        }, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
        // Register a new discoverable, this should trigger a partition change in the resource balancer service
        Cancellable cancellable = discoveryService.register(new Discoverable("test", new InetSocketAddress(InetAddress.getLoopbackAddress(), 1234)));
        try {
            // When there is exception thrown by the underlying service during partition change,
            // the resource balancer service should fail.
            Tasks.waitFor(Service.State.FAILED, new Callable<Service.State>() {

                @Override
                public Service.State call() throws Exception {
                    return stopFailureService.state();
                }
            }, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
        } finally {
            cancellable.cancel();
        }
    } finally {
        zkClient.stopAndWait();
    }
}
Also used : ZKDiscoveryService(org.apache.twill.discovery.ZKDiscoveryService) Discoverable(org.apache.twill.discovery.Discoverable) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ZKClientService(org.apache.twill.zookeeper.ZKClientService) Cancellable(org.apache.twill.common.Cancellable) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with ZKDiscoveryService

use of org.apache.twill.discovery.ZKDiscoveryService in project cdap by caskdata.

the class ResourceBalancerServiceTest method testServiceStartFailure.

@Test
public void testServiceStartFailure() throws Exception {
    ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
    zkClient.startAndWait();
    try (ZKDiscoveryService discoveryService = new ZKDiscoveryService(zkClient)) {
        // Test the failure on start case
        final TestBalancerService startFailureService = new TestBalancerService("test", 4, zkClient, discoveryService, discoveryService, true, false);
        startFailureService.startAndWait();
        // The resource balance service should fail
        Tasks.waitFor(Service.State.FAILED, new Callable<Service.State>() {

            @Override
            public Service.State call() throws Exception {
                return startFailureService.state();
            }
        }, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
    } finally {
        zkClient.stopAndWait();
    }
}
Also used : ZKDiscoveryService(org.apache.twill.discovery.ZKDiscoveryService) ZKClientService(org.apache.twill.zookeeper.ZKClientService) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

ZKDiscoveryService (org.apache.twill.discovery.ZKDiscoveryService)5 IOException (java.io.IOException)3 ZKClientService (org.apache.twill.zookeeper.ZKClientService)3 Test (org.junit.Test)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 InetSocketAddress (java.net.InetSocketAddress)2 Set (java.util.Set)2 Cancellable (org.apache.twill.common.Cancellable)2 Discoverable (org.apache.twill.discovery.Discoverable)2 MultiRowMutationEndpoint (org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint)1 ConnectionInfo (org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo)1 PTinyint (org.apache.phoenix.schema.types.PTinyint)1 PUnsignedTinyint (org.apache.phoenix.schema.types.PUnsignedTinyint)1 TransactionManager (org.apache.tephra.TransactionManager)1 PooledClientProvider (org.apache.tephra.distributed.PooledClientProvider)1 TransactionService (org.apache.tephra.distributed.TransactionService)1 TransactionServiceClient (org.apache.tephra.distributed.TransactionServiceClient)1 TxMetricsCollector (org.apache.tephra.metrics.TxMetricsCollector)1 HDFSTransactionStateStorage (org.apache.tephra.persist.HDFSTransactionStateStorage)1 SnapshotCodecProvider (org.apache.tephra.snapshot.SnapshotCodecProvider)1