use of com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraServer in project atlasdb by palantir.
the class Blacklist method checkAndUpdate.
void checkAndUpdate(Map<CassandraServer, CassandraClientPoolingContainer> pools) {
// Check blacklist and re-integrate or continue to wait as necessary
Iterator<Entry<CassandraServer, Long>> blacklistIterator = blacklist.entrySet().iterator();
while (blacklistIterator.hasNext()) {
Map.Entry<CassandraServer, Long> blacklistedEntry = blacklistIterator.next();
if (coolOffPeriodExpired(blacklistedEntry)) {
CassandraServer cassandraServer = blacklistedEntry.getKey();
if (!pools.containsKey(cassandraServer)) {
// Probably the pool changed underneath us
blacklistIterator.remove();
log.info("Removing cassandraServer {} from the blacklist as it wasn't found in the pool.", SafeArg.of("cassandraServer", cassandraServer.cassandraHostName()));
} else if (isHostHealthy(pools.get(cassandraServer))) {
blacklistIterator.remove();
log.info("Added cassandraServer {} back into the pool after a waiting period and successful health" + " check.", SafeArg.of("cassandraServer", cassandraServer.cassandraHostName()));
}
}
}
}
use of com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraServer in project atlasdb by palantir.
the class HostPartitioner method partitionByHost.
static <V> Map<CassandraServer, 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<CassandraServer, V> valuesByHost = ArrayListMultimap.create();
for (ByteBuffer key : partitionedByKey.keySet()) {
Preconditions.checkState(key.hasArray(), "Expected an array backed buffer");
Preconditions.checkState(key.arrayOffset() == 0, "Buffer array must have no offset");
Preconditions.checkState(key.limit() == key.array().length, "Array length must match the limit");
CassandraServer host = clientPool.getRandomServerForKey(key.array());
valuesByHost.putAll(host, partitionedByKey.get(key));
}
return Multimaps.asMap(valuesByHost);
}
use of com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraServer in project atlasdb by palantir.
the class CassandraRepairEteTest method tokenRangesToRepairShouldBeSubsetsOfTokenMap.
@Test
public void tokenRangesToRepairShouldBeSubsetsOfTokenMap() {
Map<CassandraServer, Set<Range<LightweightOppToken>>> fullTokenMap = getFullTokenMap();
RangesForRepair rangesToRepair = CassandraRepairHelper.getRangesToRepair(cqlCluster, ATLAS_SERVICE, TABLE_1);
KeyedStream.stream(rangesToRepair.tokenMap()).forEach((address, cqlRangesForHost) -> assertRangesToRepairAreSubsetsOfRangesFromTokenMap(fullTokenMap, address, cqlRangesForHost));
}
use of com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraServer in project atlasdb by palantir.
the class CassandraClientPoolTest method shouldRetryOnSameNodeToFailureAndThenRedirect.
@Test
public void shouldRetryOnSameNodeToFailureAndThenRedirect() {
// TODO(ssouza): make 4 =
// 1 + CassandraClientPoolImpl.MAX_TRIES_TOTAL - CassandraClientPoolImpl.MAX_TRIES_SAME_HOST
int numHosts = 4;
List<CassandraServer> serverList = new ArrayList<>();
for (int i = 0; i < numHosts; i++) {
serverList.add(getServerForIndex(i));
}
CassandraClientPoolImpl clientPool = throwingClientPoolWithServersInCurrentPool(ImmutableSet.copyOf(serverList), new SocketTimeoutException());
assertThatThrownBy(() -> runNoopWithRetryOnHost(serverList.get(0), clientPool)).isInstanceOf(Exception.class);
verifyNumberOfAttemptsOnHost(serverList.get(0), clientPool, CassandraClientPoolImpl.getMaxRetriesPerHost());
for (int i = 1; i < numHosts; i++) {
verifyNumberOfAttemptsOnHost(serverList.get(i), clientPool, 1);
}
}
use of com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraServer in project atlasdb by palantir.
the class CassandraRepairEteTest method assertRangesToRepairAreSubsetsOfRangesFromTokenMap.
// The ranges in CQL should be a subset of the Thrift ranges, except that the CQL ranges are also snipped,
// such that if the thrift range is [5..9] but we don't have data after 7, then the CQL range will be [5..7]
@SuppressWarnings({ "DnsLookup", "ReverseDnsLookup", "UnstableApiUsage" })
private void assertRangesToRepairAreSubsetsOfRangesFromTokenMap(Map<CassandraServer, Set<Range<LightweightOppToken>>> fullTokenMap, InetSocketAddress address, RangeSet<LightweightOppToken> cqlRangesForHost) {
String hostName = address.getHostName();
CassandraServer cassandraServer = CassandraServer.of(new InetSocketAddress(hostName, MultiCassandraUtils.CASSANDRA_THRIFT_PORT));
assertThat(fullTokenMap.get(cassandraServer)).isNotNull();
Set<Range<LightweightOppToken>> thriftRanges = fullTokenMap.get(cassandraServer);
cqlRangesForHost.asRanges().forEach(range -> assertThat(thriftRanges.stream().anyMatch(containsEntirely(range))).isTrue());
}
Aggregations