Search in sources :

Example 96 with TokenMetadata

use of org.apache.cassandra.locator.TokenMetadata in project cassandra by apache.

the class StorageServiceServerTest method testLocalPrimaryRangeForEndpointWithNetworkTopologyStrategy.

@Test
public void testLocalPrimaryRangeForEndpointWithNetworkTopologyStrategy() throws Exception {
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();
    // DC1
    metadata.updateNormalToken(new StringToken("A"), InetAddressAndPort.getByName("127.0.0.1"));
    metadata.updateNormalToken(new StringToken("C"), InetAddressAndPort.getByName("127.0.0.2"));
    // DC2
    metadata.updateNormalToken(new StringToken("B"), InetAddressAndPort.getByName("127.0.0.4"));
    metadata.updateNormalToken(new StringToken("D"), InetAddressAndPort.getByName("127.0.0.5"));
    Map<String, String> configOptions = new HashMap<>();
    configOptions.put("DC1", "2");
    configOptions.put("DC2", "2");
    configOptions.put(ReplicationParams.CLASS, "NetworkTopologyStrategy");
    Schema.instance.maybeRemoveKeyspaceInstance("Keyspace1");
    KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, configOptions));
    Schema.instance.load(meta);
    Collection<Range<Token>> primaryRanges = StorageService.instance.getLocalPrimaryRangeForEndpoint(InetAddressAndPort.getByName("127.0.0.1"));
    Assertions.assertThat(primaryRanges.size()).as(primaryRanges.toString()).isEqualTo(1);
    Assertions.assertThat(primaryRanges).contains(new Range<Token>(new StringToken("C"), new StringToken("A")));
    primaryRanges = StorageService.instance.getLocalPrimaryRangeForEndpoint(InetAddressAndPort.getByName("127.0.0.2"));
    Assertions.assertThat(primaryRanges.size()).as(primaryRanges.toString()).isEqualTo(1);
    Assertions.assertThat(primaryRanges).contains(new Range<Token>(new StringToken("A"), new StringToken("C")));
    primaryRanges = StorageService.instance.getLocalPrimaryRangeForEndpoint(InetAddressAndPort.getByName("127.0.0.4"));
    Assertions.assertThat(primaryRanges.size()).as(primaryRanges.toString()).isEqualTo(1);
    Assertions.assertThat(primaryRanges).contains(new Range<Token>(new StringToken("D"), new StringToken("B")));
    primaryRanges = StorageService.instance.getLocalPrimaryRangeForEndpoint(InetAddressAndPort.getByName("127.0.0.5"));
    Assertions.assertThat(primaryRanges.size()).as(primaryRanges.toString()).isEqualTo(1);
    Assertions.assertThat(primaryRanges).contains(new Range<Token>(new StringToken("B"), new StringToken("D")));
}
Also used : LongToken(org.apache.cassandra.dht.Murmur3Partitioner.LongToken) StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken) Token(org.apache.cassandra.dht.Token) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Range(org.apache.cassandra.dht.Range) StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken) Test(org.junit.Test)

Example 97 with TokenMetadata

use of org.apache.cassandra.locator.TokenMetadata in project cassandra by apache.

the class MoveTransientTest method constructTMDsMoveForward.

private Pair<TokenMetadata, TokenMetadata> constructTMDsMoveForward() {
    TokenMetadata tmd = new TokenMetadata();
    tmd.updateNormalToken(range_1_2.right, address01);
    tmd.updateNormalToken(range_3_6.right, address02);
    tmd.updateNormalToken(range_6_9.right, address03);
    tmd.updateNormalToken(range_9_11.right, address04);
    tmd.updateNormalToken(range_11_1.right, address05);
    tmd.addMovingEndpoint(fourToken, address01);
    TokenMetadata updated = tmd.cloneAfterAllSettled();
    return Pair.create(tmd, updated);
}
Also used : TokenMetadata(org.apache.cassandra.locator.TokenMetadata)

Example 98 with TokenMetadata

use of org.apache.cassandra.locator.TokenMetadata in project cassandra by apache.

the class TokenUpdater method update.

public TokenUpdater update() {
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();
    tmd.clearUnsafe();
    tmd.updateNormalTokens(endpointTokens);
    endpointTokens.keySet().stream().filter(e -> !e.equals(localEndpoint())).forEach(e -> Gossiper.instance.initializeNodeUnsafe(e, UUID.randomUUID(), 1));
    return this;
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) FBUtilities(org.apache.cassandra.utils.FBUtilities) Util(org.apache.cassandra.Util) StorageService(org.apache.cassandra.service.StorageService) UUID(java.util.UUID) Multimap(com.google.common.collect.Multimap) UnknownHostException(java.net.UnknownHostException) Gossiper(org.apache.cassandra.gms.Gossiper) List(java.util.List) Token(org.apache.cassandra.dht.Token) HashMultimap(com.google.common.collect.HashMultimap) ImmutableList(com.google.common.collect.ImmutableList) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner) TokenMetadata(org.apache.cassandra.locator.TokenMetadata)

Example 99 with TokenMetadata

use of org.apache.cassandra.locator.TokenMetadata in project cassandra by apache.

