Search in sources :

Example 21 with AbstractReplicationStrategy

use of org.apache.cassandra.locator.AbstractReplicationStrategy in project eiger by wlloyd.

the class AntiEntropyServiceTestAbstract method testGetNeighborsTimesTwo.

@Test
public void testGetNeighborsTimesTwo() throws Throwable {
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();
    // generate rf*2 nodes, and ensure that only neighbors specified by the ARS are returned
    addTokens(2 * Table.open(tablename).getReplicationStrategy().getReplicationFactor());
    AbstractReplicationStrategy ars = Table.open(tablename).getReplicationStrategy();
    Set<InetAddress> expected = new HashSet<InetAddress>();
    for (Range<Token> replicaRange : ars.getAddressRanges().get(FBUtilities.getBroadcastAddress())) {
        expected.addAll(ars.getRangeAddresses(tmd).get(replicaRange));
    }
    expected.remove(FBUtilities.getBroadcastAddress());
    Collection<Range<Token>> ranges = StorageService.instance.getLocalRanges(tablename);
    Set<InetAddress> neighbors = new HashSet<InetAddress>();
    for (Range<Token> range : ranges) {
        neighbors.addAll(AntiEntropyService.getNeighbors(tablename, range));
    }
    assertEquals(expected, neighbors);
}
Also used : AbstractReplicationStrategy(org.apache.cassandra.locator.AbstractReplicationStrategy) Token(org.apache.cassandra.dht.Token) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Range(org.apache.cassandra.dht.Range) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 22 with AbstractReplicationStrategy

use of org.apache.cassandra.locator.AbstractReplicationStrategy in project eiger by wlloyd.

the class LeaveAndBootstrapTest method newTestWriteEndpointsDuringLeave.

/**
     * Test whether write endpoints is correct when the node is leaving. Uses
     * StorageService.onChange and does not manipulate token metadata directly.
     */
@Test
public void newTestWriteEndpointsDuringLeave() throws Exception {
    StorageService ss = StorageService.instance;
    final int RING_SIZE = 6;
    final int LEAVING_NODE = 3;
    TokenMetadata tmd = ss.getTokenMetadata();
    tmd.clearUnsafe();
    IPartitioner partitioner = new RandomPartitioner();
    VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner);
    IPartitioner oldPartitioner = ss.setPartitionerUnsafe(partitioner);
    ArrayList<Token> endpointTokens = new ArrayList<Token>();
    ArrayList<Token> keyTokens = new ArrayList<Token>();
    List<InetAddress> hosts = new ArrayList<InetAddress>();
    Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, RING_SIZE);
    Map<Token, List<InetAddress>> expectedEndpoints = new HashMap<Token, List<InetAddress>>();
    for (String table : Schema.instance.getNonSystemTables()) {
        for (Token token : keyTokens) {
            List<InetAddress> endpoints = new ArrayList<InetAddress>();
            Iterator<Token> tokenIter = TokenMetadata.ringIterator(tmd.sortedTokens(), token, false);
            while (tokenIter.hasNext()) {
                endpoints.add(tmd.getEndpoint(tokenIter.next()));
            }
            expectedEndpoints.put(token, endpoints);
        }
    }
    // Third node leaves
    ss.onChange(hosts.get(LEAVING_NODE), ApplicationState.STATUS, valueFactory.leaving(endpointTokens.get(LEAVING_NODE)));
    assertTrue(tmd.isLeaving(hosts.get(LEAVING_NODE)));
    AbstractReplicationStrategy strategy;
    for (String table : Schema.instance.getNonSystemTables()) {
        strategy = getStrategy(table, tmd);
        for (Token token : keyTokens) {
            int replicationFactor = strategy.getReplicationFactor();
            HashSet<InetAddress> actual = new HashSet<InetAddress>(tmd.getWriteEndpoints(token, table, strategy.calculateNaturalEndpoints(token, tmd)));
            HashSet<InetAddress> expected = new HashSet<InetAddress>();
            for (int i = 0; i < replicationFactor; i++) {
                expected.add(expectedEndpoints.get(token).get(i));
            }
            // then we should expect it plus one extra for when it's gone
            if (expected.contains(hosts.get(LEAVING_NODE)))
                expected.add(expectedEndpoints.get(token).get(replicationFactor));
            assertEquals("mismatched endpoint sets", expected, actual);
        }
    }
    ss.setPartitionerUnsafe(oldPartitioner);
}
Also used : VersionedValue(org.apache.cassandra.gms.VersionedValue) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) AbstractReplicationStrategy(org.apache.cassandra.locator.AbstractReplicationStrategy) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Aggregations

AbstractReplicationStrategy (org.apache.cassandra.locator.AbstractReplicationStrategy)22 InetAddress (java.net.InetAddress)19 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)14 Test (org.junit.Test)12 Token (org.apache.cassandra.dht.Token)8 VersionedValue (org.apache.cassandra.gms.VersionedValue)8 Range (org.apache.cassandra.dht.Range)5 HashMultimap (com.google.common.collect.HashMultimap)4 Multimap (com.google.common.collect.Multimap)4 BigIntegerToken (org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken)4 IPartitioner (org.apache.cassandra.dht.IPartitioner)3 NetworkTopologyStrategy (org.apache.cassandra.locator.NetworkTopologyStrategy)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Keyspace (org.apache.cassandra.db.Keyspace)1 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)1 EndpointState (org.apache.cassandra.gms.EndpointState)1 IEndpointSnitch (org.apache.cassandra.locator.IEndpointSnitch)1 ProgressEvent (org.apache.cassandra.utils.progress.ProgressEvent)1