Search in sources :

Example 1 with PreparationException

use of com.scalar.db.exception.transaction.PreparationException in project scalardb by scalar-labs.

the class GrpcTwoPhaseCommitTransactionOnBidirectionalStream method throwIfErrorForPreparation.

private void throwIfErrorForPreparation(ResponseOrError responseOrError) throws PreparationException {
    if (responseOrError.isError()) {
        finished.set(true);
        Throwable error = responseOrError.getError();
        if (error instanceof Error) {
            throw (Error) error;
        }
        throw new PreparationException("failed to prepare", error);
    }
    TwoPhaseCommitTransactionResponse response = responseOrError.getResponse();
    if (response.hasError()) {
        TwoPhaseCommitTransactionResponse.Error error = response.getError();
        if (error.getErrorCode() == ErrorCode.CONFLICT) {
            throw new PreparationConflictException(error.getMessage());
        }
        throw new PreparationException(error.getMessage());
    }
}
Also used : PreparationException(com.scalar.db.exception.transaction.PreparationException) TwoPhaseCommitTransactionResponse(com.scalar.db.rpc.TwoPhaseCommitTransactionResponse) PreparationConflictException(com.scalar.db.exception.transaction.PreparationConflictException)

Example 2 with PreparationException

use of com.scalar.db.exception.transaction.PreparationException 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
    }
}
Also used : CommitConflictException(com.scalar.db.exception.transaction.CommitConflictException) CommitException(com.scalar.db.exception.transaction.CommitException) PreparationException(com.scalar.db.exception.transaction.PreparationException) UnknownTransactionStatusException(com.scalar.db.exception.transaction.UnknownTransactionStatusException) PreparationConflictException(com.scalar.db.exception.transaction.PreparationConflictException)

Aggregations

PreparationConflictException (com.scalar.db.exception.transaction.PreparationConflictException)2 PreparationException (com.scalar.db.exception.transaction.PreparationException)2 CommitConflictException (com.scalar.db.exception.transaction.CommitConflictException)1 CommitException (com.scalar.db.exception.transaction.CommitException)1 UnknownTransactionStatusException (com.scalar.db.exception.transaction.UnknownTransactionStatusException)1 TwoPhaseCommitTransactionResponse (com.scalar.db.rpc.TwoPhaseCommitTransactionResponse)1