Skip to content

Commit a10354d

Browse files
committed
Fix behavior of group commit with one-phase commit (#2832)
1 parent 6c88afa commit a10354d

File tree

3 files changed

+130
-49
lines changed

3 files changed

+130
-49
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ public void commit(Snapshot snapshot, boolean readOnly)
5757
super.commit(snapshot, readOnly);
5858
}
5959

60+
@Override
61+
boolean canOnePhaseCommit(Snapshot snapshot) throws CommitException {
62+
try {
63+
return super.canOnePhaseCommit(snapshot);
64+
} catch (CommitException e) {
65+
cancelGroupCommitIfNeeded(snapshot.getId());
66+
throw e;
67+
}
68+
}
69+
70+
@Override
71+
void onePhaseCommitRecords(Snapshot snapshot)
72+
throws CommitConflictException, UnknownTransactionStatusException {
73+
cancelGroupCommitIfNeeded(snapshot.getId());
74+
super.onePhaseCommitRecords(snapshot);
75+
}
76+
6077
@Override
6178
protected void onFailureBeforeCommit(Snapshot snapshot) {
6279
cancelGroupCommitIfNeeded(snapshot.getId());

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ protected CommitHandler createCommitHandler(boolean coordinatorWriteOmissionOnRe
9090
false);
9191
}
9292

93+
protected CommitHandler createCommitHandlerWithOnePhaseCommit() {
94+
return new CommitHandler(
95+
storage, coordinator, tableMetadataManager, parallelExecutor, mutationsGrouper, true, true);
96+
}
97+
9398
@BeforeEach
9499
void setUp() throws Exception {
95100
MockitoAnnotations.openMocks(this).close();
@@ -1068,8 +1073,9 @@ public void canOnePhaseCommit_WhenMutationsCannotBeGrouped_ShouldReturnFalse() t
10681073
}
10691074

