Skip to content

Commit 7a01959

Browse files
authored
Fix error handling for one-phase commit (#2826)
1 parent 9b9c4fe commit 7a01959

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

core/src/main/java/com/scalar/db/transaction/consensuscommit/CommitHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ protected void handleCommitConflict(Snapshot snapshot, Exception cause)
261261
}
262262

263263
@VisibleForTesting
264-
void onePhaseCommitRecords(Snapshot snapshot) throws CommitException {
264+
void onePhaseCommitRecords(Snapshot snapshot)
265+
throws CommitConflictException, UnknownTransactionStatusException {
265266
try {
266267
OnePhaseCommitMutationComposer composer =
267268
new OnePhaseCommitMutationComposer(snapshot.getId(), tableMetadataManager);
@@ -279,7 +280,7 @@ void onePhaseCommitRecords(Snapshot snapshot) throws CommitException {
279280
e,
280281
snapshot.getId());
281282
} catch (ExecutionException e) {
282-
throw new CommitException(
283+
throw new UnknownTransactionStatusException(
283284
CoreError.CONSENSUS_COMMIT_COMMITTING_RECORDS_FAILED.buildMessage(), e, snapshot.getId());
284285
}
285286
}

core/src/test/java/com/scalar/db/transaction/consensuscommit/CommitHandlerTest.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ public void canOnePhaseCommit_WhenMutationsGrouperThrowsException_ShouldThrowCom
10891089

10901090
@Test
10911091
public void onePhaseCommitRecords_WhenSuccessful_ShouldMutateUsingComposerMutations()
1092-
throws CommitException, ExecutionException {
1092+
throws CommitConflictException, UnknownTransactionStatusException, ExecutionException {
10931093
// Arrange
10941094
Snapshot snapshot = spy(prepareSnapshotWithSamePartitionPut());
10951095
doNothing().when(storage).mutate(anyList());
@@ -1131,15 +1131,16 @@ public void onePhaseCommitRecords_WhenSuccessful_ShouldMutateUsingComposerMutati
11311131
}
11321132

11331133
@Test
1134-
public void onePhaseCommitRecords_WhenExecutionExceptionThrown_ShouldThrowCommitException()
1135-
throws ExecutionException {
1134+
public void
1135+
onePhaseCommitRecords_WhenExecutionExceptionThrown_ShouldThrowUnknownTransactionStatusException()
1136+
throws ExecutionException {
11361137
// Arrange
11371138
Snapshot snapshot = prepareSnapshotWithSamePartitionPut();
11381139
doThrow(ExecutionException.class).when(storage).mutate(anyList());
11391140

11401141
// Act Assert
11411142
assertThatThrownBy(() -> handler.onePhaseCommitRecords(snapshot))
1142-
.isInstanceOf(CommitException.class)
1143+
.isInstanceOf(UnknownTransactionStatusException.class)
11431144
.hasCauseInstanceOf(ExecutionException.class);
11441145
}
11451146

@@ -1162,17 +1163,19 @@ public void commit_OnePhaseCommitted_ShouldNotThrowAnyException()
11621163
}
11631164

11641165
@Test
1165-
public void commit_OnePhaseCommitted_CommitExceptionThrown_ShouldThrowCommitException()
1166-
throws CommitException {
1166+
public void
1167+
commit_OnePhaseCommitted_UnknownTransactionStatusExceptionThrown_ShouldThrowUnknownTransactionStatusException()
1168+
throws CommitException, UnknownTransactionStatusException {
11671169
// Arrange
11681170
CommitHandler handler = spy(createCommitHandlerWithOnePhaseCommit());
11691171
Snapshot snapshot = prepareSnapshotWithSamePartitionPut();
11701172

11711173
doReturn(true).when(handler).canOnePhaseCommit(snapshot);
1172-
doThrow(CommitException.class).when(handler).onePhaseCommitRecords(snapshot);
1174+
doThrow(UnknownTransactionStatusException.class).when(handler).onePhaseCommitRecords(snapshot);
11731175

11741176
// Act Assert
1175-
assertThatThrownBy(() -> handler.commit(snapshot, true)).isInstanceOf(CommitException.class);
1177+
assertThatThrownBy(() -> handler.commit(snapshot, true))
1178+
.isInstanceOf(UnknownTransactionStatusException.class);
11761179

11771180
verify(handler).onFailureBeforeCommit(snapshot);
11781181
}

core/src/test/java/com/scalar/db/transaction/consensuscommit/CommitHandlerWithGroupCommitTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ public void onePhaseCommitRecords_WhenSuccessful_ShouldMutateUsingComposerMutati
254254
@Disabled("Enabling both one-phase commit and group commit is not supported")
255255
@Override
256256
@Test
257-
public void onePhaseCommitRecords_WhenExecutionExceptionThrown_ShouldThrowCommitException() {}
257+
public void
258+
onePhaseCommitRecords_WhenExecutionExceptionThrown_ShouldThrowUnknownTransactionStatusException() {}
258259

259260
@Disabled("Enabling both one-phase commit and group commit is not supported")
260261
@Override
@@ -264,5 +265,6 @@ public void commit_OnePhaseCommitted_ShouldNotThrowAnyException() {}
264265
@Disabled("Enabling both one-phase commit and group commit is not supported")
265266
@Override
266267
@Test
267-
public void commit_OnePhaseCommitted_CommitExceptionThrown_ShouldThrowCommitException() {}
268+
public void
269+
commit_OnePhaseCommitted_UnknownTransactionStatusExceptionThrown_ShouldThrowUnknownTransactionStatusException() {}
268270
}

0 commit comments

Comments
 (0)