Search in sources :

Example 66 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class ClusterActions method replicasForPrimaryKey.

// assumes every node knows the correct topology
static List<InetSocketAddress> replicasForPrimaryKey(String keyspaceName, String table, int primaryKey) {
    Keyspace keyspace = Keyspace.open(keyspaceName);
    TableMetadata metadata = keyspace.getColumnFamilyStore(table).metadata.get();
    DecoratedKey key = metadata.partitioner.decorateKey(Int32Type.instance.decompose(primaryKey));
    // we return a Set because simulator can easily encounter point where nodes are both natural and pending
    return ReplicaLayout.forTokenWriteLiveAndDown(keyspace, key.getToken()).all().asList(Replica::endpoint);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) Keyspace(org.apache.cassandra.db.Keyspace) DecoratedKey(org.apache.cassandra.db.DecoratedKey) Replica(org.apache.cassandra.locator.Replica)

Example 67 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class BigTableZeroCopyWriterTest method assertRowCount.

private void assertRowCount(int expected) {
    int count = 0;
    for (int i = 0; i < store.metadata().params.minIndexInterval; i++) {
        DecoratedKey dk = Util.dk(String.valueOf(i));
        UnfilteredRowIterator rowIter = sstable.iterator(dk, Slices.ALL, ColumnFilter.all(store.metadata()), false, SSTableReadsListener.NOOP_LISTENER);
        while (rowIter.hasNext()) {
            rowIter.next();
            count++;
        }
    }
    assertEquals(expected, count);
}
Also used : UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) DecoratedKey(org.apache.cassandra.db.DecoratedKey)

Example 68 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class SerializationsTest method testBloomFilterTable.

private static void testBloomFilterTable(String file, boolean oldBfFormat) throws Exception {
    Murmur3Partitioner partitioner = new Murmur3Partitioner();
    try (DataInputStream in = new DataInputStream(new FileInputStreamPlus(new File(file)));
        IFilter filter = BloomFilterSerializer.deserialize(in, oldBfFormat)) {
        for (int i = 1; i <= 10; i++) {
            DecoratedKey decoratedKey = partitioner.decorateKey(Int32Type.instance.decompose(i));
            boolean present = filter.isPresent(decoratedKey);
            Assert.assertTrue(present);
        }
        int positives = 0;
        for (int i = 11; i <= 1000010; i++) {
            DecoratedKey decoratedKey = partitioner.decorateKey(Int32Type.instance.decompose(i));
            boolean present = filter.isPresent(decoratedKey);
            if (present)
                positives++;
        }
        double fpr = positives;
        fpr /= 1000000;
        Assert.assertTrue(fpr <= 0.011d);
    }
}
Also used : FileInputStreamPlus(org.apache.cassandra.io.util.FileInputStreamPlus) DecoratedKey(org.apache.cassandra.db.DecoratedKey) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner) DataInputStream(java.io.DataInputStream) File(org.apache.cassandra.io.util.File)

Example 69 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class OnDiskIndexTest method testDescriptor.

@Test
public void testDescriptor() throws Exception {
    final Map<ByteBuffer, Pair<DecoratedKey, Long>> data = new HashMap<ByteBuffer, Pair<DecoratedKey, Long>>() {

        {
            put(Int32Type.instance.decompose(5), Pair.create(keyAt(1L), 1L));
        }
    };
    OnDiskIndexBuilder builder1 = new OnDiskIndexBuilder(UTF8Type.instance, Int32Type.instance, OnDiskIndexBuilder.Mode.PREFIX);
    OnDiskIndexBuilder builder2 = new OnDiskIndexBuilder(UTF8Type.instance, Int32Type.instance, OnDiskIndexBuilder.Mode.PREFIX);
    for (Map.Entry<ByteBuffer, Pair<DecoratedKey, Long>> e : data.entrySet()) {
        DecoratedKey key = e.getValue().left;
        Long position = e.getValue().right;
        builder1.add(e.getKey(), key, position);
        builder2.add(e.getKey(), key, position);
    }
    File index1 = FileUtils.createTempFile("on-disk-sa-int", "db");
    File index2 = FileUtils.createTempFile("on-disk-sa-int2", "db");
    index1.deleteOnExit();
    index2.deleteOnExit();
    builder1.finish(index1);
    builder2.finish(new Descriptor(Descriptor.VERSION_AA), index2);
    OnDiskIndex onDisk1 = new OnDiskIndex(index1, Int32Type.instance, new KeyConverter());
    OnDiskIndex onDisk2 = new OnDiskIndex(index2, Int32Type.instance, new KeyConverter());
    ByteBuffer number = Int32Type.instance.decompose(5);
    Assert.assertEquals(Collections.singleton(data.get(number).left), convert(onDisk1.search(expressionFor(Operator.EQ, Int32Type.instance, number))));
    Assert.assertEquals(Collections.singleton(data.get(number).left), convert(onDisk2.search(expressionFor(Operator.EQ, Int32Type.instance, number))));
    Assert.assertEquals(onDisk1.descriptor.version.version, Descriptor.CURRENT_VERSION);
    Assert.assertEquals(onDisk2.descriptor.version.version, Descriptor.VERSION_AA);
}
Also used : DecoratedKey(org.apache.cassandra.db.DecoratedKey) BufferDecoratedKey(org.apache.cassandra.db.BufferDecoratedKey) ByteBuffer(java.nio.ByteBuffer) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) File(org.apache.cassandra.io.util.File) Pair(org.apache.cassandra.utils.Pair) Test(org.junit.Test)

Example 70 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class OnDiskIndexTest method validateExclusions.

private int validateExclusions(OnDiskIndex sa, long lower, long upper, Set<Long> exclusions, boolean checkCount) {
    int count = 0;
    for (DecoratedKey key : convert(sa.search(rangeWithExclusions(lower, true, upper, true, exclusions)))) {
        String keyId = UTF8Type.instance.getString(key.getKey()).split("key")[1];
        Assert.assertFalse("key" + keyId + " is present.", exclusions.contains(Long.valueOf(keyId)));
        count++;
    }
    if (checkCount)
        Assert.assertEquals(upper - (lower == 0 ? -1 : lower) - exclusions.size(), count);
    return count;
}
Also used : DecoratedKey(org.apache.cassandra.db.DecoratedKey) BufferDecoratedKey(org.apache.cassandra.db.BufferDecoratedKey)

Aggregations

DecoratedKey (org.apache.cassandra.db.DecoratedKey)80 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)31 Test (org.junit.Test)28 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)22 ByteBuffer (java.nio.ByteBuffer)21 TableMetadata (org.apache.cassandra.schema.TableMetadata)20 Keyspace (org.apache.cassandra.db.Keyspace)18 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)16 ColumnFamily (org.apache.cassandra.db.ColumnFamily)8 QueryPath (org.apache.cassandra.db.filter.QueryPath)8 File (org.apache.cassandra.io.util.File)8 ArrayList (java.util.ArrayList)7 UUID (java.util.UUID)7 RowMutation (org.apache.cassandra.db.RowMutation)7 Table (org.apache.cassandra.db.Table)7 Row (org.apache.cassandra.db.rows.Row)7 UnfilteredRowIterator (org.apache.cassandra.db.rows.UnfilteredRowIterator)7 Token (org.apache.cassandra.dht.Token)7 BufferDecoratedKey (org.apache.cassandra.db.BufferDecoratedKey)6 RowIndexEntry (org.apache.cassandra.db.RowIndexEntry)5