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")));
}
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);
}
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;
}
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));
}
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;
}
Aggregations