Search in sources :

Example 1 with CassandraServer

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()));
            }
        }
    }
}
Also used : CassandraServer(com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraServer) Entry(java.util.Map.Entry) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map)

Example 2 with CassandraServer

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);
}
Also used : CassandraServer(com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraServer) ByteBuffer(java.nio.ByteBuffer)

Example 3 with CassandraServer

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));
}
Also used : RangesForRepair(com.palantir.atlasdb.cassandra.backup.RangesForRepair) CassandraServer(com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraServer) RangeSet(com.google.common.collect.RangeSet) ImmutableRangeSet.toImmutableRangeSet(com.google.common.collect.ImmutableRangeSet.toImmutableRangeSet) Set(java.util.Set) HashSet(java.util.HashSet) LightweightOppToken(com.palantir.atlasdb.keyvalue.cassandra.LightweightOppToken) Test(org.junit.Test)

Example 4 with CassandraServer

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);
    }
}
Also used : CassandraServer(com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraServer) SocketTimeoutException(java.net.SocketTimeoutException) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with CassandraServer

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());
}
Also used : CassandraServer(com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraServer) InetSocketAddress(java.net.InetSocketAddress) FullyBoundedTimestampRange(com.palantir.timestamp.FullyBoundedTimestampRange) Range(com.google.common.collect.Range)

Aggregations

CassandraServer (com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraServer)9 Map (java.util.Map)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 CassandraVerifierConfig (com.palantir.atlasdb.keyvalue.cassandra.CassandraVerifier.CassandraVerifierConfig)2 FunctionCheckedException (com.palantir.common.base.FunctionCheckedException)2 SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 NotFoundException (org.apache.cassandra.thrift.NotFoundException)2 Test (org.junit.Test)2 HashMultimap (com.google.common.collect.HashMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableRangeSet.toImmutableRangeSet (com.google.common.collect.ImmutableRangeSet.toImmutableRangeSet)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Multimap (com.google.common.collect.Multimap)1 Range (com.google.common.collect.Range)1 RangeMap (com.google.common.collect.RangeMap)1