TokenBackedBasicResultsPage<Entry<Cell, Value>, byte[]> page(final byte[] startCol) throws Exception { return clientPool.runWithRetryOnHost(host, new FunctionCheckedException< CassandraClient, TokenBackedBasicResultsPage<Entry<Cell, Value>, byte[]>,
final Iterable<Map.Entry<Cell, Value>> values, boolean overrideTimestamps) throws Exception { clientPool.runWithRetryOnHost(host, new FunctionCheckedException<CassandraClient, Void, Exception>() { @Override
private Void multiPutForSingleHostInternal(final InetSocketAddress host, final Set<TableReference> tableRefs, final List<TableCellAndValue> batch, long timestamp) throws Exception { final MutationMap mutationMap = convertToMutations(batch, timestamp); return clientPool.runWithRetryOnHost(host, new FunctionCheckedException<CassandraClient, Void, Exception>() { @Override public Void apply(CassandraClient client) throws Exception { return wrappingQueryRunner.batchMutate("multiPut", client, tableRefs, mutationMap, WRITE_CONSISTENCY); } @Override public String toString() { return "batch_mutate(" + host + ", " + tableRefs + ", " + batch.size() + " values)"; } }); }
private CqlResult executeFunctionOnHost( FunctionCheckedException<CassandraClient, CqlResult, TException> cqlFunction, InetSocketAddress host) { try { return clientPool.runWithRetryOnHost(host, cqlFunction); } catch (UnavailableException e) { throw wrapIfConsistencyAll(e); } catch (TException e) { throw Throwables.throwUncheckedException(e); } }
long startTs) { try { return clientPool.runWithRetryOnHost(host, new FunctionCheckedException<CassandraClient, RowColumnRangeExtractor.RowColumnRangeResult, Exception>() {
private void deleteAllTimestampsOnSingleHost( TableReference tableRef, InetSocketAddress host, Map<Cell, Long> maxTimestampExclusiveByCell, boolean deleteSentinels, long rangeTombstoneCassandraTs) { if (maxTimestampExclusiveByCell.isEmpty()) { return; } try { clientPool.runWithRetryOnHost(host, new FunctionCheckedException<CassandraClient, Void, Exception>() { @Override public Void apply(CassandraClient client) throws Exception { insertRangeTombstones(client, maxTimestampExclusiveByCell, tableRef, deleteSentinels, rangeTombstoneCassandraTs); return null; } @Override public String toString() { return "delete_timestamp_ranges_batch_mutate(" + host + ", " + tableRef.getQualifiedName() + ", " + maxTimestampExclusiveByCell.size() + " column timestamp ranges)"; } }); } catch (UnavailableException e) { throw new InsufficientConsistencyException("Deleting requires all Cassandra nodes to be up and available.", e); } catch (Exception e) { throw Throwables.unwrapAndThrowAtlasDbDependencyException(e); } }
public List<KeySlice> getRows(String kvsMethodName, KeyRange keyRange, SlicePredicate slicePredicate) { InetSocketAddress host = clientPool.getRandomHostForKey(keyRange.getStart_key()); return clientPool.runWithRetryOnHost( host, new FunctionCheckedException<CassandraClient, List<KeySlice>, RuntimeException>() { @Override public List<KeySlice> apply(CassandraClient client) { try { return queryRunner.run(client, tableRef, () -> client.get_range_slices(kvsMethodName, tableRef, slicePredicate, keyRange, consistency)); } catch (UnavailableException e) { throw new InsufficientConsistencyException("get_range_slices requires " + consistency + " Cassandra nodes to be up and available.", e); } catch (Exception e) { throw Throwables.unwrapAndThrowAtlasDbDependencyException(e); } } @Override public String toString() { return "get_range_slices(" + tableRef + ")"; } }); } }
@Override public CqlPreparedResult prepare(ByteBuffer query, byte[] rowHintForHostSelection, Compression compression) { FunctionCheckedException<CassandraClient, CqlPreparedResult, TException> prepareFunction = client -> client.prepare_cql3_query(query, compression); try { InetSocketAddress hostForRow = getHostForRow(rowHintForHostSelection); CqlPreparedResult preparedResult = clientPool.runWithRetryOnHost(hostForRow, prepareFunction); hostsPerPreparedQuery.put(preparedResult.getItemId(), hostForRow); return preparedResult; } catch (TException e) { throw Throwables.throwUncheckedException(e); } }
private void runNoopWithRetryOnHost(InetSocketAddress host, CassandraClientPool pool) { pool.runWithRetryOnHost(host, noOp()); }
final Map<Cell, Collection<Long>> cellVersionsMap) { try { clientPool.runWithRetryOnHost(host, new FunctionCheckedException<CassandraClient, Void, Exception>() { private int numVersions = 0;
for (final List<byte[]> batch : Lists.partition(rows, fetchBatchCount)) { rowCount += batch.size(); result.putAll(clientPool.runWithRetryOnHost(host, new FunctionCheckedException<CassandraClient, Map<Cell, Value>, Exception>() { @Override
Callable<Void> multiGetCallable = () -> clientPool.runWithRetryOnHost( host, new FunctionCheckedException<CassandraClient, Void, Exception>() {
@Test public void shouldNotAttemptMoreThanOneConnectionOnSuccess() { CassandraClientPool cassandraClientPool = clientPoolWithServersInCurrentPool(ImmutableSet.of(HOST_1)); cassandraClientPool.runWithRetryOnHost(HOST_1, noOp()); verifyNumberOfAttemptsOnHost(HOST_1, cassandraClientPool, 1); }
TokenBackedBasicResultsPage<Entry<Cell, Value>, byte[]> page(final byte[] startCol) throws Exception { return clientPool.runWithRetryOnHost(host, new FunctionCheckedException< CassandraClient, TokenBackedBasicResultsPage<Entry<Cell, Value>, byte[]>,
private Void multiPutForSingleHostInternal(final InetSocketAddress host, final Set<TableReference> tableRefs, final List<TableCellAndValue> batch, long timestamp) throws Exception { final MutationMap mutationMap = convertToMutations(batch, timestamp); return clientPool.runWithRetryOnHost(host, new FunctionCheckedException<CassandraClient, Void, Exception>() { @Override public Void apply(CassandraClient client) throws Exception { return wrappingQueryRunner.batchMutate("multiPut", client, tableRefs, mutationMap, WRITE_CONSISTENCY); } @Override public String toString() { return "batch_mutate(" + host + ", " + tableRefs + ", " + batch.size() + " values)"; } }); }
long startTs) { try { return clientPool.runWithRetryOnHost(host, new FunctionCheckedException<CassandraClient, RowColumnRangeExtractor.RowColumnRangeResult, Exception>() {
private CqlResult executeFunctionOnHost( FunctionCheckedException<CassandraClient, CqlResult, TException> cqlFunction, InetSocketAddress host) { try { return clientPool.runWithRetryOnHost(host, cqlFunction); } catch (UnavailableException e) { throw wrapIfConsistencyAll(e); } catch (TException e) { throw Throwables.throwUncheckedException(e); } }
private void deleteAllTimestampsOnSingleHost( TableReference tableRef, InetSocketAddress host, Map<Cell, Long> maxTimestampExclusiveByCell, boolean deleteSentinels, long rangeTombstoneCassandraTs) { if (maxTimestampExclusiveByCell.isEmpty()) { return; } try { clientPool.runWithRetryOnHost(host, new FunctionCheckedException<CassandraClient, Void, Exception>() { @Override public Void apply(CassandraClient client) throws Exception { insertRangeTombstones(client, maxTimestampExclusiveByCell, tableRef, deleteSentinels, rangeTombstoneCassandraTs); return null; } @Override public String toString() { return "delete_timestamp_ranges_batch_mutate(" + host + ", " + tableRef.getQualifiedName() + ", " + maxTimestampExclusiveByCell.size() + " column timestamp ranges)"; } }); } catch (UnavailableException e) { throw new InsufficientConsistencyException("Deleting requires all Cassandra nodes to be up and available.", e); } catch (Exception e) { throw Throwables.unwrapAndThrowAtlasDbDependencyException(e); } }
public List<KeySlice> getRows(String kvsMethodName, KeyRange keyRange, SlicePredicate slicePredicate) { InetSocketAddress host = clientPool.getRandomHostForKey(keyRange.getStart_key()); return clientPool.runWithRetryOnHost( host, new FunctionCheckedException<CassandraClient, List<KeySlice>, RuntimeException>() { @Override public List<KeySlice> apply(CassandraClient client) { try { return queryRunner.run(client, tableRef, () -> client.get_range_slices(kvsMethodName, tableRef, slicePredicate, keyRange, consistency)); } catch (UnavailableException e) { throw new InsufficientConsistencyException("get_range_slices requires " + consistency + " Cassandra nodes to be up and available.", e); } catch (Exception e) { throw Throwables.unwrapAndThrowAtlasDbDependencyException(e); } } @Override public String toString() { return "get_range_slices(" + tableRef + ")"; } }); } }
@Override public CqlPreparedResult prepare(ByteBuffer query, byte[] rowHintForHostSelection, Compression compression) { FunctionCheckedException<CassandraClient, CqlPreparedResult, TException> prepareFunction = client -> client.prepare_cql3_query(query, compression); try { InetSocketAddress hostForRow = getHostForRow(rowHintForHostSelection); CqlPreparedResult preparedResult = clientPool.runWithRetryOnHost(hostForRow, prepareFunction); hostsPerPreparedQuery.put(preparedResult.getItemId(), hostForRow); return preparedResult; } catch (TException e) { throw Throwables.throwUncheckedException(e); } }