diff --git a/core/src/main/java/com/scalar/db/storage/cassandra/BatchHandler.java b/core/src/main/java/com/scalar/db/storage/cassandra/BatchHandler.java index 035f1229d4..1b141f5ec9 100644 --- a/core/src/main/java/com/scalar/db/storage/cassandra/BatchHandler.java +++ b/core/src/main/java/com/scalar/db/storage/cassandra/BatchHandler.java @@ -11,8 +11,8 @@ import com.google.common.annotations.VisibleForTesting; import com.scalar.db.api.Mutation; import com.scalar.db.common.CoreError; +import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.exception.storage.NoMutationException; -import com.scalar.db.exception.storage.RetriableExecutionException; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.List; import javax.annotation.concurrent.ThreadSafe; @@ -48,12 +48,11 @@ public BatchHandler(Session session, StatementHandlerManager handlers) { * must be for the same partition. * * @param mutations a list of {@code Mutation}s to execute - * @throws RetriableExecutionException if it fails, but it can be retried * @throws NoMutationException if at least one of conditional {@code Mutation}s fails because it * didn't meet the condition + * @throws ExecutionException if the execution fails */ - public void handle(List mutations) - throws RetriableExecutionException, NoMutationException { + public void handle(List mutations) throws ExecutionException { try { ResultSet results = execute(mutations); // it's for conditional update. non-conditional update always return true @@ -64,16 +63,17 @@ public void handle(List mutations) logger.warn("Write timeout happened during batch mutate operation", e); WriteType writeType = e.getWriteType(); if (writeType == WriteType.BATCH_LOG) { - throw new RetriableExecutionException( - CoreError.CASSANDRA_LOGGING_FAILED_IN_BATCH.buildMessage(), e); + // A timeout occurred while the coordinator was waiting for the batch log replicas to + // acknowledge the log. Thus, the batch may or may not be applied. + throw new ExecutionException(CoreError.CASSANDRA_LOGGING_FAILED_IN_BATCH.buildMessage(), e); } else if (writeType == WriteType.BATCH) { logger.warn("Logging succeeded, but mutations in the batch partially failed", e); } else { - throw new RetriableExecutionException( + throw new ExecutionException( CoreError.CASSANDRA_OPERATION_FAILED_IN_BATCH.buildMessage(writeType), e); } } catch (RuntimeException e) { - throw new RetriableExecutionException( + throw new ExecutionException( CoreError.CASSANDRA_ERROR_OCCURRED_IN_BATCH.buildMessage(e.getMessage()), e); } } diff --git a/core/src/main/java/com/scalar/db/storage/cassandra/MutateStatementHandler.java b/core/src/main/java/com/scalar/db/storage/cassandra/MutateStatementHandler.java index 026eaebf47..5a80a4dc69 100644 --- a/core/src/main/java/com/scalar/db/storage/cassandra/MutateStatementHandler.java +++ b/core/src/main/java/com/scalar/db/storage/cassandra/MutateStatementHandler.java @@ -12,7 +12,6 @@ import com.scalar.db.common.CoreError; import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.exception.storage.NoMutationException; -import com.scalar.db.exception.storage.RetriableExecutionException; import javax.annotation.Nonnull; import javax.annotation.concurrent.ThreadSafe; @@ -28,9 +27,9 @@ public MutateStatementHandler(Session session) { * * @param operation {@link Mutation} operation * @return a {@code ResultSet} - * @throws RetriableExecutionException if the execution fails, but it can be retriable * @throws ReadRepairableExecutionException if the execution partially fails, which can be * repaired by a following read + * @throws ExecutionException if the execution fails */ @Override @Nonnull @@ -45,8 +44,7 @@ public ResultSet handle(Operation operation) throws ExecutionException { return results; } catch (WriteTimeoutException e) { if (e.getWriteType() == WriteType.CAS) { - // retry needs to be done if applications need to do the operation exactly - throw new RetriableExecutionException( + throw new ExecutionException( CoreError.CASSANDRA_WRITE_TIMEOUT_IN_PAXOS_PHASE_IN_MUTATION.buildMessage(), e); } else if (e.getWriteType() == WriteType.SIMPLE) { Mutation mutation = (Mutation) operation; @@ -55,8 +53,7 @@ public ResultSet handle(Operation operation) throws ExecutionException { throw new ReadRepairableExecutionException( CoreError.CASSANDRA_WRITE_TIMEOUT_IN_LEARN_PHASE_IN_MUTATION.buildMessage(), e); } else { - // retry needs to be done if applications need to do the operation exactly - throw new RetriableExecutionException( + throw new ExecutionException( CoreError.CASSANDRA_WRITE_TIMEOUT_SIMPLE_WRITE_OPERATION_FAILED_IN_MUTATION .buildMessage(), e); @@ -66,7 +63,7 @@ public ResultSet handle(Operation operation) throws ExecutionException { CoreError.CASSANDRA_WRITE_TIMEOUT_WITH_OTHER_WRITE_TYPE_IN_MUTATION.buildMessage(), e); } } catch (RuntimeException e) { - throw new RetriableExecutionException( + throw new ExecutionException( CoreError.CASSANDRA_ERROR_OCCURRED_IN_MUTATION.buildMessage(e.getMessage()), e); } } diff --git a/core/src/test/java/com/scalar/db/storage/cassandra/BatchHandlerTest.java b/core/src/test/java/com/scalar/db/storage/cassandra/BatchHandlerTest.java index 04f0934822..ee65aeefe5 100644 --- a/core/src/test/java/com/scalar/db/storage/cassandra/BatchHandlerTest.java +++ b/core/src/test/java/com/scalar/db/storage/cassandra/BatchHandlerTest.java @@ -20,8 +20,8 @@ import com.scalar.db.api.Put; import com.scalar.db.api.PutIfExists; import com.scalar.db.api.PutIfNotExists; +import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.exception.storage.NoMutationException; -import com.scalar.db.exception.storage.RetriableExecutionException; import com.scalar.db.io.Key; import java.util.Arrays; import java.util.List; @@ -178,7 +178,7 @@ public void handle_CorrectHandlerAndAtLeastOneConditionalPutGiven_ShouldSetConsi } @Test - public void handle_WTEThrownInLoggingInBatchExecution_ShouldThrowRetriableExecutionException() { + public void handle_WTEThrownInLoggingInBatchExecution_ShouldThrowExecutionException() { // Arrange configureBehavior(); mutations = prepareConditionalPuts(); @@ -188,7 +188,7 @@ public void handle_WTEThrownInLoggingInBatchExecution_ShouldThrowRetriableExecut // Act Assert assertThatThrownBy(() -> batch.handle(mutations)) - .isInstanceOf(RetriableExecutionException.class) + .isInstanceOf(ExecutionException.class) .hasCause(e); } @@ -206,7 +206,7 @@ public void handle_WTEThrownInMutationInBatchExecution_ShouldExecuteProperly() { } @Test - public void handle_WTEThrownInCasInBatchExecution_ShouldThrowRetriableExecutionException() { + public void handle_WTEThrownInCasInBatchExecution_ShouldThrowExecutionException() { // Arrange configureBehavior(); mutations = prepareConditionalPuts(); @@ -216,13 +216,12 @@ public void handle_WTEThrownInCasInBatchExecution_ShouldThrowRetriableExecutionE // Act Assert assertThatThrownBy(() -> batch.handle(mutations)) - .isInstanceOf(RetriableExecutionException.class) + .isInstanceOf(ExecutionException.class) .hasCause(e); } @Test - public void - handle_WTEThrownInSimpleWriteInBatchExecution_ShouldThrowRetriableExecutionException() { + public void handle_WTEThrownInSimpleWriteInBatchExecution_ShouldThrowExecutionException() { // Arrange configureBehavior(); mutations = prepareConditionalPuts(); @@ -232,12 +231,12 @@ public void handle_WTEThrownInCasInBatchExecution_ShouldThrowRetriableExecutionE // Act Assert assertThatThrownBy(() -> batch.handle(mutations)) - .isInstanceOf(RetriableExecutionException.class) + .isInstanceOf(ExecutionException.class) .hasCause(e); } @Test - public void handle_DriverExceptionThrownInExecution_ShouldThrowRetriableExecutionException() { + public void handle_DriverExceptionThrownInExecution_ShouldThrowExecutionException() { // Arrange configureBehavior(); mutations = prepareConditionalPuts(); @@ -246,7 +245,7 @@ public void handle_DriverExceptionThrownInExecution_ShouldThrowRetriableExecutio // Act Assert assertThatThrownBy(() -> batch.handle(mutations)) - .isInstanceOf(RetriableExecutionException.class) + .isInstanceOf(ExecutionException.class) .hasCause(e); } diff --git a/core/src/test/java/com/scalar/db/storage/cassandra/InsertStatementHandlerTest.java b/core/src/test/java/com/scalar/db/storage/cassandra/InsertStatementHandlerTest.java index f87021fbbd..614f303077 100644 --- a/core/src/test/java/com/scalar/db/storage/cassandra/InsertStatementHandlerTest.java +++ b/core/src/test/java/com/scalar/db/storage/cassandra/InsertStatementHandlerTest.java @@ -28,7 +28,6 @@ import com.scalar.db.api.PutIfNotExists; import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.exception.storage.NoMutationException; -import com.scalar.db.exception.storage.RetriableExecutionException; import com.scalar.db.io.Key; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -330,7 +329,7 @@ public void setConsistency_PutOperationWithIfNotExistsGiven_ShouldPrepareWithQuo } @Test - public void handle_WTEWithCasThrown_ShouldThrowProperExecutionException() { + public void handle_WTEWithCasThrown_ShouldThrowExecutionException() { // Arrange put = preparePutWithClusteringKey(); put.withCondition(new PutIfNotExists()); @@ -342,13 +341,12 @@ public void handle_WTEWithCasThrown_ShouldThrowProperExecutionException() { // Act Assert assertThatThrownBy(() -> spy.handle(put)) - .isInstanceOf(RetriableExecutionException.class) + .isInstanceOf(ExecutionException.class) .hasCause(toThrow); } @Test - public void - handle_PutWithConditionGivenAndWTEWithSimpleThrown_ShouldThrowProperExecutionException() { + public void handle_PutWithConditionGivenAndWTEWithSimpleThrown_ShouldThrowExecutionException() { // Arrange put = preparePutWithClusteringKey(); put.withCondition(new PutIfNotExists()); @@ -366,7 +364,7 @@ public void handle_WTEWithCasThrown_ShouldThrowProperExecutionException() { @Test public void - handle_PutWithoutConditionGivenAndWTEWithSimpleThrown_ShouldThrowProperExecutionException() { + handle_PutWithoutConditionGivenAndWTEWithSimpleThrown_ShouldThrowExecutionException() { // Arrange put = preparePutWithClusteringKey(); spy = prepareSpiedInsertStatementHandler(); @@ -377,12 +375,12 @@ public void handle_WTEWithCasThrown_ShouldThrowProperExecutionException() { // Act Assert assertThatThrownBy(() -> spy.handle(put)) - .isInstanceOf(RetriableExecutionException.class) + .isInstanceOf(ExecutionException.class) .hasCause(toThrow); } @Test - public void handle_DriverExceptionThrown_ShouldThrowProperExecutionException() { + public void handle_DriverExceptionThrown_ShouldThrowExecutionException() { // Arrange put = preparePutWithClusteringKey(); spy = prepareSpiedInsertStatementHandler();