use of org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken in project cassandra by apache.
the class OldNetworkTopologyStrategyTest method addEndpoint.
private void addEndpoint(String endpointTokenID, String keyTokenID, String endpointAddress) throws UnknownHostException {
BigIntegerToken endpointToken = new BigIntegerToken(endpointTokenID);
BigIntegerToken keyToken = new BigIntegerToken(keyTokenID);
keyTokens.add(keyToken);
InetAddress ep = InetAddress.getByName(endpointAddress);
tmd.updateNormalToken(endpointToken, ep);
}
use of org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken in project cassandra by apache.
the class ReplicationStrategyEndpointCacheTest method runCacheRespectsTokenChangesTest.
public void runCacheRespectsTokenChangesTest(Class stratClass, Map<String, String> configOptions) throws Exception {
setup(stratClass, configOptions);
ArrayList<InetAddress> initial;
ArrayList<InetAddress> endpoints;
endpoints = strategy.getNaturalEndpoints(searchToken);
assert endpoints.size() == 5 : StringUtils.join(endpoints, ",");
// test token addition, in DC2 before existing token
initial = strategy.getNaturalEndpoints(searchToken);
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(35)), InetAddress.getByName("127.0.0.5"));
endpoints = strategy.getNaturalEndpoints(searchToken);
assert endpoints.size() == 5 : StringUtils.join(endpoints, ",");
assert !endpoints.equals(initial);
// test token removal, newly created token
initial = strategy.getNaturalEndpoints(searchToken);
tmd.removeEndpoint(InetAddress.getByName("127.0.0.5"));
endpoints = strategy.getNaturalEndpoints(searchToken);
assert endpoints.size() == 5 : StringUtils.join(endpoints, ",");
assert !endpoints.contains(InetAddress.getByName("127.0.0.5"));
assert !endpoints.equals(initial);
// test token change
initial = strategy.getNaturalEndpoints(searchToken);
//move .8 after search token but before other DC3
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(25)), InetAddress.getByName("127.0.0.8"));
endpoints = strategy.getNaturalEndpoints(searchToken);
assert endpoints.size() == 5 : StringUtils.join(endpoints, ",");
assert !endpoints.equals(initial);
}
use of org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken in project cassandra by apache.
the class ReplicationStrategyEndpointCacheTest method setup.
public void setup(Class stratClass, Map<String, String> strategyOptions) throws Exception {
tmd = new TokenMetadata();
searchToken = new BigIntegerToken(String.valueOf(15));
strategy = getStrategyWithNewTokenMetadata(Keyspace.open(KEYSPACE).getReplicationStrategy(), tmd);
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(10)), InetAddress.getByName("127.0.0.1"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(20)), InetAddress.getByName("127.0.0.2"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(30)), InetAddress.getByName("127.0.0.3"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(40)), InetAddress.getByName("127.0.0.4"));
//tmd.updateNormalToken(new BigIntegerToken(String.valueOf(50)), InetAddress.getByName("127.0.0.5"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(60)), InetAddress.getByName("127.0.0.6"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(70)), InetAddress.getByName("127.0.0.7"));
tmd.updateNormalToken(new BigIntegerToken(String.valueOf(80)), InetAddress.getByName("127.0.0.8"));
}
use of org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken in project cassandra by apache.
the class SimpleStrategyTest method testGetEndpointsDuringBootstrap.
@Test
public void testGetEndpointsDuringBootstrap() throws UnknownHostException {
// the token difference will be RING_SIZE * 2.
final int RING_SIZE = 10;
TokenMetadata tmd = new TokenMetadata();
TokenMetadata oldTmd = StorageServiceAccessor.setTokenMetadata(tmd);
Token[] endpointTokens = new Token[RING_SIZE];
Token[] keyTokens = new Token[RING_SIZE];
for (int i = 0; i < RING_SIZE; i++) {
endpointTokens[i] = new BigIntegerToken(String.valueOf(RING_SIZE * 2 * i));
keyTokens[i] = new BigIntegerToken(String.valueOf(RING_SIZE * 2 * i + RING_SIZE));
}
List<InetAddress> hosts = new ArrayList<InetAddress>();
for (int i = 0; i < endpointTokens.length; i++) {
InetAddress ep = InetAddress.getByName("127.0.0." + String.valueOf(i + 1));
tmd.updateNormalToken(endpointTokens[i], ep);
hosts.add(ep);
}
// bootstrap at the end of the ring
Token bsToken = new BigIntegerToken(String.valueOf(210));
InetAddress bootstrapEndpoint = InetAddress.getByName("127.0.0.11");
tmd.addBootstrapToken(bsToken, bootstrapEndpoint);
AbstractReplicationStrategy strategy = null;
for (String keyspaceName : Schema.instance.getNonLocalStrategyKeyspaces()) {
strategy = getStrategy(keyspaceName, tmd);
PendingRangeCalculatorService.calculatePendingRanges(strategy, keyspaceName);
int replicationFactor = strategy.getReplicationFactor();
for (int i = 0; i < keyTokens.length; i++) {
Collection<InetAddress> endpoints = tmd.getWriteEndpoints(keyTokens[i], keyspaceName, strategy.getNaturalEndpoints(keyTokens[i]));
assertTrue(endpoints.size() >= replicationFactor);
for (int j = 0; j < replicationFactor; j++) {
//Check that the old nodes are definitely included
assertTrue(endpoints.contains(hosts.get((i + j + 1) % hosts.size())));
}
// bootstrapEndpoint should be in the endpoints for i in MAX-RF to MAX, but not in any earlier ep.
if (i < RING_SIZE - replicationFactor)
assertFalse(endpoints.contains(bootstrapEndpoint));
else
assertTrue(endpoints.contains(bootstrapEndpoint));
}
}
StorageServiceAccessor.setTokenMetadata(oldTmd);
}
use of org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken in project cassandra by apache.
the class SimpleStrategyTest method testBigIntegerEndpoints.
@Test
public void testBigIntegerEndpoints() throws UnknownHostException {
List<Token> endpointTokens = new ArrayList<Token>();
List<Token> keyTokens = new ArrayList<Token>();
for (int i = 0; i < 5; i++) {
endpointTokens.add(new BigIntegerToken(String.valueOf(10 * i)));
keyTokens.add(new BigIntegerToken(String.valueOf(10 * i + 5)));
}
verifyGetNaturalEndpoints(endpointTokens.toArray(new Token[0]), keyTokens.toArray(new Token[0]));
}
Aggregations