Search in sources :

Example 21 with IPartitioner

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

the class CleanupTest method testCleanupWithIndexes.

@Test
public void testCleanupWithIndexes() throws IOException, ExecutionException, InterruptedException {
    Table table = Table.open(TABLE1);
    ColumnFamilyStore cfs = table.getColumnFamilyStore(CF1);
    assertEquals(cfs.indexManager.getIndexedColumns().iterator().next(), COLUMN);
    List<Row> rows;
    // insert data and verify we get it back w/ range query
    fillCF(cfs, LOOPS);
    rows = Util.getRangeSlice(cfs);
    assertEquals(LOOPS, rows.size());
    SecondaryIndex index = cfs.indexManager.getIndexForColumn(COLUMN);
    long start = System.currentTimeMillis();
    while (!index.isIndexBuilt(COLUMN) && System.currentTimeMillis() < start + 10000) Thread.sleep(10);
    // verify we get it back w/ index query too
    IndexExpression expr = new IndexExpression(COLUMN, IndexOperator.EQ, VALUE);
    List<IndexExpression> clause = Arrays.asList(expr);
    IFilter filter = new IdentityQueryFilter();
    IPartitioner p = StorageService.getPartitioner();
    Range<RowPosition> range = Util.range("", "");
    rows = table.getColumnFamilyStore(CF1).search(clause, range, Integer.MAX_VALUE, filter);
    assertEquals(LOOPS, rows.size());
    // we don't allow cleanup when the local host has no range to avoid wipping up all data when a node has not join the ring.
    // So to make sure cleanup erase everything here, we give the localhost the tiniest possible range.
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();
    byte[] tk1 = new byte[1], tk2 = new byte[1];
    tk1[0] = 2;
    tk2[0] = 1;
    tmd.updateNormalToken(new BytesToken(tk1), InetAddress.getByName("127.0.0.1"));
    tmd.updateNormalToken(new BytesToken(tk2), InetAddress.getByName("127.0.0.2"));
    CompactionManager.instance.performCleanup(cfs, new NodeId.OneShotRenewer());
    // row data should be gone
    rows = Util.getRangeSlice(cfs);
    assertEquals(0, rows.size());
    // not only should it be gone but there should be no data on disk, not even tombstones
    assert cfs.getSSTables().isEmpty();
    // 2ary indexes should result in no results, too (although tombstones won't be gone until compacted)
    rows = cfs.search(clause, range, Integer.MAX_VALUE, filter);
    assertEquals(0, rows.size());
}
Also used : IndexExpression(org.apache.cassandra.thrift.IndexExpression) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) IdentityQueryFilter(org.apache.cassandra.db.columniterator.IdentityQueryFilter) SecondaryIndex(org.apache.cassandra.db.index.SecondaryIndex) IFilter(org.apache.cassandra.db.filter.IFilter) BytesToken(org.apache.cassandra.dht.BytesToken) NodeId(org.apache.cassandra.utils.NodeId) IPartitioner(org.apache.cassandra.dht.IPartitioner) Test(org.junit.Test)

Example 22 with IPartitioner

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

the class ColumnFamilyStoreTest method testIndexScan.

@Test
public void testIndexScan() throws IOException {
    RowMutation rm;
    rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("k1"));
    rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(1L), 0);
    rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 0);
    rm.apply();
    rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("k2"));
    rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(2L), 0);
    rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(2L), 0);
    rm.apply();
    rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("k3"));
    rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(2L), 0);
    rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 0);
    rm.apply();
    rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("k4aaaa"));
    rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(2L), 0);
    rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(3L), 0);
    rm.apply();
    // basic single-expression query
    IndexExpression expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, ByteBufferUtil.bytes(1L));
    List<IndexExpression> clause = Arrays.asList(expr);
    IFilter filter = new IdentityQueryFilter();
    IPartitioner p = StorageService.getPartitioner();
    Range<RowPosition> range = Util.range("", "");
    List<Row> rows = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").search(clause, range, 100, filter);
    assert rows != null;
    assert rows.size() == 2 : StringUtils.join(rows, ",");
    String key = new String(rows.get(0).key.key.array(), rows.get(0).key.key.position(), rows.get(0).key.key.remaining());
    assert "k1".equals(key) : key;
    key = new String(rows.get(1).key.key.array(), rows.get(1).key.key.position(), rows.get(1).key.key.remaining());
    assert "k3".equals(key) : key;
    assert ByteBufferUtil.bytes(1L).equals(rows.get(0).cf.getColumn(ByteBufferUtil.bytes("birthdate")).value());
    assert ByteBufferUtil.bytes(1L).equals(rows.get(1).cf.getColumn(ByteBufferUtil.bytes("birthdate")).value());
    // add a second expression
    IndexExpression expr2 = new IndexExpression(ByteBufferUtil.bytes("notbirthdate"), IndexOperator.GTE, ByteBufferUtil.bytes(2L));
    clause = Arrays.asList(expr, expr2);
    rows = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").search(clause, range, 100, filter);
    assert rows.size() == 1 : StringUtils.join(rows, ",");
    key = new String(rows.get(0).key.key.array(), rows.get(0).key.key.position(), rows.get(0).key.key.remaining());
    assert "k3".equals(key);
    // same query again, but with resultset not including the subordinate expression
    rows = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").search(clause, range, 100, new NamesQueryFilter(ByteBufferUtil.bytes("birthdate")));
    assert rows.size() == 1 : StringUtils.join(rows, ",");
    key = new String(rows.get(0).key.key.array(), rows.get(0).key.key.position(), rows.get(0).key.key.remaining());
    assert "k3".equals(key);
    assert rows.get(0).cf.getColumnCount() == 1 : rows.get(0).cf;
    // once more, this time with a slice rowset that needs to be expanded
    SliceQueryFilter emptyFilter = new SliceQueryFilter(ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 0);
    rows = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").search(clause, range, 100, emptyFilter);
    assert rows.size() == 1 : StringUtils.join(rows, ",");
    key = new String(rows.get(0).key.key.array(), rows.get(0).key.key.position(), rows.get(0).key.key.remaining());
    assert "k3".equals(key);
    assert rows.get(0).cf.getColumnCount() == 0;
    // query with index hit but rejected by secondary clause, with a small enough count that just checking count
    // doesn't tell the scan loop that it's done
    IndexExpression expr3 = new IndexExpression(ByteBufferUtil.bytes("notbirthdate"), IndexOperator.EQ, ByteBufferUtil.bytes(-1L));
    clause = Arrays.asList(expr, expr3);
    rows = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").search(clause, range, 100, filter);
    assert rows.isEmpty();
}
Also used : IdentityQueryFilter(org.apache.cassandra.db.columniterator.IdentityQueryFilter) IPartitioner(org.apache.cassandra.dht.IPartitioner) Test(org.junit.Test)

