Search in sources :

Example 41 with IPartitioner

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);
    }
}
Also used : CTConnection(com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection) AbstractByteOrderedPartitioner(org.apache.cassandra.dht.AbstractByteOrderedPartitioner) KeyRange(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange) ArrayList(java.util.ArrayList) Token(org.apache.cassandra.dht.Token) BackendException(com.thinkaurelius.titan.diskstorage.BackendException) TException(org.apache.thrift.TException) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Example 42 with IPartitioner

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();
}
Also used : Message(org.apache.cassandra.net.Message) SliceRange(org.apache.cassandra.thrift.SliceRange) DataOutputStream(java.io.DataOutputStream) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate) Token(org.apache.cassandra.dht.Token) ByteBuffer(java.nio.ByteBuffer) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Example 43 with IPartitioner

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, ",");
}
Also used : IdentityQueryFilter(org.apache.cassandra.db.columniterator.IdentityQueryFilter) IPartitioner(org.apache.cassandra.dht.IPartitioner) Test(org.junit.Test)

Example 44 with IPartitioner

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"));
}
Also used : IPartitioner(org.apache.cassandra.dht.IPartitioner) Test(org.junit.Test)

Example 45 with IPartitioner

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"));
}
Also used : IPartitioner(org.apache.cassandra.dht.IPartitioner) Test(org.junit.Test)

Aggregations

IPartitioner (org.apache.cassandra.dht.IPartitioner)55 Token (org.apache.cassandra.dht.Token)28 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)7 RandomPartitioner (org.apache.cassandra.dht.RandomPartitioner)6 IOError (java.io.IOError)4 ByteBuffer (java.nio.ByteBuffer)4 ExecutionException (java.util.concurrent.ExecutionException)3 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