use of org.apache.cassandra.locator.TokenMetadata 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);
}
use of org.apache.cassandra.locator.TokenMetadata in project cassandra by apache.
the class StorageProxyTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Throwable {
DatabaseDescriptor.daemonInitialization();
DatabaseDescriptor.getHintsDirectory().mkdir();
TokenMetadata tmd = StorageService.instance.getTokenMetadata();
tmd.updateNormalToken(token("1"), InetAddress.getByName("127.0.0.1"));
tmd.updateNormalToken(token("6"), InetAddress.getByName("127.0.0.6"));
}
use of org.apache.cassandra.locator.TokenMetadata in project cassandra by apache.
the class StorageServiceServerTest method testPrimaryRangesWithNetworkTopologyStrategy.
@Test
public void testPrimaryRangesWithNetworkTopologyStrategy() 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.getPrimaryRangesForEndpoint(meta.name, InetAddress.getByName("127.0.0.1"));
assert primaryRanges.size() == 1;
assert primaryRanges.contains(new Range<Token>(new StringToken("D"), new StringToken("A")));
primaryRanges = StorageService.instance.getPrimaryRangesForEndpoint(meta.name, InetAddress.getByName("127.0.0.2"));
assert primaryRanges.size() == 1;
assert primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C")));
primaryRanges = StorageService.instance.getPrimaryRangesForEndpoint(meta.name, InetAddress.getByName("127.0.0.4"));
assert primaryRanges.size() == 1;
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() == 1;
assert primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D")));
}
use of org.apache.cassandra.locator.TokenMetadata in project cassandra by apache.
the class StorageServiceServerTest method testPrimaryRangesWithSimpleStrategy.
@Test
public void testPrimaryRangesWithSimpleStrategy() 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"));
Keyspace.clear("Keyspace1");
KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.simpleTransient(2));
Schema.instance.load(meta);
Collection<Range<Token>> primaryRanges = StorageService.instance.getPrimaryRangesForEndpoint(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.getPrimaryRangesForEndpoint(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.getPrimaryRangesForEndpoint(meta.name, InetAddress.getByName("127.0.0.3"));
assert primaryRanges.size() == 1;
assert primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C")));
}
use of org.apache.cassandra.locator.TokenMetadata in project cassandra by apache.
the class StorageServiceServerTest method testPrimaryRangeForEndpointWithinDCWithNetworkTopologyStrategyOneDCOnly.
@Test
public void testPrimaryRangeForEndpointWithinDCWithNetworkTopologyStrategyOneDCOnly() 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.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.1"));
assertTrue(primaryRanges.isEmpty());
primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.2"));
assertTrue(primaryRanges.isEmpty());
// endpoints in DC2 should have primary ranges which also cover DC1
primaryRanges = StorageService.instance.getPrimaryRangeForEndpointWithinDC(meta.name, InetAddress.getByName("127.0.0.4"));
assertTrue(primaryRanges.size() == 2);
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"));
assertTrue(primaryRanges.size() == 2);
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("C"), new StringToken("D"))));
assertTrue(primaryRanges.contains(new Range<Token>(new StringToken("B"), new StringToken("C"))));
}
Aggregations