use of org.apache.cassandra.db.IMutation in project eiger by wlloyd.
the class UpdateStatement method prepareRowMutations.
/** {@inheritDoc} */
@Override
public List<IMutation> prepareRowMutations(String keyspace, ClientState clientState, Long timestamp, List<String> variables) throws InvalidRequestException {
List<String> cfamsSeen = new ArrayList<String>();
boolean hasCommutativeOperation = false;
for (Map.Entry<Term, Operation> column : getColumns().entrySet()) {
if (!column.getValue().isUnary())
hasCommutativeOperation = true;
if (hasCommutativeOperation && column.getValue().isUnary())
throw new InvalidRequestException("Mix of commutative and non-commutative operations is not allowed.");
}
CFMetaData metadata = validateColumnFamily(keyspace, columnFamily, hasCommutativeOperation);
if (hasCommutativeOperation)
validateCommutativeForWrite(metadata, cLevel);
QueryProcessor.validateKeyAlias(metadata, keyName);
// Avoid unnecessary authorizations.
if (!(cfamsSeen.contains(columnFamily))) {
clientState.hasColumnFamilyAccess(columnFamily, Permission.WRITE);
cfamsSeen.add(columnFamily);
}
List<IMutation> rowMutations = new LinkedList<IMutation>();
for (Term key : keys) {
if (timestamp != 0) {
logger.warn("Supplied timestamp: " + timestamp + " ignored, server generating timestamp");
}
long opTimestamp = LamportClock.getVersion();
rowMutations.add(mutationForKey(keyspace, key.getByteBuffer(getKeyType(keyspace), variables), metadata, opTimestamp, clientState, variables));
}
return rowMutations;
}
use of org.apache.cassandra.db.IMutation in project cassandra-indexing by hmsonline.
the class CassandraIndexAspect method process.
@Around("execution(* org.apache.cassandra.thrift.CassandraServer.doInsert(..))")
public void process(ProceedingJoinPoint joinPoint) throws Throwable {
ConsistencyLevel consistency = (ConsistencyLevel) joinPoint.getArgs()[0];
@SuppressWarnings("unchecked") List<IMutation> mutations = (List<IMutation>) joinPoint.getArgs()[1];
Handler handler = new Handler(cluster, indexDao, configurationDao, mutations, consistency);
Future<?> future = executors.submit(handler);
future.get();
joinPoint.proceed(joinPoint.getArgs());
}
use of org.apache.cassandra.db.IMutation 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;
}
Aggregations