use of com.scalar.db.exception.transaction.CommitException in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method populateRecords.
private void populateRecords(String namespace, String table) throws CommitException, UnknownTransactionStatusException {
ConsensusCommit transaction = manager.start();
IntStream.range(0, NUM_ACCOUNTS).forEach(i -> IntStream.range(0, NUM_TYPES).forEach(j -> {
Key partitionKey = new Key(ACCOUNT_ID, i);
Key clusteringKey = new Key(ACCOUNT_TYPE, j);
Put put = new Put(partitionKey, clusteringKey).forNamespace(namespace).forTable(table).withValue(BALANCE, INITIAL_BALANCE);
transaction.put(put);
}));
transaction.commit();
}
use of com.scalar.db.exception.transaction.CommitException in project scalardb by scalar-labs.
the class ConsensusCommitSpecificIntegrationTestBase method populateRecords.
private void populateRecords(String namespace, String table) throws CommitException, UnknownTransactionStatusException {
ConsensusCommit transaction = manager.start();
IntStream.range(0, NUM_ACCOUNTS).forEach(i -> IntStream.range(0, NUM_TYPES).forEach(j -> {
Key partitionKey = new Key(ACCOUNT_ID, i);
Key clusteringKey = new Key(ACCOUNT_TYPE, j);
Put put = new Put(partitionKey, clusteringKey).forNamespace(namespace).forTable(table).withValue(BALANCE, INITIAL_BALANCE);
transaction.put(put);
}));
transaction.commit();
}
use of com.scalar.db.exception.transaction.CommitException in project scalardb by scalar-labs.
the class TwoPhaseConsensusCommit method prepare.
@Override
public void prepare() throws PreparationException {
checkStatus("The transaction is not active", Status.ACTIVE);
beforePrepareHook.run();
try {
commit.prepare(crud.getSnapshot(), false);
status = Status.PREPARED;
} catch (CommitConflictException e) {
status = Status.PREPARE_FAILED;
throw new PreparationConflictException("prepare failed", e);
} catch (CommitException e) {
status = Status.PREPARE_FAILED;
throw new PreparationException("prepare failed", e);
} catch (UnknownTransactionStatusException e) {
// Should not be reached here because CommitHandler.prepare() with abortIfError=false won't
// throw UnknownTransactionStatusException
}
}
use of com.scalar.db.exception.transaction.CommitException in project scalardb by scalar-labs.
the class CommitHandler method commitState.
public void commitState(Snapshot snapshot) throws CommitException, UnknownTransactionStatusException {
String id = snapshot.getId();
try {
commitState(snapshot.getId());
} catch (CoordinatorException e) {
TransactionState state = abort(id);
if (state.equals(TransactionState.ABORTED)) {
rollbackRecords(snapshot);
throw new CommitException("committing state in coordinator failed. the transaction is aborted", e);
}
}
LOGGER.debug("transaction {} is committed successfully at {}", id, System.currentTimeMillis());
}
use of com.scalar.db.exception.transaction.CommitException in project scalardb by scalar-labs.
the class TwoPhaseConsensusCommit method validate.
@Override
public void validate() throws ValidationException {
checkStatus("The transaction is not prepared", Status.PREPARED);
try {
commit.preCommitValidation(crud.getSnapshot(), false);
status = Status.VALIDATED;
} catch (CommitConflictException e) {
status = Status.VALIDATION_FAILED;
throw new ValidationConflictException("validation failed", e);
} catch (CommitException e) {
status = Status.VALIDATION_FAILED;
throw new ValidationException("validation failed", e);
} catch (UnknownTransactionStatusException e) {
// Should not be reached here because CommitHandler.prepare() with abortIfError=false won't
// throw UnknownTransactionStatusException
}
}
Aggregations