Example 23 with IPartitioner

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

the class ColumnFamilyStoreTest method testLargeScan.

@Test
public void testLargeScan() throws IOException {
    RowMutation rm;
    for (int i = 0; i < 100; i++) {
        rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("key" + i));
        rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(34L), 0);
        rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes((long) (i % 2)), 0);
        rm.applyUnsafe();
    }
    IndexExpression expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, ByteBufferUtil.bytes(34L));
    IndexExpression expr2 = new IndexExpression(ByteBufferUtil.bytes("notbirthdate"), IndexOperator.EQ, ByteBufferUtil.bytes(1L));
    List<IndexExpression> clause = Arrays.asList(expr, expr2);
    IFilter filter = new IdentityQueryFilter();
    IPartitioner p = StorageService.getPartitioner();
    Range<RowPosition> range = Util.range("", "");
    List<Row> rows = Table.open("Keyspace1").getColumnFamilyStore("Indexed1").search(clause, range, 100, filter);
    assert rows != null;
    assert rows.size() == 50 : rows.size();
    Set<DecoratedKey> keys = new HashSet<DecoratedKey>();
    // extra check that there are no duplicate results -- see https://issues.apache.org/jira/browse/CASSANDRA-2406
    for (Row row : rows) keys.add(row.key);
    assert rows.size() == keys.size();
}
Also used : IdentityQueryFilter(org.apache.cassandra.db.columniterator.IdentityQueryFilter) IPartitioner(org.apache.cassandra.dht.IPartitioner) Test(org.junit.Test)

Example 24 with IPartitioner

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

the class SSTableReaderTest method assertIndexQueryWorks.

private void assertIndexQueryWorks(ColumnFamilyStore indexedCFS) {
    assert "Indexed1".equals(indexedCFS.getColumnFamilyName());
    // make sure all sstables including 2ary indexes load from disk
    indexedCFS.clearUnsafe();
    for (ColumnFamilyStore indexCfs : indexedCFS.indexManager.getIndexesBackedByCfs()) {
        indexCfs.clearUnsafe();
        // v1.0.4 would fail here (see CASSANDRA-3540)
        indexCfs.loadNewSSTables();
    }
    indexedCFS.loadNewSSTables();
    // query using index to see if sstable for secondary index opens
    IndexExpression expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, ByteBufferUtil.bytes(1L));
    List<IndexExpression> clause = Arrays.asList(expr);
    IPartitioner p = StorageService.getPartitioner();
    Range<RowPosition> range = Util.range("", "");
    List<Row> rows = indexedCFS.search(clause, range, 100, new IdentityQueryFilter());
    assert rows.size() == 1;
}
Also used : IdentityQueryFilter(org.apache.cassandra.db.columniterator.IdentityQueryFilter) IndexExpression(org.apache.cassandra.thrift.IndexExpression) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Example 25 with IPartitioner

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

the class RemoveTest method testRemoveToken.

@Test
public void testRemoveToken() throws InterruptedException {
    IPartitioner partitioner = StorageService.getPartitioner();
    final String token = partitioner.getTokenFactory().toString(removaltoken);
    ReplicationSink rSink = new ReplicationSink();
    SinkManager.add(rSink);
    // start removal in background and send replication confirmations
    final AtomicBoolean success = new AtomicBoolean(false);
    Thread remover = new Thread() {

        public void run() {
            try {
                ss.removeToken(token);
            } catch (Exception e) {
                System.err.println(e);
                e.printStackTrace();
                return;
            }
            success.set(true);
        }
    };
    remover.start();
    // make sure removal is waiting for confirmation
    Thread.sleep(1000);
    assertTrue(tmd.isLeaving(removalhost));
    assertEquals(1, tmd.getLeavingEndpoints().size());
    for (InetAddress host : hosts) {
        Message msg = new Message(host, StorageService.Verb.REPLICATION_FINISHED, new byte[0], MessagingService.version_);
        MessagingService.instance().sendRR(msg, FBUtilities.getBroadcastAddress());
    }
    remover.join();
    assertTrue(success.get());
    assertTrue(tmd.getLeavingEndpoints().isEmpty());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Message(org.apache.cassandra.net.Message) InetAddress(java.net.InetAddress) IOException(java.io.IOException) ConfigurationException(org.apache.cassandra.config.ConfigurationException) 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