private InetSocketAddress getHostForRow(byte[] row) { return clientPool.getRandomHostForKey(row); }
static <V> Map<InetSocketAddress, List<V>> partitionByHost(CassandraClientPool clientPool, Iterable<V> iterable, Function<V, byte[]> keyExtractor) { // Ensure that the same key goes to the same partition. This is important when writing multiple columns // to the same row, since this is a normally a single write in cassandra, whereas splitting the columns // into different requests results in multiple writes. ListMultimap<ByteBuffer, V> partitionedByKey = ArrayListMultimap.create(); for (V value : iterable) { partitionedByKey.put(ByteBuffer.wrap(keyExtractor.apply(value)), value); } ListMultimap<InetSocketAddress, V> valuesByHost = ArrayListMultimap.create(); for (ByteBuffer key : partitionedByKey.keySet()) { InetSocketAddress host = clientPool.getRandomHostForKey(key.array()); valuesByHost.putAll(host, partitionedByKey.get(key)); } return Multimaps.asMap(valuesByHost); } }
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 + ")"; } }); } }
private InetSocketAddress getHostForRow(byte[] row) { return clientPool.getRandomHostForKey(row); }
static <V> Map<InetSocketAddress, List<V>> partitionByHost(CassandraClientPool clientPool, Iterable<V> iterable, Function<V, byte[]> keyExtractor) { // Ensure that the same key goes to the same partition. This is important when writing multiple columns // to the same row, since this is a normally a single write in cassandra, whereas splitting the columns // into different requests results in multiple writes. ListMultimap<ByteBuffer, V> partitionedByKey = ArrayListMultimap.create(); for (V value : iterable) { partitionedByKey.put(ByteBuffer.wrap(keyExtractor.apply(value)), value); } ListMultimap<InetSocketAddress, V> valuesByHost = ArrayListMultimap.create(); for (ByteBuffer key : partitionedByKey.keySet()) { InetSocketAddress host = clientPool.getRandomHostForKey(key.array()); valuesByHost.putAll(host, partitionedByKey.get(key)); } return Multimaps.asMap(valuesByHost); } }
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 + ")"; } }); } }