Search in sources :

Example 16 with KeyspaceMetadata

use of org.apache.cassandra.schema.KeyspaceMetadata in project cassandra by apache.

the class StorageServiceServerTest method testPrimaryRangesWithNetworkTopologyStrategyOneDCOnly.

@Test
public void testPrimaryRangesWithNetworkTopologyStrategyOneDCOnly() throws Exception {
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();
    // DC1
    metadata.updateNormalToken(new StringToken("A"), InetAddress.getByName("127.0.0.1"));
    metadata.updateNormalToken(new StringToken("C"), InetAddress.getByName("127.0.0.2"));
    // DC2
    metadata.updateNormalToken(new StringToken("B"), InetAddress.getByName("127.0.0.4"));
    metadata.updateNormalToken(new StringToken("D"), InetAddress.getByName("127.0.0.5"));
    Map<String, String> configOptions = new HashMap<>();
    configOptions.put("DC2", "2");
    configOptions.put(ReplicationParams.CLASS, "NetworkTopologyStrategy");
    Keyspace.clear("Keyspace1");
    KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, configOptions));
    Schema.instance.load(meta);
    // endpoints in DC1 should not have primary range
    Collection<Range<Token>> primaryRanges = StorageService.instance.getPrimaryRangesForEndpoint(meta.name, InetAddress.getByName("127.0.0.1"));
    assert primaryRanges.isEmpty();
    primaryRanges = StorageService.instance.getPrimaryRangesForEndpoint(meta.name, InetAddress.getByName("127.0.0.2"));
    assert primaryRanges.isEmpty();
    // endpoints in DC2 should have primary ranges which also cover DC1
    primaryRanges = StorageService.instance.getPrimaryRangesForEndpoint(meta.name, InetAddress.getByName("127.0.0.4"));
    assert primaryRanges.size() == 2;
    assert primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("A")));
    assert primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B")));
    primaryRanges = StorageService.instance.getPrimaryRangesForEndpoint(meta.name, InetAddress.getByName("127.0.0.5"));
    assert primaryRanges.size() == 2;
    assert primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D")));
    assert primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C")));
}
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) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken) Test(org.junit.Test)

Example 17 with KeyspaceMetadata

use of org.apache.cassandra.schema.KeyspaceMetadata in project cassandra by apache.

the class StorageServiceServerTest method testPrimaryRangeForEndpointWithinDCWithSimpleStrategy.

/* Does not make much sense to use -local and -pr with simplestrategy, but just to prevent human errors */
@Test
public void testPrimaryRangeForEndpointWithinDCWithSimpleStrategy() throws Exception {
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();
    metadata.updateNormalToken(new StringToken("A"), InetAddress.getByName("127.0.0.1"));
    metadata.updateNormalToken(new StringToken("B"), InetAddress.getByName("127.0.0.2"));
    metadata.updateNormalToken(new StringToken("C"), InetAddress.getByName("127.0.0.3"));
    Map<String, String> configOptions = new HashMap<>();
    configOptions.put("replication_factor", "2");
    Keyspace.clear("Keyspace1");
    KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.simpleTransient(2));
    Schema.instance.load(meta);
    Collection<Range<Token>> primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.1"));
    assert primaryRanges.size() == 1;
    assert primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("A")));
    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.2"));
    assert primaryRanges.size() == 1;
    assert primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B")));
    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.3"));
    assert primaryRanges.size() == 1;
    assert primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C")));
}
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) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken) Test(org.junit.Test)

Example 18 with KeyspaceMetadata

use of org.apache.cassandra.schema.KeyspaceMetadata in project cassandra by apache.

the class StorageServiceServerTest method testPrimaryRangeForEndpointWithinDCWithVnodes.

