Search in sources :

Example 26 with IPartitioner

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

the class StreamingTransferTest method testTransferTable.

@Test
public void testTransferTable() throws Exception {
    final Table table = Table.open("Keyspace1");
    final ColumnFamilyStore cfs = table.getColumnFamilyStore("Indexed1");
    List<String> keys = createAndTransfer(table, cfs, new Mutator() {

        public void mutate(String key, String col, long timestamp) throws Exception {
            long val = key.hashCode();
            RowMutation rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes(key));
            ColumnFamily cf = ColumnFamily.create(table.name, cfs.columnFamily);
            cf.addColumn(column(col, "v", timestamp));
            cf.addColumn(new Column(ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(val), timestamp));
            rm.add(cf);
            logger.debug("Applying row to transfer " + rm);
            rm.apply();
        }
    });
    // confirm that the secondary index was recovered
    for (String key : keys) {
        long val = key.hashCode();
        IPartitioner p = StorageService.getPartitioner();
        IndexExpression expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, ByteBufferUtil.bytes(val));
        List<IndexExpression> clause = Arrays.asList(expr);
        IFilter filter = new IdentityQueryFilter();
        Range<RowPosition> range = Util.range("", "");
        List<Row> rows = cfs.search(clause, range, 100, filter);
        assertEquals(1, rows.size());
        assert rows.get(0).key.key.equals(ByteBufferUtil.bytes(key));
    }
}
Also used : IndexExpression(org.apache.cassandra.thrift.IndexExpression) IdentityQueryFilter(org.apache.cassandra.db.columniterator.IdentityQueryFilter) IFilter(org.apache.cassandra.db.filter.IFilter) IPartitioner(org.apache.cassandra.dht.IPartitioner) Test(org.junit.Test)

Example 27 with IPartitioner

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

the class StreamingTransferTest method transfer.

private void transfer(Table table, SSTableReader sstable) throws Exception {
    IPartitioner p = StorageService.getPartitioner();
    List<Range<Token>> ranges = new ArrayList<Range<Token>>();
    ranges.add(new Range<Token>(p.getMinimumToken(), p.getToken(ByteBufferUtil.bytes("key1"))));
    ranges.add(new Range<Token>(p.getToken(ByteBufferUtil.bytes("key2")), p.getMinimumToken()));
    StreamOutSession session = StreamOutSession.create(table.name, LOCAL, null);
    StreamOut.transferSSTables(session, Arrays.asList(sstable), ranges, OperationType.BOOTSTRAP);
    session.await();
}
Also used : Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Example 28 with IPartitioner

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

Aggregations

IPartitioner (org.apache.cassandra.dht.IPartitioner)53 Token (org.apache.cassandra.dht.Token)27 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)6 RandomPartitioner (org.apache.cassandra.dht.RandomPartitioner)6 IOError (java.io.IOError)4 ByteBuffer (java.nio.ByteBuffer)4 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 Multimap (com.google.common.collect.Multimap)2