10701075
@Test
1071-
public void canOnePhaseCommit_WhenMutationsGrouperThrowsException_ShouldThrowCommitException()
1072-
throws ExecutionException {
1076+
public void
1077+
canOnePhaseCommit_WhenMutationsGrouperThrowsExecutionException_ShouldThrowCommitException()
1078+
throws ExecutionException {
10731079
// Arrange
10741080
CommitHandler handler = createCommitHandlerWithOnePhaseCommit();
10751081
Snapshot snapshot = prepareSnapshot();
@@ -1180,11 +1186,6 @@ public void commit_OnePhaseCommitted_ShouldNotThrowAnyException()
11801186
verify(handler).onFailureBeforeCommit(snapshot);
11811187
}
11821188

1183-
private CommitHandler createCommitHandlerWithOnePhaseCommit() {
1184-
return new CommitHandler(
1185-
storage, coordinator, tableMetadataManager, parallelExecutor, mutationsGrouper, true, true);
1186-
}
1187-
11881189
protected void doThrowExceptionWhenCoordinatorPutState(
11891190
TransactionState targetState, Class<? extends Exception> exceptionClass)
11901191
throws CoordinatorException {

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

Lines changed: 105 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515

1616
import com.scalar.db.api.TransactionState;
1717
import com.scalar.db.exception.storage.ExecutionException;
18+
import com.scalar.db.exception.transaction.CommitConflictException;
1819
import com.scalar.db.exception.transaction.CommitException;
1920
import com.scalar.db.exception.transaction.UnknownTransactionStatusException;
2021
import com.scalar.db.exception.transaction.ValidationConflictException;
2122
import com.scalar.db.transaction.consensuscommit.CoordinatorGroupCommitter.CoordinatorGroupCommitKeyManipulator;
2223
import com.scalar.db.util.groupcommit.GroupCommitConfig;
2324
import java.util.List;
2425
import java.util.UUID;
25-
import org.junit.jupiter.api.Disabled;
2626
import org.junit.jupiter.api.Test;
2727
import org.junit.jupiter.params.ParameterizedTest;
2828
import org.junit.jupiter.params.provider.ValueSource;
@@ -75,6 +75,20 @@ protected CommitHandler createCommitHandler(boolean coordinatorWriteOmissionOnRe
7575
groupCommitter);
7676
}
7777

78+
@Override
79+
protected CommitHandler createCommitHandlerWithOnePhaseCommit() {
80+
createGroupCommitterIfNotExists();
81+
return new CommitHandlerWithGroupCommit(
82+
storage,
83+
coordinator,
84+
tableMetadataManager,
85+
parallelExecutor,
86+
mutationsGrouper,
87+
true,
88+
true,
89+
groupCommitter);
90+
}
91+
7892
private String anyGroupCommitParentId() {
7993
return parentKey;
8094
}
@@ -199,72 +213,121 @@ public void commit_NoReadsInSnapshot_ShouldNotValidateRecords(boolean withSnapsh
199213
verify(groupCommitter, never()).remove(anyId());
200214
}
201215

202-
@Disabled("Enabling both one-phase commit and group commit is not supported")
203-
@Override
204216
@Test
205-
public void canOnePhaseCommit_WhenOnePhaseCommitDisabled_ShouldReturnFalse() {}
206-
207-
@Disabled("Enabling both one-phase commit and group commit is not supported")
208217
@Override
209-
@Test
210-
public void canOnePhaseCommit_WhenValidationRequired_ShouldReturnFalse() {}
218+
public void onePhaseCommitRecords_WhenSuccessful_ShouldMutateUsingComposerMutations()
219+
throws CommitConflictException, UnknownTransactionStatusException, ExecutionException {
220+
super.onePhaseCommitRecords_WhenSuccessful_ShouldMutateUsingComposerMutations();
211221

212-
@Disabled("Enabling both one-phase commit and group commit is not supported")
213-
@Override
214-
@Test
215-
public void canOnePhaseCommit_WhenNoWritesAndDeletes_ShouldReturnFalse() {}
222+
// Assert
223+
verify(groupCommitter).remove(anyId());
224+
}
216225

217-
@Disabled("Enabling both one-phase commit and group commit is not supported")
218-
@Override
219226
@Test
220-
public void canOnePhaseCommit_WhenDeleteWithoutExistingRecord_ShouldReturnFalse() {}
221-
222-
@Disabled("Enabling both one-phase commit and group commit is not supported")
223227
@Override
224-
@Test
225-
public void canOnePhaseCommit_WhenMutationsCanBeGrouped_ShouldReturnTrue() {}
228+
public void
229+
onePhaseCommitRecords_WhenNoMutationExceptionThrown_ShouldThrowCommitConflictException()
230+
throws ExecutionException {
231+
super.onePhaseCommitRecords_WhenNoMutationExceptionThrown_ShouldThrowCommitConflictException();
226232

227-
@Disabled("Enabling both one-phase commit and group commit is not supported")
228-
@Override
229-
@Test
230-
public void canOnePhaseCommit_WhenMutationsCannotBeGrouped_ShouldReturnFalse() {}
233+
// Assert
234+
verify(groupCommitter).remove(anyId());
235+
}
231236

232-
@Disabled("Enabling both one-phase commit and group commit is not supported")
233-
@Override
234237
@Test
235-
public void canOnePhaseCommit_WhenMutationsGrouperThrowsException_ShouldThrowCommitException() {}
238+
@Override
239+
public void
240+
onePhaseCommitRecords_WhenRetriableExecutionExceptionThrown_ShouldThrowCommitConflictException()
241+
throws ExecutionException {
242+
super
243+
.onePhaseCommitRecords_WhenRetriableExecutionExceptionThrown_ShouldThrowCommitConflictException();
236244

237-
@Disabled("Enabling both one-phase commit and group commit is not supported")
245+
// Assert
246+
verify(groupCommitter).remove(anyId());
247+
}
248+
249+
@Test
238250
@Override
251+
public void
252+
onePhaseCommitRecords_WhenExecutionExceptionThrown_ShouldThrowUnknownTransactionStatusException()
253+
throws ExecutionException {
254+
super
255+
.onePhaseCommitRecords_WhenExecutionExceptionThrown_ShouldThrowUnknownTransactionStatusException();
256+
257+
// Assert
258+
verify(groupCommitter).remove(anyId());
259+
}
260+
239261
@Test
240-
public void onePhaseCommitRecords_WhenSuccessful_ShouldMutateUsingComposerMutations() {}
262+
@Override
263+
public void canOnePhaseCommit_WhenOnePhaseCommitDisabled_ShouldReturnFalse() throws Exception {
264+
super.canOnePhaseCommit_WhenOnePhaseCommitDisabled_ShouldReturnFalse();
265+
groupCommitter.remove(anyId());
266+
}
241267

242-
@Disabled("Enabling both one-phase commit and group commit is not supported")
268+
@Test
243269
@Override
270+
public void canOnePhaseCommit_WhenValidationRequired_ShouldReturnFalse() throws Exception {
271+
super.canOnePhaseCommit_WhenValidationRequired_ShouldReturnFalse();
272+
groupCommitter.remove(anyId());
273+
}
274+
244275
@Test
245-
public void
246-
onePhaseCommitRecords_WhenNoMutationExceptionThrown_ShouldThrowCommitConflictException() {}
276+
@Override
277+
public void canOnePhaseCommit_WhenNoWritesAndDeletes_ShouldReturnFalse() throws Exception {
278+
super.canOnePhaseCommit_WhenNoWritesAndDeletes_ShouldReturnFalse();
279+
groupCommitter.remove(anyId());
280+
}
247281

248-
@Disabled("Enabling both one-phase commit and group commit is not supported")
282+
@Test
249283
@Override
284+
public void canOnePhaseCommit_WhenDeleteWithoutExistingRecord_ShouldReturnFalse()
285+
throws Exception {
286+
super.canOnePhaseCommit_WhenDeleteWithoutExistingRecord_ShouldReturnFalse();
287+
groupCommitter.remove(anyId());
288+
}
289+
250290
@Test
251-
public void
252-
onePhaseCommitRecords_WhenRetriableExecutionExceptionThrown_ShouldThrowCommitConflictException() {}
291+
@Override
292+
public void canOnePhaseCommit_WhenMutationsCanBeGrouped_ShouldReturnTrue() throws Exception {
293+
super.canOnePhaseCommit_WhenMutationsCanBeGrouped_ShouldReturnTrue();
294+
groupCommitter.remove(anyId());
295+
}
253296

254-
@Disabled("Enabling both one-phase commit and group commit is not supported")
297+
@Test
255298
@Override
299+
public void canOnePhaseCommit_WhenMutationsCannotBeGrouped_ShouldReturnFalse() throws Exception {
300+
super.canOnePhaseCommit_WhenMutationsCannotBeGrouped_ShouldReturnFalse();
301+
groupCommitter.remove(anyId());
302+
}
303+
256304
@Test
305+
@Override
257306
public void
258-
onePhaseCommitRecords_WhenExecutionExceptionThrown_ShouldThrowUnknownTransactionStatusException() {}
307+
canOnePhaseCommit_WhenMutationsGrouperThrowsExecutionException_ShouldThrowCommitException()
308+
throws ExecutionException {
309+
super
310+
.canOnePhaseCommit_WhenMutationsGrouperThrowsExecutionException_ShouldThrowCommitException();
259311

260-
@Disabled("Enabling both one-phase commit and group commit is not supported")
261-
@Override
262-
@Test
263-
public void commit_OnePhaseCommitted_ShouldNotThrowAnyException() {}
312+
// Assert
313+
verify(groupCommitter).remove(anyId());
314+
}
264315

265-
@Disabled("Enabling both one-phase commit and group commit is not supported")
316+
@Test
266317
@Override
318+
public void commit_OnePhaseCommitted_ShouldNotThrowAnyException()
319+
throws CommitException, UnknownTransactionStatusException {
320+
super.commit_OnePhaseCommitted_ShouldNotThrowAnyException();
321+
groupCommitter.remove(anyId());
322+
}
323+
267324
@Test
325+
@Override
268326
public void
269-
commit_OnePhaseCommitted_UnknownTransactionStatusExceptionThrown_ShouldThrowUnknownTransactionStatusException() {}
327+
commit_OnePhaseCommitted_UnknownTransactionStatusExceptionThrown_ShouldThrowUnknownTransactionStatusException()
328+
throws CommitException, UnknownTransactionStatusException {
329+
super
330+
.commit_OnePhaseCommitted_UnknownTransactionStatusExceptionThrown_ShouldThrowUnknownTransactionStatusException();
331+
groupCommitter.remove(anyId());
332+
}
270333
}

0 commit comments

Comments
 (0)