use of org.apache.cassandra.locator.TokenMetadata in project cassandra by apache.
the class ViewUtilsTest method testGetIndexNaturalEndpoint.
@Test
public void testGetIndexNaturalEndpoint() 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> replicationMap = new HashMap<>();
replicationMap.put(ReplicationParams.CLASS, NetworkTopologyStrategy.class.getName());
replicationMap.put("DC1", "1");
replicationMap.put("DC2", "1");
Keyspace.clear("Keyspace1");
KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, replicationMap));
Schema.instance.load(meta);
Optional<InetAddress> naturalEndpoint = ViewUtils.getViewNaturalEndpoint("Keyspace1", new StringToken("CA"), new StringToken("BB"));
Assert.assertTrue(naturalEndpoint.isPresent());
Assert.assertEquals(InetAddress.getByName("127.0.0.2"), naturalEndpoint.get());
}
use of org.apache.cassandra.locator.TokenMetadata in project cassandra by apache.
the class ViewUtilsTest method testLocalHostPreference.
@Test
public void testLocalHostPreference() 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> replicationMap = new HashMap<>();
replicationMap.put(ReplicationParams.CLASS, NetworkTopologyStrategy.class.getName());
replicationMap.put("DC1", "2");
replicationMap.put("DC2", "2");
Keyspace.clear("Keyspace1");
KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, replicationMap));
Schema.instance.load(meta);
Optional<InetAddress> naturalEndpoint = ViewUtils.getViewNaturalEndpoint("Keyspace1", new StringToken("CA"), new StringToken("BB"));
Assert.assertTrue(naturalEndpoint.isPresent());
Assert.assertEquals(InetAddress.getByName("127.0.0.1"), naturalEndpoint.get());
}
use of org.apache.cassandra.locator.TokenMetadata in project cassandra by apache.
the class BootStrapperTest method testSourceTargetComputation.
private RangeStreamer testSourceTargetComputation(String keyspaceName, int numOldNodes, int replicationFactor) throws UnknownHostException {
StorageService ss = StorageService.instance;
TokenMetadata tmd = ss.getTokenMetadata();
generateFakeEndpoints(numOldNodes);
Token myToken = tmd.partitioner.getRandomToken();
InetAddress myEndpoint = InetAddress.getByName("127.0.0.1");
assertEquals(numOldNodes, tmd.sortedTokens().size());
RangeStreamer s = new RangeStreamer(tmd, null, myEndpoint, "Bootstrap", true, DatabaseDescriptor.getEndpointSnitch(), new StreamStateStore(), false, 1);
IFailureDetector mockFailureDetector = new IFailureDetector() {
public boolean isAlive(InetAddress ep) {
return true;
}
public void interpret(InetAddress ep) {
throw new UnsupportedOperationException();
}
public void report(InetAddress ep) {
throw new UnsupportedOperationException();
}
public void registerFailureDetectionEventListener(IFailureDetectionEventListener listener) {
throw new UnsupportedOperationException();
}
public void unregisterFailureDetectionEventListener(IFailureDetectionEventListener listener) {
throw new UnsupportedOperationException();
}
public void remove(InetAddress ep) {
throw new UnsupportedOperationException();
}
public void forceConviction(InetAddress ep) {
throw new UnsupportedOperationException();
}
};
s.addSourceFilter(new RangeStreamer.FailureDetectorSourceFilter(mockFailureDetector));
s.addRanges(keyspaceName, Keyspace.open(keyspaceName).getReplicationStrategy().getPendingAddressRanges(tmd, myToken, myEndpoint));
Collection<Map.Entry<InetAddress, Collection<Range<Token>>>> toFetch = s.toFetch().get(keyspaceName);
// Check we get get RF new ranges in total
Set<Range<Token>> ranges = new HashSet<>();
for (Map.Entry<InetAddress, Collection<Range<Token>>> e : toFetch) ranges.addAll(e.getValue());
assertEquals(replicationFactor, ranges.size());
// is used, they will vary.
assert toFetch.iterator().next().getValue().size() > 0;
assert !toFetch.iterator().next().getKey().equals(myEndpoint);
return s;
}
use of org.apache.cassandra.locator.TokenMetadata in project cassandra by apache.
the class BootStrapperTest method testAllocateTokens.
@Test
public void testAllocateTokens() throws UnknownHostException {
int vn = 16;
String ks = "BootStrapperTestKeyspace3";
TokenMetadata tm = new TokenMetadata();
generateFakeEndpoints(tm, 10, vn);
InetAddress addr = FBUtilities.getBroadcastAddress();
allocateTokensForNode(vn, ks, tm, addr);
}
use of org.apache.cassandra.locator.TokenMetadata in project cassandra by apache.
the class BootStrapperTest method testAllocateTokensNetworkStrategy.
public void testAllocateTokensNetworkStrategy(int rackCount, int replicas) throws UnknownHostException {
IEndpointSnitch oldSnitch = DatabaseDescriptor.getEndpointSnitch();
try {
DatabaseDescriptor.setEndpointSnitch(new RackInferringSnitch());
int vn = 16;
String ks = "BootStrapperTestNTSKeyspace" + rackCount + replicas;
String dc = "1";
// Register peers with expected DC for NetworkTopologyStrategy.
TokenMetadata metadata = StorageService.instance.getTokenMetadata();
metadata.clearUnsafe();
metadata.updateHostId(UUID.randomUUID(), InetAddress.getByName("127.1.0.99"));
metadata.updateHostId(UUID.randomUUID(), InetAddress.getByName("127.15.0.99"));
SchemaLoader.createKeyspace(ks, KeyspaceParams.nts(dc, replicas, "15", 15), SchemaLoader.standardCFMD(ks, "Standard1"));
TokenMetadata tm = StorageService.instance.getTokenMetadata();
tm.clearUnsafe();
for (int i = 0; i < rackCount; ++i) generateFakeEndpoints(tm, 10, vn, dc, Integer.toString(i));
InetAddress addr = InetAddress.getByName("127." + dc + ".0.99");
allocateTokensForNode(vn, ks, tm, addr);
// Note: Not matching replication factor in second datacentre, but this should not affect us.
} finally {
DatabaseDescriptor.setEndpointSnitch(oldSnitch);
}
}
Aggregations