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);
}
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);
}
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);
}
}
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);
}
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;
}
Aggregations