Search in sources :

Example 91 with QueryPath

use of org.apache.cassandra.db.filter.QueryPath in project eiger by wlloyd.

the class DynamicCompositeTypeTest method testFullRound.

@Test
public void testFullRound() throws Exception {
    Table table = Table.open("Keyspace1");
    ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
    ByteBuffer cname1 = createDynamicCompositeKey("test1", null, -1, false);
    ByteBuffer cname2 = createDynamicCompositeKey("test1", uuids[0], 24, false);
    ByteBuffer cname3 = createDynamicCompositeKey("test1", uuids[0], 42, false);
    ByteBuffer cname4 = createDynamicCompositeKey("test2", uuids[0], -1, false);
    ByteBuffer cname5 = createDynamicCompositeKey("test2", uuids[1], 42, false);
    ByteBuffer key = ByteBufferUtil.bytes("k");
    RowMutation rm = new RowMutation("Keyspace1", key);
    addColumn(rm, cname5);
    addColumn(rm, cname1);
    addColumn(rm, cname4);
    addColumn(rm, cname2);
    addColumn(rm, cname3);
    rm.apply();
    ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("k"), new QueryPath(cfName, null, null)));
    Iterator<IColumn> iter = cf.getSortedColumns().iterator();
    assert iter.next().name().equals(cname1);
    assert iter.next().name().equals(cname2);
    assert iter.next().name().equals(cname3);
    assert iter.next().name().equals(cname4);
    assert iter.next().name().equals(cname5);
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 92 with QueryPath

use of org.apache.cassandra.db.filter.QueryPath in project eiger by wlloyd.

the class RowMutation method convertToPending.

@Override
public PendingTransactionMutation convertToPending(long pendingTime, long transactionId) {
    PendingTransactionMutation pendingMutation = new PendingTransactionMutation(this.table_, this.key_, pendingTime, transactionId);
    for (ColumnFamily columnFamily : modifications_.values()) {
        String columnFamilyName = columnFamily.metadata().cfName;
        for (IColumn column : columnFamily.columns) {
            if (column instanceof SuperColumn) {
                if (column.getSubColumns().size() == 0) {
                    // just inserting a new super column
                    QueryPath path = new QueryPath(columnFamilyName, column.name(), null);
                    pendingMutation.makePending(path);
                } else {
                    for (IColumn subcolumn : column.getSubColumns()) {
                        QueryPath path = new QueryPath(columnFamilyName, column.name(), subcolumn.name());
                        pendingMutation.makePending(path);
                    }
                }
            } else if (column instanceof DeletedColumn) {
                assert column.getSubColumns().size() == 0 : "Haven't added support for deleting supercolumn in transactions yet";
                QueryPath path = new QueryPath(columnFamilyName, null, column.name());
                pendingMutation.makePending(path);
            } else {
                assert column instanceof Column;
                QueryPath path = new QueryPath(columnFamilyName, null, column.name());
                pendingMutation.makePending(path);
            }
        }
    }
    return pendingMutation;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) PendingTransactionMutation(org.apache.cassandra.db.transaction.PendingTransactionMutation) ColumnOrSuperColumn(org.apache.cassandra.thrift.ColumnOrSuperColumn) ColumnOrSuperColumn(org.apache.cassandra.thrift.ColumnOrSuperColumn)

Example 93 with QueryPath

use of org.apache.cassandra.db.filter.QueryPath in project eiger by wlloyd.

the class SystemTable method getOldLocalNodeIds.

public static List<NodeId.NodeIdRecord> getOldLocalNodeIds() {
    List<NodeId.NodeIdRecord> l = new ArrayList<NodeId.NodeIdRecord>();
    Table table = Table.open(Table.SYSTEM_TABLE);
    QueryFilter filter = QueryFilter.getIdentityFilter(decorate(ALL_LOCAL_NODE_ID_KEY), new QueryPath(NODE_ID_CF));
    ColumnFamily cf = table.getColumnFamilyStore(NODE_ID_CF).getColumnFamily(filter);
    NodeId previous = null;
    for (IColumn c : cf) {
        if (previous != null)
            l.add(new NodeId.NodeIdRecord(previous, c.timestamp()));
        // this will ignore the last column on purpose since it is the
        // current local node id
        previous = NodeId.wrap(c.name());
    }
    return l;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) NodeId(org.apache.cassandra.utils.NodeId)