@Test
public void testPrimaryRangeForEndpointWithinDCWithVnodes() throws Exception {
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();
    // DC1
    Multimap<InetAddress, Token> dc1 = HashMultimap.create();
    dc1.put(InetAddress.getByName("127.0.0.1"), new StringToken("A"));
    dc1.put(InetAddress.getByName("127.0.0.1"), new StringToken("E"));
    dc1.put(InetAddress.getByName("127.0.0.1"), new StringToken("H"));
    dc1.put(InetAddress.getByName("127.0.0.2"), new StringToken("C"));
    dc1.put(InetAddress.getByName("127.0.0.2"), new StringToken("I"));
    dc1.put(InetAddress.getByName("127.0.0.2"), new StringToken("J"));
    metadata.updateNormalTokens(dc1);
    // DC2
    Multimap<InetAddress, Token> dc2 = HashMultimap.create();
    dc2.put(InetAddress.getByName("127.0.0.4"), new StringToken("B"));
    dc2.put(InetAddress.getByName("127.0.0.4"), new StringToken("G"));
    dc2.put(InetAddress.getByName("127.0.0.4"), new StringToken("L"));
    dc2.put(InetAddress.getByName("127.0.0.5"), new StringToken("D"));
    dc2.put(InetAddress.getByName("127.0.0.5"), new StringToken("F"));
    dc2.put(InetAddress.getByName("127.0.0.5"), new StringToken("K"));
    metadata.updateNormalTokens(dc2);
    Map<String, String> configOptions = new HashMap<>();
    configOptions.put("DC1", "1");
    configOptions.put("DC2", "2");
    configOptions.put(ReplicationParams.CLASS, "NetworkTopologyStrategy");
    Keyspace.clear("Keyspace1");
    KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, configOptions));
    Schema.instance.load(meta);
    // endpoints in DC1 should have primary ranges which also cover DC2
    Collection<Range<Token>> primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.1"));
    assertEquals(8, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("J"), new StringToken("K"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("K"), new StringToken("L"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("L"), new StringToken("A"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("E"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("E"), new StringToken("F"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("F"), new StringToken("G"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("G"), new StringToken("H"))));
    // endpoints in DC1 should have primary ranges which also cover DC2
    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.2"));
    assertEquals(4, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("H"), new StringToken("I"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("I"), new StringToken("J"))));
    // endpoints in DC2 should have primary ranges which also cover DC1
    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.4"));
    assertEquals(4, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("F"), new StringToken("G"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("K"), new StringToken("L"))));
    // because /127.0.0.4 holds token "B" which is the next to token "A" from /127.0.0.1,
    // the node covers range (L, A]
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("L"), new StringToken("A"))));
    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.5"));
    assertTrue(primaryRanges.size() == 8);
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("E"), new StringToken("F"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("J"), new StringToken("K"))));
    // ranges from /127.0.0.1
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("E"))));
    // the next token to "H" in DC2 is "K" in /127.0.0.5, so (G, H] goes to /127.0.0.5
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("G"), new StringToken("H"))));
    // ranges from /127.0.0.2
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("H"), new StringToken("I"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("I"), new StringToken("J"))));
}
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) InetAddress(java.net.InetAddress) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken) Test(org.junit.Test)

Example 19 with KeyspaceMetadata

use of org.apache.cassandra.schema.KeyspaceMetadata in project cassandra by apache.

the class StorageServiceServerTest method testPrimaryRangesWithVnodes.

@Test
public void testPrimaryRangesWithVnodes() throws Exception {
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();
    // DC1
    Multimap<InetAddress, Token> dc1 = HashMultimap.create();
    dc1.put(InetAddress.getByName("127.0.0.1"), new StringToken("A"));
    dc1.put(InetAddress.getByName("127.0.0.1"), new StringToken("E"));
    dc1.put(InetAddress.getByName("127.0.0.1"), new StringToken("H"));
    dc1.put(InetAddress.getByName("127.0.0.2"), new StringToken("C"));
    dc1.put(InetAddress.getByName("127.0.0.2"), new StringToken("I"));
    dc1.put(InetAddress.getByName("127.0.0.2"), new StringToken("J"));
    metadata.updateNormalTokens(dc1);
    // DC2
    Multimap<InetAddress, Token> dc2 = HashMultimap.create();
    dc2.put(InetAddress.getByName("127.0.0.4"), new StringToken("B"));
    dc2.put(InetAddress.getByName("127.0.0.4"), new StringToken("G"));
    dc2.put(InetAddress.getByName("127.0.0.4"), new StringToken("L"));
    dc2.put(InetAddress.getByName("127.0.0.5"), new StringToken("D"));
    dc2.put(InetAddress.getByName("127.0.0.5"), new StringToken("F"));
    dc2.put(InetAddress.getByName("127.0.0.5"), new StringToken("K"));
    metadata.updateNormalTokens(dc2);
    Map<String, String> configOptions = new HashMap<>();
    configOptions.put("DC2", "2");
    configOptions.put(ReplicationParams.CLASS, "NetworkTopologyStrategy");
    Keyspace.clear("Keyspace1");
    KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, configOptions));
    Schema.instance.load(meta);
    // endpoints in DC1 should not have primary range
    Collection<Range<Token>> primaryRanges = StorageService.instance.getPrimaryRangesForEndpoint(meta.name, InetAddress.getByName("127.0.0.1"));
    assert primaryRanges.isEmpty();
    primaryRanges = StorageService.instance.getPrimaryRangesForEndpoint(meta.name, InetAddress.getByName("127.0.0.2"));
    assert primaryRanges.isEmpty();
    // endpoints in DC2 should have primary ranges which also cover DC1
    primaryRanges = StorageService.instance.getPrimaryRangesForEndpoint(meta.name, InetAddress.getByName("127.0.0.4"));
    assert primaryRanges.size() == 4;
    assert primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B")));
    assert primaryRanges.contains(new Range<Token>(new StringToken("F"), new StringToken("G")));
    assert primaryRanges.contains(new Range<Token>(new StringToken("K"), new StringToken("L")));
    // the node covers range (L, A]
    assert primaryRanges.contains(new Range<Token>(new StringToken("L"), new StringToken("A")));
    primaryRanges = StorageService.instance.getPrimaryRangesForEndpoint(meta.name, InetAddress.getByName("127.0.0.5"));
    assert primaryRanges.size() == 8;
    assert primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D")));
    assert primaryRanges.contains(new Range<Token>(new StringToken("E"), new StringToken("F")));
    assert primaryRanges.contains(new Range<Token>(new StringToken("J"), new StringToken("K")));
    // ranges from /127.0.0.1
    assert primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("E")));
    // the next token to "H" in DC2 is "K" in /127.0.0.5, so (G, H] goes to /127.0.0.5
    assert primaryRanges.contains(new Range<Token>(new StringToken("G"), new StringToken("H")));
    // ranges from /127.0.0.2
    assert primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C")));
    assert primaryRanges.contains(new Range<Token>(new StringToken("H"), new StringToken("I")));
    assert primaryRanges.contains(new Range<Token>(new StringToken("I"), new StringToken("J")));
}
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) InetAddress(java.net.InetAddress) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken) Test(org.junit.Test)

