@Override public void close() throws IOException { try { if (txService != null) txService.stopAndWait(); } finally { if (zkClient != null) zkClient.stopAndWait(); } }
public void start() { zkClient.startAndWait(); txService.startAndWait(); }
@Override public CloseableThriftClient getCloseableClient() throws TException, TimeoutException, InterruptedException { TransactionServiceThriftClient client = getClientPool().obtain(obtainClientTimeoutMs, TimeUnit.MILLISECONDS); return new CloseableThriftClient(this, client); }
PooledClientProvider pooledClientProvider = new PooledClientProvider( config, zkDiscoveryService); TransactionServiceClient txClient = new TransactionServiceClient(config,pooledClientProvider); TephraTransactionClient client = new TephraTransactionClient(zkClientService, txClient); client.start();
@Override public void returnClient(TransactionServiceThriftClient client) { getClientPool().release(client); }
@Override public CloseableThriftClient getCloseableClient() throws TException, TimeoutException, InterruptedException { return new CloseableThriftClient(this, newClient(timeout)); }
@Override public PhoenixTransactionService getTransactionService(Configuration config, ConnectionInfo connInfo, int port) { config.setInt(TxConstants.Service.CFG_DATA_TX_BIND_PORT, port); int retryTimeOut = config.getInt(TxConstants.Service.CFG_DATA_TX_CLIENT_DISCOVERY_TIMEOUT_SEC, TxConstants.Service.DEFAULT_DATA_TX_CLIENT_DISCOVERY_TIMEOUT_SEC); ZKClientService 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, retryTimeOut, TimeUnit.MILLISECONDS) ) ) ); DiscoveryService discovery = new ZKDiscoveryService(zkClient); TransactionManager txManager = new TransactionManager(config, new HDFSTransactionStateStorage(config, new SnapshotCodecProvider(config), new TxMetricsCollector()), new TxMetricsCollector()); TransactionService txService = new TransactionService(config, zkClient, discovery, Providers.of(txManager)); TephraTransactionService service = new TephraTransactionService(zkClient, txService); service.start(); return service; }
@Override public void close() { // in any case, the client must be returned to the pool. The pool is // responsible for discarding the client if it is in a bad state. provider.returnClient(thriftClient); } }
@Override public Void execute(TransactionServiceThriftClient client) throws Exception { client.canCommit(tx, changeIds); return null; } });
@Override Transaction execute(TransactionServiceThriftClient client) throws Exception { return client.checkpoint(tx); } }
@Override public Boolean execute(TransactionServiceThriftClient client) throws TException { return client.truncateInvalidTx(invalidTxIds); } });
@Override public Integer execute(TransactionServiceThriftClient client) throws TException { return client.getInvalidSize(); } });
@Override public Transaction execute(TransactionServiceThriftClient client) throws TException { return client.startLong(clientId); } });
@Override public Boolean execute(TransactionServiceThriftClient client) throws TException { return client.invalidate(tx); } });
@Override public Transaction execute(TransactionServiceThriftClient client) throws TException { return client.startShort(clientId, timeout); } });
@Override public boolean canCommit(final Transaction tx, final Collection<byte[]> changeIds) throws TransactionNotInProgressException { try { canCommitOrThrow(tx, changeIds); return true; } catch (TransactionFailureException e) { return false; } }
@Override public InputStream execute(TransactionServiceThriftClient client) throws Exception { return client.getSnapshotStream(); } });
@Override public RetryStrategy newRetryStrategy() { return new RetryNTimes(nTimes); }
@Override public RetryStrategy newRetryStrategy() { return new RetryWithBackoff(initialSleep, backoffFactor, maxSleep); }