Search in sources :

Example 1 with Attribute.toIdValue

use of com.scalar.db.transaction.consensuscommit.Attribute.toIdValue in project scalardb by scalar-labs.

the class PrepareMutationComposer method add.

private void add(Delete base, TransactionResult result) {
    Put put = new Put(base.getPartitionKey(), getClusteringKey(base, result).orElse(null)).forNamespace(base.forNamespace().get()).forTable(base.forTable().get()).withConsistency(Consistency.LINEARIZABLE);
    List<Value<?>> values = new ArrayList<>();
    values.add(Attribute.toIdValue(id));
    values.add(Attribute.toStateValue(TransactionState.DELETED));
    values.add(Attribute.toPreparedAtValue(current));
    if (result != null) {
        values.addAll(createBeforeValues(base, result));
        int version = result.getVersion();
        values.add(Attribute.toVersionValue(version + 1));
        // check if the record is not interrupted by other conflicting transactions
        put.withCondition(new PutIf(new ConditionalExpression(VERSION, toVersionValue(version), Operator.EQ), new ConditionalExpression(ID, toIdValue(result.getId()), Operator.EQ)));
    } else {
        put.withValue(Attribute.toVersionValue(1));
        // check if the record is not created by other conflicting transactions
        put.withCondition(new PutIfNotExists());
    }
    put.withValues(values);
    mutations.add(put);
}
Also used : PutIfNotExists(com.scalar.db.api.PutIfNotExists) PutIf(com.scalar.db.api.PutIf) ConditionalExpression(com.scalar.db.api.ConditionalExpression) Value(com.scalar.db.io.Value) Attribute.toIdValue(com.scalar.db.transaction.consensuscommit.Attribute.toIdValue) Attribute.toVersionValue(com.scalar.db.transaction.consensuscommit.Attribute.toVersionValue) ArrayList(java.util.ArrayList) Put(com.scalar.db.api.Put)

Example 2 with Attribute.toIdValue

use of com.scalar.db.transaction.consensuscommit.Attribute.toIdValue in project scalardb by scalar-labs.

the class PrepareMutationComposer method add.

// This prepares a record that was read but didn't exist to avoid anti-dependency for the record.
// This is only called when Serializable with Extra-write strategy is enabled.
private void add(Get base) {
    Put put = new Put(base.getPartitionKey(), getClusteringKey(base, null).orElse(null)).forNamespace(base.forNamespace().get()).forTable(base.forTable().get()).withConsistency(Consistency.LINEARIZABLE);
    List<Value<?>> values = new ArrayList<>();
    values.add(Attribute.toIdValue(id));
    values.add(Attribute.toStateValue(TransactionState.DELETED));
    values.add(Attribute.toPreparedAtValue(current));
    values.add(Attribute.toVersionValue(1));
    // check if the record is not interrupted by other conflicting transactions
    put.withCondition(new PutIfNotExists());
    put.withValues(values);
    mutations.add(put);
}
Also used : PutIfNotExists(com.scalar.db.api.PutIfNotExists) Value(com.scalar.db.io.Value) Attribute.toIdValue(com.scalar.db.transaction.consensuscommit.Attribute.toIdValue) Attribute.toVersionValue(com.scalar.db.transaction.consensuscommit.Attribute.toVersionValue) ArrayList(java.util.ArrayList) Put(com.scalar.db.api.Put)

Aggregations

Put (com.scalar.db.api.Put)2 PutIfNotExists (com.scalar.db.api.PutIfNotExists)2 Value (com.scalar.db.io.Value)2 Attribute.toIdValue (com.scalar.db.transaction.consensuscommit.Attribute.toIdValue)2 Attribute.toVersionValue (com.scalar.db.transaction.consensuscommit.Attribute.toVersionValue)2 ArrayList (java.util.ArrayList)2 ConditionalExpression (com.scalar.db.api.ConditionalExpression)1 PutIf (com.scalar.db.api.PutIf)1