Search in sources :

Example 16 with QueryPath

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

the class CassandraServer method internal_insert.

private void internal_insert(ByteBuffer key, ColumnParent column_parent, Column column, ConsistencyLevel consistency_level, Set<Dep> deps) throws InvalidRequestException, UnavailableException, TimedOutException {
    state().hasColumnFamilyAccess(column_parent.column_family, Permission.WRITE);
    CFMetaData metadata = ThriftValidation.validateColumnFamily(state().getKeyspace(), column_parent.column_family, false);
    ThriftValidation.validateKey(metadata, key);
    ThriftValidation.validateColumnParent(metadata, column_parent);
    // SuperColumn field is usually optional, but not when we're inserting
    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));
    ThriftValidation.validateColumnData(metadata, column, column_parent.super_column != null);
    // be 0 when sent to us, and we'll set it here.
    if (column.timestamp == 0) {
        column.timestamp = LamportClock.getVersion();
        logger.debug("Setting timestamp to {}", column.timestamp);
    }
    Set<Dependency> dependencies = new HashSet<Dependency>();
    for (Dep dep : deps) {
        dependencies.add(new Dependency(dep));
    }
    RowMutation rm = new RowMutation(state().getKeyspace(), key, dependencies);
    try {
        rm.add(new QueryPath(column_parent.column_family, column_parent.super_column, column.name), column.value, column.timestamp, column.ttl);
    } catch (MarshalException e) {
        throw new InvalidRequestException(e.getMessage());
    }
    doInsert(consistency_level, Arrays.asList(rm));
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) MarshalException(org.apache.cassandra.db.marshal.MarshalException)

Example 17 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)

Example 18 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 19 with QueryPath

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

the class CleanupTest method fillCF.

protected void fillCF(ColumnFamilyStore cfs, int rowsPerSSTable) throws ExecutionException, InterruptedException, IOException {
    CompactionManager.instance.disableAutoCompaction();
    for (int i = 0; i < rowsPerSSTable; i++) {
        String key = String.valueOf(i);
        // create a row and update the birthdate value, test that the index query fetches the new version
        RowMutation rm;
        rm = new RowMutation(TABLE1, ByteBufferUtil.bytes(key));
        rm.add(new QueryPath(cfs.getColumnFamilyName(), null, COLUMN), VALUE, System.currentTimeMillis());
        rm.applyUnsafe();
    }
    cfs.forceBlockingFlush();
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath)

Example 20 with QueryPath

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

the class CommitLogTest method testExceedSegmentSizeWithOverhead.

// CASSANDRA-3615
@Test
public void testExceedSegmentSizeWithOverhead() throws Exception {
    CommitLog.instance.resetUnsafe();
    RowMutation rm = new RowMutation("Keyspace1", bytes("k"));
    rm.add(new QueryPath("Standard1", null, bytes("c1")), ByteBuffer.allocate((128 * 1024 * 1024) - 83), 0);
    CommitLog.instance.add(rm);
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) Test(org.junit.Test)

Aggregations

QueryPath (org.apache.cassandra.db.filter.QueryPath)123 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)11 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 IColumn (org.apache.cassandra.db.IColumn)6 ArrayList (java.util.ArrayList)5 PrintStream (java.io.PrintStream)4 UnknownHostException (java.net.UnknownHostException)4 HashSet (java.util.HashSet)4 DropColumnFamily (org.apache.cassandra.db.migration.DropColumnFamily)4