Example 94 with QueryPath

use of org.apache.cassandra.db.filter.QueryPath in project eiger by wlloyd.

the class SystemTable method getSavedToken.

public static Token getSavedToken() {
    Table table = Table.open(Table.SYSTEM_TABLE);
    QueryFilter filter = QueryFilter.getNamesFilter(decorate(LOCATION_KEY), new QueryPath(STATUS_CF), TOKEN);
    ColumnFamily cf = table.getColumnFamilyStore(STATUS_CF).getColumnFamily(filter);
    return cf == null ? null : StorageService.getPartitioner().getTokenFactory().fromByteArray(cf.getColumn(TOKEN).value());
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) QueryFilter(org.apache.cassandra.db.filter.QueryFilter)

Example 95 with QueryPath

use of org.apache.cassandra.db.filter.QueryPath in project eiger by wlloyd.

the class SystemTable method incrementAndGetGeneration.

public static int incrementAndGetGeneration() throws IOException {
    Table table = Table.open(Table.SYSTEM_TABLE);
    QueryFilter filter = QueryFilter.getNamesFilter(decorate(LOCATION_KEY), new QueryPath(STATUS_CF), GENERATION);
    ColumnFamily cf = table.getColumnFamilyStore(STATUS_CF).getColumnFamily(filter);
    int generation;
    if (cf == null) {
        // seconds-since-epoch isn't a foolproof new generation
        // (where foolproof is "guaranteed to be larger than the last one seen at this ip address"),
        // but it's as close as sanely possible
        generation = (int) (System.currentTimeMillis() / 1000);
    } else {
        // Other nodes will ignore gossip messages about a node that have a lower generation than previously seen.
        final int storedGeneration = ByteBufferUtil.toInt(cf.getColumn(GENERATION).value()) + 1;
        final int now = (int) (System.currentTimeMillis() / 1000);
        if (storedGeneration >= now) {
            logger.warn("Using stored Gossip Generation {} as it is greater than current system time {}.  See CASSANDRA-3654 if you experience problems", storedGeneration, now);
            generation = storedGeneration;
        } else {
            generation = now;
        }
    }
    RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, LOCATION_KEY);
    cf = ColumnFamily.create(Table.SYSTEM_TABLE, SystemTable.STATUS_CF);
    cf.addColumn(new Column(GENERATION, ByteBufferUtil.bytes(generation), LamportClock.getVersion()));
    rm.add(cf);
    rm.apply();
    forceBlockingFlush(STATUS_CF);
    return generation;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) QueryFilter(org.apache.cassandra.db.filter.QueryFilter)

Aggregations

QueryPath (org.apache.cassandra.db.filter.QueryPath)127 Test (org.junit.Test)67 ByteBuffer (java.nio.ByteBuffer)40 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)22 ColumnFamily (org.apache.cassandra.db.ColumnFamily)14 RowMutation (org.apache.cassandra.db.RowMutation)12 File (java.io.File)10 SSTableReader (org.apache.cassandra.io.sstable.SSTableReader)10 IOException (java.io.IOException)8 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)8 DecoratedKey (org.apache.cassandra.db.DecoratedKey)8 Table (org.apache.cassandra.db.Table)8 SSTableUtils.tempSSTableFile (org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile)8 WrappedRunnable (org.apache.cassandra.utils.WrappedRunnable)8 ArrayList (java.util.ArrayList)5 IColumn (org.apache.cassandra.db.IColumn)5 PrintStream (java.io.PrintStream)4 UnknownHostException (java.net.UnknownHostException)4 HashSet (java.util.HashSet)4 DropColumnFamily (org.apache.cassandra.db.migration.DropColumnFamily)4