Search in sources :

Example 51 with QueryPath

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

the class RemoveSuperColumnTest method validateRemoveSubColumn.

private void validateRemoveSubColumn(DecoratedKey dk) throws IOException {
    ColumnFamilyStore store = Table.open("Keyspace1").getColumnFamilyStore("Super3");
    ColumnFamily cf = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath("Super3", ByteBufferUtil.bytes("SC1")), Util.getBytes(1L)));
    assertNull(Util.cloneAndRemoveDeleted(cf, Integer.MAX_VALUE));
    cf = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath("Super3", ByteBufferUtil.bytes("SC1")), Util.getBytes(2L)));
    assertNotNull(Util.cloneAndRemoveDeleted(cf, Integer.MAX_VALUE));
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath)

Example 52 with QueryPath

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

the class RemoveSuperColumnTest method validateRemoveTwoSources.

private void validateRemoveTwoSources(DecoratedKey dk) throws IOException {
    ColumnFamilyStore store = Table.open("Keyspace1").getColumnFamilyStore("Super1");
    ColumnFamily cf = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath("Super1"), ByteBufferUtil.bytes("SC1")));
    assert cf.getSortedColumns().iterator().next().getMarkedForDeleteAt() == 1 : cf;
    assert cf.getSortedColumns().iterator().next().getSubColumns().size() == 0 : cf;
    assertNull(Util.cloneAndRemoveDeleted(cf, Integer.MAX_VALUE));
    cf = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath("Super1"), ByteBufferUtil.bytes("SC1")));
    assertNull(Util.cloneAndRemoveDeleted(cf, Integer.MAX_VALUE));
    cf = store.getColumnFamily(QueryFilter.getIdentityFilter(dk, new QueryPath("Super1")));
    assertNull(Util.cloneAndRemoveDeleted(cf, Integer.MAX_VALUE));
    assertNull(Util.cloneAndRemoveDeleted(store.getColumnFamily(QueryFilter.getIdentityFilter(dk, new QueryPath("Super1"))), Integer.MAX_VALUE));
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath)

Example 53 with QueryPath

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

the class RowIterationTest method testRowIteration.

