use of org.apache.cassandra.locator.TokenMetadata in project cassandra by apache.
the class HintTest method testChangedTopologyNotHintable.
@SuppressWarnings("unchecked")
@Test
public void testChangedTopologyNotHintable() throws Exception {
// create a hint
long now = FBUtilities.timestampMicros();
String key = "testChangedTopology";
Mutation mutation = createMutation(key, now);
Hint hint = Hint.create(mutation, now / 1000);
// Prepare metadata with injected stale endpoint.
TokenMetadata tokenMeta = StorageService.instance.getTokenMetadata();
InetAddressAndPort local = FBUtilities.getBroadcastAddressAndPort();
InetAddressAndPort endpoint = InetAddressAndPort.getByName("1.1.1.1");
UUID localId = StorageService.instance.getLocalHostUUID();
UUID targetId = UUID.randomUUID();
tokenMeta.updateHostId(targetId, endpoint);
tokenMeta.updateNormalTokens(ImmutableList.of(mutation.key().getToken()), endpoint);
// sanity check that there is no data inside yet
assertNoPartitions(key, TABLE0);
assertNoPartitions(key, TABLE1);
assertNoPartitions(key, TABLE2);
try {
DatabaseDescriptor.setHintedHandoffEnabled(false);
assert StorageMetrics.totalHintsInProgress.getCount() == 0;
long totalHintCount = StorageMetrics.totalHints.getCount();
// Process hint message.
HintMessage message = new HintMessage(localId, hint);
HINT_REQ.<HintMessage>handler().doVerb(Message.builder(HINT_REQ, message).from(local).build());
// hint should not be applied as we no longer are a replica
assertNoPartitions(key, TABLE0);
assertNoPartitions(key, TABLE1);
assertNoPartitions(key, TABLE2);
// Attempt to send to new endpoint should not have been made.
assertEquals(totalHintCount, StorageMetrics.totalHints.getCount());
} finally {
DatabaseDescriptor.setHintedHandoffEnabled(true);
}
}
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();
InetAddressAndPort myEndpoint = InetAddressAndPort.getByName("127.0.0.1");
assertEquals(numOldNodes, tmd.sortedTokens().size());
IFailureDetector mockFailureDetector = new IFailureDetector() {
public boolean isAlive(InetAddressAndPort ep) {
return true;
}
public void interpret(InetAddressAndPort ep) {
throw new UnsupportedOperationException();
}
public void report(InetAddressAndPort ep) {
throw new UnsupportedOperationException();
}
public void registerFailureDetectionEventListener(IFailureDetectionEventListener listener) {
throw new UnsupportedOperationException();
}
public void unregisterFailureDetectionEventListener(IFailureDetectionEventListener listener) {
throw new UnsupportedOperationException();
}
public void remove(InetAddressAndPort ep) {
throw new UnsupportedOperationException();
}
public void forceConviction(InetAddressAndPort ep) {
throw new UnsupportedOperationException();
}
};
RangeStreamer s = new RangeStreamer(tmd, null, myEndpoint, StreamOperation.BOOTSTRAP, true, DatabaseDescriptor.getEndpointSnitch(), new StreamStateStore(), mockFailureDetector, false, 1);
assertNotNull(Keyspace.open(keyspaceName));
s.addRanges(keyspaceName, Keyspace.open(keyspaceName).getReplicationStrategy().getPendingAddressRanges(tmd, myToken, myEndpoint));
Multimap<InetAddressAndPort, FetchReplica> toFetch = s.toFetch().get(keyspaceName);
// Check we get get RF new ranges in total
assertEquals(replicationFactor, toFetch.size());
// is used, they will vary.
assert toFetch.values().size() > 0;
assert toFetch.keys().stream().noneMatch(myEndpoint::equals);
return s;
}
use of org.apache.cassandra.locator.TokenMetadata in project cassandra by apache.
the class FailureDetectorTest method testConvictAfterLeft.
@Test
public void testConvictAfterLeft() throws UnknownHostException {
StorageService ss = StorageService.instance;
TokenMetadata tmd = ss.getTokenMetadata();
tmd.clearUnsafe();
IPartitioner partitioner = new RandomPartitioner();
VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner);
ArrayList<Token> endpointTokens = new ArrayList<>();
ArrayList<Token> keyTokens = new ArrayList<>();
List<InetAddressAndPort> hosts = new ArrayList<>();
List<UUID> hostIds = new ArrayList<>();
// we want to convict if there is any heartbeat data present in the FD
DatabaseDescriptor.setPhiConvictThreshold(0);
// create a ring of 2 nodes
Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 3);
InetAddressAndPort leftHost = hosts.get(1);
FailureDetector.instance.report(leftHost);
// trigger handleStateLeft in StorageService
ss.onChange(leftHost, ApplicationState.STATUS_WITH_PORT, valueFactory.left(Collections.singleton(endpointTokens.get(1)), Gossiper.computeExpireTime()));
// confirm that handleStateLeft was called and leftEndpoint was removed from TokenMetadata
assertFalse("Left endpoint not removed from TokenMetadata", tmd.isMember(leftHost));
// confirm the FD's history for leftHost didn't get wiped by status jump to LEFT
FailureDetector.instance.interpret(leftHost);
assertFalse("Left endpoint not convicted", FailureDetector.instance.isAlive(leftHost));
}
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"), 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> replicationMap = new HashMap<>();
replicationMap.put(ReplicationParams.CLASS, NetworkTopologyStrategy.class.getName());
replicationMap.put("DC1", "2");
replicationMap.put("DC2", "2");
Schema.instance.maybeRemoveKeyspaceInstance("Keyspace1");
KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, replicationMap));
Schema.instance.load(meta);
Optional<Replica> naturalEndpoint = ViewUtils.getViewNaturalEndpoint(Keyspace.open("Keyspace1").getReplicationStrategy(), new StringToken("CA"), new StringToken("BB"));
Assert.assertTrue(naturalEndpoint.isPresent());
Assert.assertEquals(InetAddressAndPort.getByName("127.0.0.1"), naturalEndpoint.get().endpoint());
}
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"), 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> replicationMap = new HashMap<>();
replicationMap.put(ReplicationParams.CLASS, NetworkTopologyStrategy.class.getName());
replicationMap.put("DC1", "1");
replicationMap.put("DC2", "1");
Schema.instance.maybeRemoveKeyspaceInstance("Keyspace1");
KeyspaceMetadata meta = KeyspaceMetadata.create("Keyspace1", KeyspaceParams.create(false, replicationMap));
Schema.instance.load(meta);
Optional<Replica> naturalEndpoint = ViewUtils.getViewNaturalEndpoint(Keyspace.open("Keyspace1").getReplicationStrategy(), new StringToken("CA"), new StringToken("BB"));
Assert.assertTrue(naturalEndpoint.isPresent());
Assert.assertEquals(InetAddressAndPort.getByName("127.0.0.2"), naturalEndpoint.get().endpoint());
}
Aggregations