Search in sources :

Example 16 with CFMetaData

use of org.apache.cassandra.config.CFMetaData in project eiger by wlloyd.

the class ColumnFamily method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder("ColumnFamily(");
    CFMetaData cfm = metadata();
    sb.append(cfm == null ? "<anonymous>" : cfm.cfName);
    if (isMarkedForDelete())
        sb.append(" -deleted at ").append(getMarkedForDeleteAt()).append("-");
    sb.append(" [").append(getComparator().getColumnsString(getSortedColumns())).append("])");
    return sb.toString();
}
Also used : CFMetaData(org.apache.cassandra.config.CFMetaData)

Example 17 with CFMetaData

use of org.apache.cassandra.config.CFMetaData in project eiger by wlloyd.

the class RowMutation method toString.

@Override
public String toString(boolean shallow) {
    StringBuilder buff = new StringBuilder("RowMutation(");
    buff.append("keyspace='").append(table_).append('\'');
    buff.append(", key='").append(ByteBufferUtil.bytesToHex(key_)).append('\'');
    buff.append(", modifications=[");
    if (shallow) {
        List<String> cfnames = new ArrayList<String>();
        for (Integer cfid : modifications_.keySet()) {
            CFMetaData cfm = Schema.instance.getCFMetaData(cfid);
            cfnames.add(cfm == null ? "-dropped-" : cfm.cfName);
        }
        buff.append(StringUtils.join(cfnames, ", "));
    } else
        buff.append(StringUtils.join(modifications_.values(), ", "));
    return buff.append("])").toString();
}
Also used : CFMetaData(org.apache.cassandra.config.CFMetaData)

Example 18 with CFMetaData

use of org.apache.cassandra.config.CFMetaData in project eiger by wlloyd.

the class ReadCallback method randomlyReadRepair.

private boolean randomlyReadRepair() {
    if (resolver instanceof RowDigestResolver) {
        assert command instanceof ReadCommand : command;
        String table = ((RowDigestResolver) resolver).table;
        String columnFamily = ((ReadCommand) command).getColumnFamilyName();
        CFMetaData cfmd = Schema.instance.getTableMetaData(table).get(columnFamily);
        return cfmd.getReadRepairChance() > FBUtilities.threadLocalRandom().nextDouble();
    }
    // we don't read repair on range scans
    return false;
}
Also used : ReadCommand(org.apache.cassandra.db.ReadCommand) CFMetaData(org.apache.cassandra.config.CFMetaData)

Example 19 with CFMetaData

use of org.apache.cassandra.config.CFMetaData in project eiger by wlloyd.

the class DeleteStatement method mutationForKey.

public RowMutation mutationForKey(ByteBuffer key, String keyspace, Long timestamp, ClientState clientState, List<String> variables) throws InvalidRequestException {
    RowMutation rm = new RowMutation(keyspace, key);
    CFMetaData metadata = validateColumnFamily(keyspace, columnFamily);
    QueryProcessor.validateKeyAlias(metadata, keyName);
    AbstractType<?> comparator = metadata.getComparatorFor(null);
    if (columns.size() < 1) {
        // No columns, delete the row
        rm.delete(new QueryPath(columnFamily), (timestamp == null) ? getTimestamp(clientState) : timestamp);
    } else {
        // Delete specific columns
        for (Term column : columns) {
            ByteBuffer columnName = column.getByteBuffer(comparator, variables);
            validateColumnName(columnName);
            rm.delete(new QueryPath(columnFamily, null, columnName), (timestamp == null) ? getTimestamp(clientState) : timestamp);
        }
    }
    return rm;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) RowMutation(org.apache.cassandra.db.RowMutation) CFMetaData(org.apache.cassandra.config.CFMetaData) ByteBuffer(java.nio.ByteBuffer)

Example 20 with CFMetaData

use of org.apache.cassandra.config.CFMetaData in project eiger by wlloyd.

the class BatchMutateTransactionUtil method convertToInternalMutations.

