use of org.apache.cassandra.dht.IPartitioner in project titan by thinkaurelius.
the class CassandraThriftStoreManager method getLocalKeyPartition.
@Override
public List<KeyRange> getLocalKeyPartition() throws BackendException {
CTConnection conn = null;
IPartitioner partitioner = getCassandraPartitioner();
if (!(partitioner instanceof AbstractByteOrderedPartitioner))
throw new UnsupportedOperationException("getLocalKeyPartition() only supported by byte ordered partitioner.");
Token.TokenFactory tokenFactory = partitioner.getTokenFactory();
try {
// Resist the temptation to describe SYSTEM_KS. It has no ring.
// Instead, we'll create our own keyspace (or check that it exists), then describe it.
ensureKeyspaceExists(keySpaceName);
conn = pool.borrowObject(keySpaceName);
List<TokenRange> ranges = conn.getClient().describe_ring(keySpaceName);
List<KeyRange> keyRanges = new ArrayList<KeyRange>(ranges.size());
for (TokenRange range : ranges) {
if (!NetworkUtil.hasLocalAddress(range.endpoints))
continue;
keyRanges.add(CassandraHelper.transformRange(tokenFactory.fromString(range.start_token), tokenFactory.fromString(range.end_token)));
}
return keyRanges;
} catch (Exception e) {
throw CassandraThriftKeyColumnValueStore.convertException(e);
} finally {
pool.returnObjectUnsafe(keySpaceName, conn);
}
}
use of org.apache.cassandra.dht.IPartitioner in project eiger by wlloyd.
the class SerializationsTest method testRangeSliceCommandWrite.
private void testRangeSliceCommandWrite() throws IOException {
ByteBuffer startCol = ByteBufferUtil.bytes("Start");
ByteBuffer stopCol = ByteBufferUtil.bytes("Stop");
ByteBuffer emptyCol = ByteBufferUtil.bytes("");
SlicePredicate namesPred = new SlicePredicate();
namesPred.column_names = Statics.NamedCols;
SliceRange emptySliceRange = new SliceRange(emptyCol, emptyCol, false, 100);
SliceRange nonEmptySliceRange = new SliceRange(startCol, stopCol, true, 100);
SlicePredicate emptyRangePred = new SlicePredicate();
emptyRangePred.slice_range = emptySliceRange;
SlicePredicate nonEmptyRangePred = new SlicePredicate();
nonEmptyRangePred.slice_range = nonEmptySliceRange;
IPartitioner part = StorageService.getPartitioner();
AbstractBounds<RowPosition> bounds = new Range<Token>(part.getRandomToken(), part.getRandomToken()).toRowBounds();
Message namesCmd = new RangeSliceCommand(Statics.KS, "Standard1", null, namesPred, bounds, 100).getMessage(MessagingService.version_);
Message emptyRangeCmd = new RangeSliceCommand(Statics.KS, "Standard1", null, emptyRangePred, bounds, 100).getMessage(MessagingService.version_);
Message regRangeCmd = new RangeSliceCommand(Statics.KS, "Standard1", null, nonEmptyRangePred, bounds, 100).getMessage(MessagingService.version_);
Message namesCmdSup = new RangeSliceCommand(Statics.KS, "Super1", Statics.SC, namesPred, bounds, 100).getMessage(MessagingService.version_);
Message emptyRangeCmdSup = new RangeSliceCommand(Statics.KS, "Super1", Statics.SC, emptyRangePred, bounds, 100).getMessage(MessagingService.version_);
Message regRangeCmdSup = new RangeSliceCommand(Statics.KS, "Super1", Statics.SC, nonEmptyRangePred, bounds, 100).getMessage(MessagingService.version_);
DataOutputStream dout = getOutput("db.RangeSliceCommand.bin");
messageSerializer.serialize(namesCmd, dout, getVersion());
messageSerializer.serialize(emptyRangeCmd, dout, getVersion());
messageSerializer.serialize(regRangeCmd, dout, getVersion());
messageSerializer.serialize(namesCmdSup, dout, getVersion());
messageSerializer.serialize(emptyRangeCmdSup, dout, getVersion());
messageSerializer.serialize(regRangeCmdSup, dout, getVersion());
dout.close();
}
use of org.apache.cassandra.dht.IPartitioner in project eiger by wlloyd.
the class ColumnFamilyStoreTest method testIndexScanWithLimitOne.
// See CASSANDRA-2628
@Test
public void testIndexScanWithLimitOne() throws IOException {
RowMutation rm;
rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("kk1"));
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("kk2"));
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("kk3"));
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("kk4"));
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();
// basic single-expression query
IndexExpression expr1 = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, ByteBufferUtil.bytes(1L));
IndexExpression expr2 = new IndexExpression(ByteBufferUtil.bytes("notbirthdate"), IndexOperator.GT, ByteBufferUtil.bytes(1L));
List<IndexExpression> clause = Arrays.asList(new IndexExpression[] { expr1, 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, 1, filter);
assert rows != null;
assert rows.size() == 1 : StringUtils.join(rows, ",");
}
use of org.apache.cassandra.dht.IPartitioner in project eiger by wlloyd.
the class ColumnFamilyStoreTest method testInclusiveBounds.
@Test
public void testInclusiveBounds() throws IOException, ExecutionException, InterruptedException {
ColumnFamilyStore cfs = insertKey1Key2();
IPartitioner p = StorageService.getPartitioner();
List<Row> result = cfs.getRangeSlice(ByteBufferUtil.EMPTY_BYTE_BUFFER, Util.bounds("key1", "key2"), 10, new NamesQueryFilter(ByteBufferUtil.bytes("asdf")), null);
assertEquals(2, result.size());
assert result.get(0).key.key.equals(ByteBufferUtil.bytes("key1"));
}
use of org.apache.cassandra.dht.IPartitioner in project eiger by wlloyd.
the class ColumnFamilyStoreTest method testSkipStartKey.
@Test
public void testSkipStartKey() throws IOException, ExecutionException, InterruptedException {
ColumnFamilyStore cfs = insertKey1Key2();
IPartitioner p = StorageService.getPartitioner();
List<Row> result = cfs.getRangeSlice(ByteBufferUtil.EMPTY_BYTE_BUFFER, Util.range(p, "key1", "key2"), 10, new NamesQueryFilter(ByteBufferUtil.bytes("asdf")), null);
assertEquals(1, result.size());
assert result.get(0).key.key.equals(ByteBufferUtil.bytes("key2"));
}
Aggregations