Search in sources :

Example 41 with TokenMetadata

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));
}
Also used : RandomPartitioner(org.apache.cassandra.dht.RandomPartitioner) ArrayList(java.util.ArrayList) Token(org.apache.cassandra.dht.Token) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) StorageService(org.apache.cassandra.service.StorageService) UUID(java.util.UUID) InetAddress(java.net.InetAddress) IPartitioner(org.apache.cassandra.dht.IPartitioner) Test(org.junit.Test)

Example 42 with TokenMetadata

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);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) InetAddress(java.net.InetAddress) Before(org.junit.Before)

Example 43 with TokenMetadata

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());
}
Also used : TokenMetadata(org.apache.cassandra.locator.TokenMetadata) UUID(java.util.UUID) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 44 with TokenMetadata

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);
    }
}
Also used : TokenMetadata(org.apache.cassandra.locator.TokenMetadata) UUID(java.util.UUID) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 45 with TokenMetadata

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)));
}
Also used : VersionedValue(org.apache.cassandra.gms.VersionedValue) BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) Token(org.apache.cassandra.dht.Token) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) InetAddress(java.net.InetAddress) IPartitioner(org.apache.cassandra.dht.IPartitioner) Test(org.junit.Test)

Aggregations

TokenMetadata (org.apache.cassandra.locator.TokenMetadata)72 InetAddress (java.net.InetAddress)50 Test (org.junit.Test)50 Token (org.apache.cassandra.dht.Token)27 VersionedValue (org.apache.cassandra.gms.VersionedValue)22 Range (org.apache.cassandra.dht.Range)16 AbstractReplicationStrategy (org.apache.cassandra.locator.AbstractReplicationStrategy)14 BigIntegerToken (org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken)13 StringToken (org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken)12 KeyspaceMetadata (org.apache.cassandra.schema.KeyspaceMetadata)12 IPartitioner (org.apache.cassandra.dht.IPartitioner)10 LongToken (org.apache.cassandra.dht.Murmur3Partitioner.LongToken)7 HashMap (java.util.HashMap)5 HashMultimap (com.google.common.collect.HashMultimap)4 Multimap (com.google.common.collect.Multimap)4 BytesToken (org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken)4 NetworkTopologyStrategy (org.apache.cassandra.locator.NetworkTopologyStrategy)4 StorageService (org.apache.cassandra.service.StorageService)4 UUID (java.util.UUID)3 Before (org.junit.Before)3