public static List<IMutation> convertToInternalMutations(String keyspace, Map<ByteBuffer, Map<String, List<Mutation>>> mutation_map, ByteBuffer coordinatorKey) throws InvalidRequestException {
    //the timestamp and localCommitTime are set when we apply the transaction, so we'll set them to invalid values here
    long timestamp = Long.MIN_VALUE;
    long localCommitTime = Long.MIN_VALUE;
    List<IMutation> rowMutations = new ArrayList<IMutation>();
    //Note, permission was checked when the thrift interface received the transaction.
    for (Map.Entry<ByteBuffer, Map<String, List<Mutation>>> mutationEntry : mutation_map.entrySet()) {
        ByteBuffer key = mutationEntry.getKey();
        // We need to separate row mutation for standard cf and counter cf (that will be encapsulated in a
        // CounterMutation) because it doesn't follow the same code path
        RowMutation rmStandard = null;
        RowMutation rmCounter = null;
        Map<String, List<Mutation>> columnFamilyToMutations = mutationEntry.getValue();
        for (Map.Entry<String, List<Mutation>> columnFamilyMutations : columnFamilyToMutations.entrySet()) {
            String cfName = columnFamilyMutations.getKey();
            CFMetaData metadata = ThriftValidation.validateColumnFamily(keyspace, cfName);
            ThriftValidation.validateKey(metadata, key);
            RowMutation rm;
            if (metadata.getDefaultValidator().isCommutative()) {
                ThriftValidation.validateCommutativeForWrite(metadata, ConsistencyLevel.ONE);
                rmCounter = rmCounter == null ? new RowMutation(keyspace, key) : rmCounter;
                rm = rmCounter;
            } else {
                rmStandard = rmStandard == null ? new RowMutation(keyspace, key) : rmStandard;
                rm = rmStandard;
            }
            for (Mutation mutation : columnFamilyMutations.getValue()) {
                ThriftValidation.validateMutation(metadata, mutation);
                if (mutation.deletion != null) {
                    rm.deleteColumnOrSuperColumn(cfName, mutation.deletion, timestamp, localCommitTime, coordinatorKey);
                }
                if (mutation.column_or_supercolumn != null) {
                    rm.addColumnOrSuperColumn(cfName, mutation.column_or_supercolumn, timestamp, localCommitTime, coordinatorKey);
                }
            }
        }
        if (rmStandard != null && !rmStandard.isEmpty())
            rowMutations.add(rmStandard);
        if (rmCounter != null && !rmCounter.isEmpty())
            rowMutations.add(new org.apache.cassandra.db.CounterMutation(rmCounter, ConsistencyLevel.ONE));
    }
    logger.debug("Mutations are {}", rowMutations);
    return rowMutations;
}
Also used : IMutation(org.apache.cassandra.db.IMutation) ByteBuffer(java.nio.ByteBuffer) CounterMutation(org.apache.cassandra.db.CounterMutation) RowMutation(org.apache.cassandra.db.RowMutation) CFMetaData(org.apache.cassandra.config.CFMetaData) CounterMutation(org.apache.cassandra.db.CounterMutation) RowMutation(org.apache.cassandra.db.RowMutation) Mutation(org.apache.cassandra.thrift.Mutation) IMutation(org.apache.cassandra.db.IMutation) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

CFMetaData (org.apache.cassandra.config.CFMetaData)22 ByteBuffer (java.nio.ByteBuffer)4 ColumnDefinition (org.apache.cassandra.config.ColumnDefinition)3 ConfigurationException (org.apache.cassandra.config.ConfigurationException)3 AbstractType (org.apache.cassandra.db.marshal.AbstractType)3 InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)3 Test (org.junit.Test)3 KSMetaData (org.apache.cassandra.config.KSMetaData)2 IMutation (org.apache.cassandra.db.IMutation)2 RowMutation (org.apache.cassandra.db.RowMutation)2 QueryPath (org.apache.cassandra.db.filter.QueryPath)2 File (java.io.File)1 IOException (java.io.IOException)1 CharacterCodingException (java.nio.charset.CharacterCodingException)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)1