Search in sources :

Example 1 with ValidationConflictException

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

the class GrpcTwoPhaseCommitTransactionOnBidirectionalStream method throwIfErrorForValidation.

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

Example 2 with ValidationConflictException

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

Aggregations

ValidationConflictException (com.scalar.db.exception.transaction.ValidationConflictException)2 ValidationException (com.scalar.db.exception.transaction.ValidationException)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