use of com.scalar.db.transaction.consensuscommit.Attribute.toVersionValue 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);
}
use of com.scalar.db.transaction.consensuscommit.Attribute.toVersionValue 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);
}
Aggregations