Search in sources :

Example 31 with IPartitioner

use of org.apache.cassandra.dht.IPartitioner in project cassandra by apache.

the class PropertyFileSnitchTest method setup.

@Before
public void setup() throws ConfigurationException, IOException {
    String confFile = FBUtilities.resourceToFile(PropertyFileSnitch.SNITCH_PROPERTIES_FILENAME);
    effectiveFile = Paths.get(confFile);
    backupFile = Paths.get(confFile + ".bak");
    restoreOrigConfigFile();
    InetAddress[] hosts = { // this exists in the config file
    InetAddress.getByName("127.0.0.1"), // this exists in the config file
    InetAddress.getByName("127.0.0.2"), // this does not exist in the config file
    InetAddress.getByName("127.0.0.9") };
    IPartitioner partitioner = new RandomPartitioner();
    valueFactory = new VersionedValue.VersionedValueFactory(partitioner);
    tokenMap = new HashMap<>();
    for (InetAddress host : hosts) {
        Set<Token> tokens = Collections.singleton(partitioner.getRandomToken());
        Gossiper.instance.initializeNodeUnsafe(host, UUID.randomUUID(), 1);
        Gossiper.instance.injectApplicationState(host, ApplicationState.TOKENS, valueFactory.tokens(tokens));
        setNodeShutdown(host);
        tokenMap.put(host, tokens);
    }
}
Also used : RandomPartitioner(org.apache.cassandra.dht.RandomPartitioner) VersionedValue(org.apache.cassandra.gms.VersionedValue) Token(org.apache.cassandra.dht.Token) InetAddress(java.net.InetAddress) IPartitioner(org.apache.cassandra.dht.IPartitioner) Before(org.junit.Before)

Example 32 with IPartitioner

use of org.apache.cassandra.dht.IPartitioner in project cassandra by apache.

the class SimpleStrategyTest method testStringEndpoints.

@Test
public void testStringEndpoints() throws UnknownHostException {
    IPartitioner partitioner = OrderPreservingPartitioner.instance;
    List<Token> endpointTokens = new ArrayList<Token>();
    List<Token> keyTokens = new ArrayList<Token>();
    for (int i = 0; i < 5; i++) {
        endpointTokens.add(new StringToken(String.valueOf((char) ('a' + i * 2))));
        keyTokens.add(partitioner.getToken(ByteBufferUtil.bytes(String.valueOf((char) ('a' + i * 2 + 1)))));
    }
    verifyGetNaturalEndpoints(endpointTokens.toArray(new Token[0]), keyTokens.toArray(new Token[0]));
}
Also used : ArrayList(java.util.ArrayList) BigIntegerToken(org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken) StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken) Token(org.apache.cassandra.dht.Token) StringToken(org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken) IPartitioner(org.apache.cassandra.dht.IPartitioner) Test(org.junit.Test)

Example 33 with IPartitioner

use of org.apache.cassandra.dht.IPartitioner 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)

Example 34 with IPartitioner

use of org.apache.cassandra.dht.IPartitioner in project cassandra by apache.

the class RepairSessionTest method testConviction.

@Test
public void testConviction() throws Exception {
    InetAddress remote = InetAddress.getByName("127.0.0.2");
    Gossiper.instance.initializeNodeUnsafe(remote, UUID.randomUUID(), 1);
    // Set up RepairSession
    UUID parentSessionId = UUIDGen.getTimeUUID();
    UUID sessionId = UUID.randomUUID();
    IPartitioner p = Murmur3Partitioner.instance;
    Range<Token> repairRange = new Range<>(p.getToken(ByteBufferUtil.bytes(0)), p.getToken(ByteBufferUtil.bytes(100)));
    Set<InetAddress> endpoints = Sets.newHashSet(remote);
    RepairSession session = new RepairSession(parentSessionId, sessionId, Arrays.asList(repairRange), "Keyspace1", RepairParallelism.SEQUENTIAL, endpoints, ActiveRepairService.UNREPAIRED_SSTABLE, false, false, "Standard1");
    // perform convict
    session.convict(remote, Double.MAX_VALUE);
    // RepairSession should throw ExecutorException with the cause of IOException when getting its value
    try {
        session.get();
        fail();
    } catch (ExecutionException ex) {
        assertEquals(IOException.class, ex.getCause().getClass());
    }
}
Also used : Token(org.apache.cassandra.dht.Token) IOException(java.io.IOException) UUID(java.util.UUID) Range(org.apache.cassandra.dht.Range) ExecutionException(java.util.concurrent.ExecutionException) InetAddress(java.net.InetAddress) IPartitioner(org.apache.cassandra.dht.IPartitioner) Test(org.junit.Test)

Example 35 with IPartitioner

use of org.apache.cassandra.dht.IPartitioner in project cassandra by apache.

the class LeaveAndBootstrapTest method testStateJumpToLeaving.

@Test
public void testStateJumpToLeaving() 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 with _different_ token
    Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(0))));
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.leaving(Collections.singleton(keyTokens.get(0))));
    assertEquals(keyTokens.get(0), tmd.getToken(hosts.get(2)));
    assertTrue(tmd.isLeaving(hosts.get(2)));
    assertNull(tmd.getEndpoint(endpointTokens.get(2)));
    // go to boostrap
    Gossiper.instance.injectApplicationState(hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(1))));
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.bootstrapping(Collections.<Token>singleton(keyTokens.get(1))));
    assertFalse(tmd.isLeaving(hosts.get(2)));
    assertEquals(1, tmd.getBootstrapTokens().size());
    assertEquals(hosts.get(2), tmd.getBootstrapTokens().get(keyTokens.get(1)));
    // jump to leaving again
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.leaving(Collections.singleton(keyTokens.get(1))));
    assertEquals(hosts.get(2), tmd.getEndpoint(keyTokens.get(1)));
    assertTrue(tmd.isLeaving(hosts.get(2)));
    assertTrue(tmd.getBootstrapTokens().isEmpty());
    // go to state left
    ss.onChange(hosts.get(2), ApplicationState.STATUS, valueFactory.left(Collections.singleton(keyTokens.get(1)), Gossiper.computeExpireTime()));
    assertFalse(tmd.isMember(hosts.get(2)));
    assertFalse(tmd.isLeaving(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

IPartitioner (org.apache.cassandra.dht.IPartitioner)55 Token (org.apache.cassandra.dht.Token)28 Test (org.junit.Test)27 InetAddress (java.net.InetAddress)15 Range (org.apache.cassandra.dht.Range)14 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)10 IdentityQueryFilter (org.apache.cassandra.db.columniterator.IdentityQueryFilter)9 BigIntegerToken (org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken)9 VersionedValue (org.apache.cassandra.gms.VersionedValue)9 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 RandomPartitioner (org.apache.cassandra.dht.RandomPartitioner)6 IOError (java.io.IOError)4 ByteBuffer (java.nio.ByteBuffer)4 ExecutionException (java.util.concurrent.ExecutionException)3 IFilter (org.apache.cassandra.db.filter.IFilter)3 QueryPath (org.apache.cassandra.db.filter.QueryPath)3 AbstractReplicationStrategy (org.apache.cassandra.locator.AbstractReplicationStrategy)3 IndexExpression (org.apache.cassandra.thrift.IndexExpression)3 HashMultimap (com.google.common.collect.HashMultimap)2