Example 20 with KeyspaceMetadata

use of org.apache.cassandra.schema.KeyspaceMetadata in project cassandra by apache.

the class StorageServiceServerTest method testPrimaryRangeForEndpointWithinDCWithNetworkTopologyStrategy.

@Test
public void testPrimaryRangeForEndpointWithinDCWithNetworkTopologyStrategy() throws Exception {
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();
    // DC1
    metadata.updateNormalToken(new StringToken("A"), InetAddress.getByName("127.0.0.1"));
    metadata.updateNormalToken(new StringToken("C"), InetAddress.getByName("127.0.0.2"));
    // DC2
    metadata.updateNormalToken(new StringToken("B"), InetAddress.getByName("127.0.0.4"));
    metadata.updateNormalToken(new StringToken("D"), InetAddress.getByName("127.0.0.5"));
    Map<String, String> configOptions = new HashMap<>();
    configOptions.put("DC1", "1");
    configOptions.put("DC2", "1");
    configOptions.put(ReplicationParams.CLASS, "NetworkTopologyStrategy");
    Keyspace.clear("Keyspace1");
    KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, configOptions));
    Schema.instance.load(meta);
    Collection<Range<Token>> primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.1"));
    assertEquals(2, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("A"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));
    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.2"));
    assertEquals(2, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));
    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.4"));
    assertEquals(2, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("A"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("A"), new StringToken("B"))));
    primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.5"));
    assertEquals(2, primaryRanges.size());
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));
    assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));
}
Also used : TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Range(org.apache.cassandra.dht.Range) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken) Test(org.junit.Test)

Aggregations

KeyspaceMetadata (org.apache.cassandra.schema.KeyspaceMetadata)30 Test (org.junit.Test)17 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)12 StringToken (org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken)11 Range (org.apache.cassandra.dht.Range)8 TableMetadata (org.apache.cassandra.schema.TableMetadata)8 InetAddress (java.net.InetAddress)6 LongToken (org.apache.cassandra.dht.Murmur3Partitioner.LongToken)6 Token (org.apache.cassandra.dht.Token)6 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)4 HashMap (java.util.HashMap)3 UserType (org.apache.cassandra.db.marshal.UserType)3 NetworkTopologyStrategy (org.apache.cassandra.locator.NetworkTopologyStrategy)3 TriggerMetadata (org.apache.cassandra.schema.TriggerMetadata)3 JavaBasedUDFunction (org.apache.cassandra.cql3.functions.JavaBasedUDFunction)1 UDAggregate (org.apache.cassandra.cql3.functions.UDAggregate)1 UDFunction (org.apache.cassandra.cql3.functions.UDFunction)1 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)1 DataInputBuffer (org.apache.cassandra.io.util.DataInputBuffer)1 DataOutputBufferFixed (org.apache.cassandra.io.util.DataOutputBufferFixed)1