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<InetAddress> 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);
InetAddress leftHost = hosts.get(1);
FailureDetector.instance.report(leftHost);
// trigger handleStateLeft in StorageService
ss.onChange(leftHost, ApplicationState.STATUS, 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 HintTest method resetGcGraceSeconds.
@Before
public void resetGcGraceSeconds() {
TokenMetadata tokenMeta = StorageService.instance.getTokenMetadata();
InetAddress local = FBUtilities.getBroadcastAddress();
tokenMeta.clearUnsafe();
tokenMeta.updateHostId(UUID.randomUUID(), local);
tokenMeta.updateNormalTokens(BootStrapper.getRandomTokens(tokenMeta, 1), local);
for (TableMetadata table : Schema.instance.getTablesAndViews(KEYSPACE)) MigrationManager.announceTableUpdate(table.unbuild().gcGraceSeconds(TableParams.DEFAULT_GC_GRACE_SECONDS).build(), true);
}
use of org.apache.cassandra.locator.TokenMetadata in project cassandra by apache.
the class HintTest method testChangedTopology.
@SuppressWarnings("unchecked")
@Test
public void testChangedTopology() 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 serving the mutation key.
TokenMetadata tokenMeta = StorageService.instance.getTokenMetadata();
InetAddress local = FBUtilities.getBroadcastAddress();
InetAddress endpoint = InetAddress.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);
assert StorageProxy.instance.getHintsInProgress() == 0;
long totalHintCount = StorageProxy.instance.getTotalHints();
// Process hint message.
HintMessage message = new HintMessage(localId, hint);
MessagingService.instance().getVerbHandler(MessagingService.Verb.HINT).doVerb(MessageIn.create(local, message, Collections.emptyMap(), MessagingService.Verb.HINT, MessagingService.current_version), -1);
// 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 have been made. Node is not live hence it should now be a hint.
assertEquals(totalHintCount + 1, StorageProxy.instance.getTotalHints());
}
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();
InetAddress local = FBUtilities.getBroadcastAddress();
InetAddress endpoint = InetAddress.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);
MessagingService.instance().getVerbHandler(MessagingService.Verb.HINT).doVerb(MessageIn.create(local, message, Collections.emptyMap(), MessagingService.Verb.HINT, MessagingService.current_version), -1);
// 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 LeaveAndBootstrapTest method testStateJumpToNormal.
@Test
public void testStateJumpToNormal() throws UnknownHostException {
StorageService ss = StorageService.instance;
TokenMetadata tmd = ss.getTokenMetadata();
tmd.clearUnsafe();
IPartitioner partitioner = RandomPartitioner.instance;
VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner);
ArrayList<Token> endpointTokens = new ArrayList<Token>();
ArrayList<Token> keyTokens = new ArrayList<Token>();
List<InetAddress> hosts = new ArrayList<InetAddress>();
List<UUID> hostIds = new ArrayList<UUID>();
// create a ring or 5 nodes
Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 6);
// node 2 leaves
ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.leaving(Collections.singleton(endpointTokens.get(2))));
assertTrue(tmd.isLeaving(hosts.get(2)));
assertEquals(endpointTokens.get(2), tmd.getToken(hosts.get(2)));
// back to normal
Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(2))));
ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.normal(Collections.singleton(keyTokens.get(2))));
assertTrue(tmd.getSizeOfLeavingEndpoints() == 0);
assertEquals(keyTokens.get(2), tmd.getToken(hosts.get(2)));
// node 3 goes through leave and left and then jumps to normal at its new token
ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.leaving(Collections.singleton(keyTokens.get(2))));
ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.left(Collections.singleton(keyTokens.get(2)), Gossiper.computeExpireTime()));
Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(4))));
ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.normal(Collections.singleton(keyTokens.get(4))));
assertTrue(tmd.getBootstrapTokens().isEmpty());
assertTrue(tmd.getSizeOfLeavingEndpoints() == 0);
assertEquals(keyTokens.get(4), tmd.getToken(hosts.get(2)));
}
Aggregations