the class WriteResponseHandlerTransientTest method setupClass.

@BeforeClass
public static void setupClass() throws Throwable {
    SchemaLoader.loadSchema();
    DatabaseDescriptor.setTransientReplicationEnabledUnsafe(true);
    DatabaseDescriptor.setPartitionerUnsafe(Murmur3Partitioner.instance);
    // Register peers with expected DC for NetworkTopologyStrategy.
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();
    metadata.updateHostId(UUID.randomUUID(), InetAddressAndPort.getByName("127.1.0.1"));
    metadata.updateHostId(UUID.randomUUID(), InetAddressAndPort.getByName("127.2.0.1"));
    DatabaseDescriptor.setEndpointSnitch(new IEndpointSnitch() {

        public String getRack(InetAddressAndPort endpoint) {
            return null;
        }

        public String getDatacenter(InetAddressAndPort endpoint) {
            byte[] address = endpoint.getAddress().getAddress();
            if (address[1] == 1)
                return DC1;
            else
                return DC2;
        }

        public <C extends ReplicaCollection<? extends C>> C sortedByProximity(InetAddressAndPort address, C unsortedAddress) {
            return unsortedAddress;
        }

        public int compareEndpoints(InetAddressAndPort target, Replica a1, Replica a2) {
            return 0;
        }

        public void gossiperStarting() {
        }

        public boolean isWorthMergingForRangeQuery(ReplicaCollection<?> merged, ReplicaCollection<?> l1, ReplicaCollection<?> l2) {
            return false;
        }
    });
    DatabaseDescriptor.setBroadcastAddress(InetAddress.getByName("127.1.0.1"));
    SchemaLoader.createKeyspace("ks", KeyspaceParams.nts(DC1, "3/1", DC2, "3/1"), SchemaLoader.standardCFMD("ks", "tbl"));
    ks = Keyspace.open("ks");
    cfs = ks.getColumnFamilyStore("tbl");
    dummy = DatabaseDescriptor.getPartitioner().getToken(ByteBufferUtil.bytes(0));
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Replica(org.apache.cassandra.locator.Replica) IEndpointSnitch(org.apache.cassandra.locator.IEndpointSnitch) BeforeClass(org.junit.BeforeClass)

Example 100 with TokenMetadata

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

the class BootStrapperTest method testGuessToken.

@Test
public void testGuessToken() throws IOException {
    StorageService ss = StorageService.instance;
    generateFakeEndpoints(5);
    InetAddress two = InetAddress.getByName("127.0.0.2");
    InetAddress three = InetAddress.getByName("127.0.0.3");
    InetAddress four = InetAddress.getByName("127.0.0.4");
    InetAddress five = InetAddress.getByName("127.0.0.5");
    Map<InetAddress, Double> load = new HashMap<InetAddress, Double>();
    load.put(two, 2.0);
    load.put(three, 3.0);
    load.put(four, 4.0);
    load.put(five, 5.0);
    TokenMetadata tmd = ss.getTokenMetadata();
    InetAddress source = BootStrapper.getBootstrapSource(tmd, load);
    assert five.equals(source) : five + " != " + source;
    InetAddress myEndpoint = InetAddress.getByName("127.0.0.1");
    Range<Token> range5 = ss.getPrimaryRangeForEndpoint(five);
    Token fakeToken = StorageService.getPartitioner().midpoint(range5.left, range5.right);
    assert range5.contains(fakeToken);
    ss.onChange(myEndpoint, ApplicationState.STATUS, StorageService.instance.valueFactory.bootstrapping(fakeToken));
    tmd = ss.getTokenMetadata();
    InetAddress source4 = BootStrapper.getBootstrapSource(tmd, load);
    assert four.equals(source4) : four + " != " + source4;
}
Also used : HashMap(java.util.HashMap) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) InetAddress(java.net.InetAddress) StorageService(org.apache.cassandra.service.StorageService) Test(org.junit.Test)

Aggregations

TokenMetadata (org.apache.cassandra.locator.TokenMetadata)109 Test (org.junit.Test)66 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)43 Token (org.apache.cassandra.dht.Token)37 VersionedValue (org.apache.cassandra.gms.VersionedValue)22 InetAddress (java.net.InetAddress)21 Range (org.apache.cassandra.dht.Range)19 AbstractReplicationStrategy (org.apache.cassandra.locator.AbstractReplicationStrategy)19 StringToken (org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken)13 BigIntegerToken (org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken)13 Replica (org.apache.cassandra.locator.Replica)13 RangesAtEndpoint (org.apache.cassandra.locator.RangesAtEndpoint)11 IPartitioner (org.apache.cassandra.dht.IPartitioner)10 LongToken (org.apache.cassandra.dht.Murmur3Partitioner.LongToken)10 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)8 IEndpointSnitch (org.apache.cassandra.locator.IEndpointSnitch)8 RangesByEndpoint (org.apache.cassandra.locator.RangesByEndpoint)8 BeforeClass (org.junit.BeforeClass)8 Multimap (com.google.common.collect.Multimap)7 EndpointsForToken (org.apache.cassandra.locator.EndpointsForToken)7