@Test
public void testRowIteration() throws IOException, ExecutionException, InterruptedException {
    Table table = Table.open(TABLE1);
    ColumnFamilyStore store = table.getColumnFamilyStore("Super3");
    final int ROWS_PER_SSTABLE = 10;
    Set<DecoratedKey> inserted = new HashSet<DecoratedKey>();
    for (int i = 0; i < ROWS_PER_SSTABLE; i++) {
        DecoratedKey key = Util.dk(String.valueOf(i));
        RowMutation rm = new RowMutation(TABLE1, key.key);
        rm.add(new QueryPath("Super3", ByteBufferUtil.bytes("sc"), ByteBufferUtil.bytes(String.valueOf(i))), ByteBuffer.wrap(new byte[ROWS_PER_SSTABLE * 10 - i * 2]), i);
        rm.apply();
        inserted.add(key);
    }
    store.forceBlockingFlush();
    assertEquals(inserted.toString(), inserted.size(), Util.getRangeSlice(store).size());
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 54 with QueryPath

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

the class CassandraServer method add.

// counter methods
@Override
public WriteResult add(ByteBuffer key, ColumnParent column_parent, CounterColumn column, ConsistencyLevel consistency_level, Set<Dep> deps, long lts) throws InvalidRequestException, UnavailableException, TimedOutException, TException {
    LamportClock.updateTime(lts);
    logger.debug("add");
    state().hasColumnFamilyAccess(column_parent.column_family, Permission.WRITE);
    String keyspace = state().getKeyspace();
    CFMetaData metadata = ThriftValidation.validateColumnFamily(keyspace, column_parent.column_family, true);
    ThriftValidation.validateKey(metadata, key);
    ThriftValidation.validateCommutativeForWrite(metadata, consistency_level);
    ThriftValidation.validateColumnParent(metadata, column_parent);
    // SuperColumn field is usually optional, but not when we're adding
    if (metadata.cfType == ColumnFamilyType.Super && column_parent.super_column == null) {
        throw new InvalidRequestException("missing mandatory super column name for super CF " + column_parent.column_family);
    }
    ThriftValidation.validateColumnNames(metadata, column_parent, Arrays.asList(column.name));
    Set<Dependency> dependencies = new HashSet<Dependency>();
    for (Dep dep : deps) {
        dependencies.add(new Dependency(dep));
    }
    // add operations also need a dependency on the previous value for this datacenter
    try {
        ColumnOrSuperColumn cosc = this.internal_get(key, new ColumnPath(column_parent.column_family).setSuper_column(column_parent.super_column).setColumn(column.name), ConsistencyLevel.ONE);
        if (cosc.isSetColumn()) {
            // on that delete because clients have to wait until it reaches all nodes before resurrecting it
            assert cosc.column.isSetDeleted_time();
        } else {
            ClientContext tmpContext = new ClientContext();
            tmpContext.addDep(key, cosc);
            if (tmpContext.getDeps().size() > 0) {
                Dependency newDep = new Dependency(tmpContext.getDeps().iterator().next());
                dependencies.add(newDep);
                logger.debug("Adding a dependency on the previous value from this dc: " + newDep);
            }
        }
    } catch (NotFoundException e1) {
    // this is fine, it's the first add for this datacenter, no dep needed
    }
    RowMutation rm = new RowMutation(keyspace, key, dependencies);
    long timestamp = LamportClock.getVersion();
    try {
        rm.addCounter(new QueryPath(column_parent.column_family, column_parent.super_column, column.name), column.value, timestamp, timestamp, null);
    } catch (MarshalException e) {
        throw new InvalidRequestException(e.getMessage());
    }
    doInsert(consistency_level, Arrays.asList(new CounterMutation(rm, consistency_level)));
    if (logger.isTraceEnabled()) {
        logger.trace("add({}, {}, {}, {}, {}, {}) = {}", new Object[] { ByteBufferUtil.bytesToHex(key), column_parent, column, consistency_level, deps, lts, timestamp });
    }
    return new WriteResult(timestamp, LamportClock.sendTimestamp());
}
Also used : MarshalException(org.apache.cassandra.db.marshal.MarshalException) ClientContext(org.apache.cassandra.client.ClientContext) QueryPath(org.apache.cassandra.db.filter.QueryPath)

Example 55 with QueryPath

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

the class CassandraServer method internal_remove.

private long internal_remove(ByteBuffer key, ColumnPath column_path, long timestamp, ConsistencyLevel consistency_level, Set<Dep> deps, boolean isCommutativeOp) throws InvalidRequestException, UnavailableException, TimedOutException {
    state().hasColumnFamilyAccess(column_path.column_family, Permission.WRITE);
    CFMetaData metadata = ThriftValidation.validateColumnFamily(state().getKeyspace(), column_path.column_family, isCommutativeOp);
    ThriftValidation.validateKey(metadata, key);
    ThriftValidation.validateColumnPathOrParent(metadata, column_path);
    if (isCommutativeOp)
        ThriftValidation.validateCommutativeForWrite(metadata, consistency_level);
    // be 0 when sent to us, and we'll set it here.
    if (timestamp == 0) {
        timestamp = LamportClock.getVersion();
        logger.debug("Setting timestamp to {}", timestamp);
    }
    Set<Dependency> dependencies = new HashSet<Dependency>();
    for (Dep dep : deps) {
        dependencies.add(new Dependency(dep));
    }
    RowMutation rm = new RowMutation(state().getKeyspace(), key, dependencies);
    rm.delete(new QueryPath(column_path), timestamp);
    if (isCommutativeOp)
        doInsert(consistency_level, Arrays.asList(new CounterMutation(rm, consistency_level)));
    else
        doInsert(consistency_level, Arrays.asList(rm));
    return timestamp;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath)

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