Search in sources :

Example 31 with Token

use of org.apache.cassandra.dht.Token in project cassandra by apache.

the class RemoveTest method testNonmemberId.

@Test(expected = UnsupportedOperationException.class)
public void testNonmemberId() {
    VersionedValueFactory valueFactory = new VersionedValueFactory(DatabaseDescriptor.getPartitioner());
    Collection<Token> tokens = Collections.singleton(DatabaseDescriptor.getPartitioner().getRandomToken());
    InetAddress joininghost = hosts.get(4);
    UUID joiningId = hostIds.get(4);
    hosts.remove(joininghost);
    hostIds.remove(joiningId);
    // Change a node to a bootstrapping node that is not yet a member of the ring
    Gossiper.instance.injectApplicationState(joininghost, ApplicationState.TOKENS, valueFactory.tokens(tokens));
    ss.onChange(joininghost, ApplicationState.STATUS, valueFactory.bootstrapping(tokens));
    ss.removeNode(joiningId.toString());
}
Also used : VersionedValueFactory(org.apache.cassandra.gms.VersionedValue.VersionedValueFactory) Token(org.apache.cassandra.dht.Token) UUID(java.util.UUID) InetAddress(java.net.InetAddress)

Example 32 with Token

use of org.apache.cassandra.dht.Token in project cassandra by apache.

the class ActiveRepairServiceTest method testGetNeighborsTimesTwoInLocalDC.

@Test
public void testGetNeighborsTimesTwoInLocalDC() throws Throwable {
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();
    // generate rf*2 nodes, and ensure that only neighbors specified by the ARS are returned
    addTokens(2 * Keyspace.open(KEYSPACE5).getReplicationStrategy().getReplicationFactor());
    AbstractReplicationStrategy ars = Keyspace.open(KEYSPACE5).getReplicationStrategy();
    Set<InetAddress> expected = new HashSet<>();
    for (Range<Token> replicaRange : ars.getAddressRanges().get(FBUtilities.getBroadcastAddress())) {
        expected.addAll(ars.getRangeAddresses(tmd.cloneOnlyTokenMap()).get(replicaRange));
    }
    expected.remove(FBUtilities.getBroadcastAddress());
    // remove remote endpoints
    TokenMetadata.Topology topology = tmd.cloneOnlyTokenMap().getTopology();
    HashSet<InetAddress> localEndpoints = Sets.newHashSet(topology.getDatacenterEndpoints().get(DatabaseDescriptor.getLocalDataCenter()));
    expected = Sets.intersection(expected, localEndpoints);
    Collection<Range<Token>> ranges = StorageService.instance.getLocalRanges(KEYSPACE5);
    Set<InetAddress> neighbors = new HashSet<>();
    for (Range<Token> range : ranges) {
        neighbors.addAll(ActiveRepairService.getNeighbors(KEYSPACE5, ranges, range, Arrays.asList(DatabaseDescriptor.getLocalDataCenter()), null));
    }
    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 33 with Token

use of org.apache.cassandra.dht.Token in project cassandra by apache.

the class ActiveRepairServiceTest method testGetNeighborsTimesTwoInSpecifiedHosts.

@Test
public void testGetNeighborsTimesTwoInSpecifiedHosts() throws Throwable {
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();
    // generate rf*2 nodes, and ensure that only neighbors specified by the hosts are returned
    addTokens(2 * Keyspace.open(KEYSPACE5).getReplicationStrategy().getReplicationFactor());
    AbstractReplicationStrategy ars = Keyspace.open(KEYSPACE5).getReplicationStrategy();
    List<InetAddress> expected = new ArrayList<>();
    for (Range<Token> replicaRange : ars.getAddressRanges().get(FBUtilities.getBroadcastAddress())) {
        expected.addAll(ars.getRangeAddresses(tmd.cloneOnlyTokenMap()).get(replicaRange));
    }
    expected.remove(FBUtilities.getBroadcastAddress());
    Collection<String> hosts = Arrays.asList(FBUtilities.getBroadcastAddress().getCanonicalHostName(), expected.get(0).getCanonicalHostName());
    Collection<Range<Token>> ranges = StorageService.instance.getLocalRanges(KEYSPACE5);
    assertEquals(expected.get(0), ActiveRepairService.getNeighbors(KEYSPACE5, ranges, ranges.iterator().next(), null, hosts).iterator().next());
}
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 34 with Token

use of org.apache.cassandra.dht.Token in project cassandra by apache.

the class ActiveRepairServiceTest method testGetNeighborsPlusOneInLocalDC.

@Test
public void testGetNeighborsPlusOneInLocalDC() throws Throwable {
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();
    // generate rf+1 nodes, and ensure that all nodes are returned
    Set<InetAddress> expected = addTokens(1 + Keyspace.open(KEYSPACE5).getReplicationStrategy().getReplicationFactor());
    expected.remove(FBUtilities.getBroadcastAddress());
    // remove remote endpoints
    TokenMetadata.Topology topology = tmd.cloneOnlyTokenMap().getTopology();
    HashSet<InetAddress> localEndpoints = Sets.newHashSet(topology.getDatacenterEndpoints().get(DatabaseDescriptor.getLocalDataCenter()));
    expected = Sets.intersection(expected, localEndpoints);
    Collection<Range<Token>> ranges = StorageService.instance.getLocalRanges(KEYSPACE5);
    Set<InetAddress> neighbors = new HashSet<>();
    for (Range<Token> range : ranges) {
        neighbors.addAll(ActiveRepairService.getNeighbors(KEYSPACE5, ranges, range, Arrays.asList(DatabaseDescriptor.getLocalDataCenter()), null));
    }
    assertEquals(expected, neighbors);
}
Also used : 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 35 with Token

use of org.apache.cassandra.dht.Token in project cassandra by apache.

the class StreamingTransferTest method transferRanges.

private void transferRanges(ColumnFamilyStore cfs) throws Exception {
    IPartitioner p = cfs.getPartitioner();
    List<Range<Token>> ranges = new ArrayList<>();
    // wrapped range
    ranges.add(new Range<Token>(p.getToken(ByteBufferUtil.bytes("key1")), p.getToken(ByteBufferUtil.bytes("key0"))));
    StreamPlan streamPlan = new StreamPlan("StreamingTransferTest").transferRanges(LOCAL, cfs.keyspace.getName(), ranges, cfs.getTableName());
    streamPlan.execute().get();
    verifyConnectionsAreClosed();
    //cannot add ranges after stream session is finished
    try {
        streamPlan.transferRanges(LOCAL, cfs.keyspace.getName(), ranges, cfs.getTableName());
        fail("Should have thrown exception");
    } catch (RuntimeException e) {
    //do nothing
    }
}
Also used : Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Aggregations

Token (org.apache.cassandra.dht.Token)173 Range (org.apache.cassandra.dht.Range)73 InetAddress (java.net.InetAddress)66 Test (org.junit.Test)65 BigIntegerToken (org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken)27 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)27 IPartitioner (org.apache.cassandra.dht.IPartitioner)26 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)23 ArrayList (java.util.ArrayList)16 UUID (java.util.UUID)16 VersionedValue (org.apache.cassandra.gms.VersionedValue)15 StringToken (org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken)14 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)9 IOException (java.io.IOException)8 ByteBuffer (java.nio.ByteBuffer)8 BytesToken (org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken)8 AbstractReplicationStrategy (org.apache.cassandra.locator.AbstractReplicationStrategy)8 Set (java.util.Set)7 LongToken (org.apache.cassandra.dht.Murmur3Partitioner.LongToken)7 HashSet (java.util.HashSet)6