Search in sources :

Example 1 with ServiceTemporaryUnavailableException

use of com.scalar.db.util.retry.ServiceTemporaryUnavailableException in project scalardb by scalar-labs.

the class GrpcScanOnBidirectionalStream method throwIfErrorForOpenScanner.

private void throwIfErrorForOpenScanner(ResponseOrError responseOrError) throws ExecutionException {
    if (responseOrError.isError()) {
        hasMoreResults.set(false);
        Throwable error = responseOrError.getError();
        if (error instanceof StatusRuntimeException) {
            StatusRuntimeException e = (StatusRuntimeException) error;
            if (e.getStatus().getCode() == Code.INVALID_ARGUMENT) {
                throw new IllegalArgumentException(e.getMessage(), e);
            }
            if (e.getStatus().getCode() == Code.UNAVAILABLE) {
                throw new ServiceTemporaryUnavailableException(e.getMessage(), e);
            }
        }
        if (error instanceof Error) {
            throw (Error) error;
        }
        throw new ExecutionException("failed to open scanner", error);
    }
}
Also used : ServiceTemporaryUnavailableException(com.scalar.db.util.retry.ServiceTemporaryUnavailableException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(com.scalar.db.exception.storage.ExecutionException)

Example 2 with ServiceTemporaryUnavailableException

use of com.scalar.db.util.retry.ServiceTemporaryUnavailableException in project scalardb by scalar-labs.

the class GrpcTransactionOnBidirectionalStream method throwIfErrorForStart.

private void throwIfErrorForStart(ResponseOrError responseOrError) throws TransactionException {
    if (responseOrError.isError()) {
        finished.set(true);
        Throwable error = responseOrError.getError();
        if (error instanceof StatusRuntimeException) {
            StatusRuntimeException e = (StatusRuntimeException) error;
            if (e.getStatus().getCode() == Code.INVALID_ARGUMENT) {
                throw new IllegalArgumentException(e.getMessage(), e);
            }
            if (e.getStatus().getCode() == Code.UNAVAILABLE) {
                throw new ServiceTemporaryUnavailableException(e.getMessage(), e);
            }
        }
        if (error instanceof Error) {
            throw (Error) error;
        }
        throw new TransactionException("failed to start", error);
    }
}
Also used : TransactionException(com.scalar.db.exception.transaction.TransactionException) ServiceTemporaryUnavailableException(com.scalar.db.util.retry.ServiceTemporaryUnavailableException) StatusRuntimeException(io.grpc.StatusRuntimeException)

Example 3 with ServiceTemporaryUnavailableException

use of com.scalar.db.util.retry.ServiceTemporaryUnavailableException in project scalardb by scalar-labs.

the class GrpcTwoPhaseCommitTransactionOnBidirectionalStream method throwIfErrorForStartOrJoin.

private void throwIfErrorForStartOrJoin(ResponseOrError responseOrError, boolean start) throws TransactionException {
    if (responseOrError.isError()) {
        finished.set(true);
        Throwable error = responseOrError.getError();
        if (error instanceof StatusRuntimeException) {
            StatusRuntimeException e = (StatusRuntimeException) error;
            if (e.getStatus().getCode() == Code.INVALID_ARGUMENT) {
                throw new IllegalArgumentException(e.getMessage(), e);
            }
            if (e.getStatus().getCode() == Code.UNAVAILABLE) {
                throw new ServiceTemporaryUnavailableException(e.getMessage(), e);
            }
        }
        if (error instanceof Error) {
            throw (Error) error;
        }
        throw new TransactionException("failed to " + (start ? "start" : "join"), error);
    }
}
Also used : TransactionException(com.scalar.db.exception.transaction.TransactionException) ServiceTemporaryUnavailableException(com.scalar.db.util.retry.ServiceTemporaryUnavailableException) StatusRuntimeException(io.grpc.StatusRuntimeException)

Aggregations

ServiceTemporaryUnavailableException (com.scalar.db.util.retry.ServiceTemporaryUnavailableException)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3 TransactionException (com.scalar.db.exception.transaction.TransactionException)2 ExecutionException (com.scalar.db.exception.storage.ExecutionException)1