Skip to content

Commit 6ccaeec

Browse files
authored
Rename methods of CommitHandler (#2785)
1 parent 2dc4608 commit 6ccaeec

File tree

7 files changed

+51
-56
lines changed

7 files changed

+51
-56
lines changed

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

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void commit(Snapshot snapshot, boolean readOnly)
117117

118118
if (hasWritesOrDeletesInSnapshot) {
119119
try {
120-
prepare(snapshot);
120+
prepareRecords(snapshot);
121121
} catch (PreparationException e) {
122122
safelyCallOnFailureBeforeCommit(snapshot);
123123
abortState(snapshot.getId());
@@ -134,7 +134,7 @@ public void commit(Snapshot snapshot, boolean readOnly)
134134

135135
if (snapshot.hasReads()) {
136136
try {
137-
validate(snapshot);
137+
validateRecords(snapshot);
138138
} catch (ValidationException e) {
139139
safelyCallOnFailureBeforeCommit(snapshot);
140140

@@ -194,9 +194,19 @@ protected void handleCommitConflict(Snapshot snapshot, Exception cause)
194194
}
195195
}
196196

197-
public void prepare(Snapshot snapshot) throws PreparationException {
197+
public void prepareRecords(Snapshot snapshot) throws PreparationException {
198198
try {
199-
prepareRecords(snapshot);
199+
PrepareMutationComposer composer =
200+
new PrepareMutationComposer(snapshot.getId(), tableMetadataManager);
201+
snapshot.to(composer);
202+
PartitionedMutations mutations = new PartitionedMutations(composer.get());
203+
204+
ImmutableList<PartitionedMutations.Key> orderedKeys = mutations.getOrderedKeys();
205+
List<ParallelExecutorTask> tasks = new ArrayList<>(orderedKeys.size());
206+
for (PartitionedMutations.Key key : orderedKeys) {
207+
tasks.add(() -> storage.mutate(mutations.get(key)));
208+
}
209+
parallelExecutor.prepareRecords(tasks, snapshot.getId());
200210
} catch (NoMutationException e) {
201211
throw new PreparationConflictException(
202212
CoreError.CONSENSUS_COMMIT_PREPARING_RECORD_EXISTS.buildMessage(), e, snapshot.getId());
@@ -211,22 +221,7 @@ public void prepare(Snapshot snapshot) throws PreparationException {
211221
}
212222
}
213223

214-
private void prepareRecords(Snapshot snapshot)
215-
throws ExecutionException, PreparationConflictException {
216-
PrepareMutationComposer composer =
217-
new PrepareMutationComposer(snapshot.getId(), tableMetadataManager);
218-
snapshot.to(composer);
219-
PartitionedMutations mutations = new PartitionedMutations(composer.get());
220-
221-
ImmutableList<PartitionedMutations.Key> orderedKeys = mutations.getOrderedKeys();
222-
List<ParallelExecutorTask> tasks = new ArrayList<>(orderedKeys.size());
223-
for (PartitionedMutations.Key key : orderedKeys) {
224-
tasks.add(() -> storage.mutate(mutations.get(key)));
225-
}
226-
parallelExecutor.prepare(tasks, snapshot.getId());
227-
}
228-
229-
public void validate(Snapshot snapshot) throws ValidationException {
224+
public void validateRecords(Snapshot snapshot) throws ValidationException {
230225
try {
231226
// validation is executed when SERIALIZABLE is chosen.
232227
snapshot.toSerializable(storage);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public ParallelExecutor(ConsensusCommitConfig config) {
6060
this.parallelExecutorService = parallelExecutorService;
6161
}
6262

63-
public void prepare(List<ParallelExecutorTask> tasks, String transactionId)
63+
public void prepareRecords(List<ParallelExecutorTask> tasks, String transactionId)
6464
throws ExecutionException {
6565
try {
6666
// When parallel preparation is disabled, we stop running the tasks when one of them fails
@@ -85,7 +85,7 @@ public void prepare(List<ParallelExecutorTask> tasks, String transactionId)
8585
}
8686
}
8787

88-
public void validate(List<ParallelExecutorTask> tasks, String transactionId)
88+
public void validateRecords(List<ParallelExecutorTask> tasks, String transactionId)
8989
throws ExecutionException, ValidationConflictException {
9090
try {
9191
executeTasks(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ void toSerializable(DistributedStorage storage)
548548
}
549549
}
550550

551-
parallelExecutor.validate(tasks, getId());
551+
parallelExecutor.validateRecords(tasks, getId());
552552
}
553553

554554
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,15 @@ public void prepare() throws PreparationException {
269269
}
270270

271271
try {
272-
commit.prepare(crud.getSnapshot());
272+
commit.prepareRecords(crud.getSnapshot());
273273
} finally {
274274
needRollback = true;
275275
}
276276
}
277277

278278
@Override
279279
public void validate() throws ValidationException {
280-
commit.validate(crud.getSnapshot());
280+
commit.validateRecords(crud.getSnapshot());
281281
validated = true;
282282
}
283283

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ protected void afterEach() throws Exception {
5858
}
5959

6060
@Test
61-
public void prepare_ParallelPreparationNotEnabled_ShouldExecuteTasksSerially()
61+
public void prepareRecords_ParallelPreparationNotEnabled_ShouldExecuteTasksSerially()
6262
throws ExecutionException, ValidationConflictException, CrudException {
6363
// Arrange
6464
when(config.isParallelPreparationEnabled()).thenReturn(false);
6565

6666
// Act
67-
parallelExecutor.prepare(tasks, TX_ID);
67+
parallelExecutor.prepareRecords(tasks, TX_ID);
6868

6969
// Assert
7070
verify(task, times(tasks.size())).run();
@@ -73,36 +73,36 @@ public void prepare_ParallelPreparationNotEnabled_ShouldExecuteTasksSerially()
7373

7474
@Test
7575
public void
76-
prepare_ParallelPreparationNotEnabled_ExecutionExceptionThrownByTask_ShouldStopRunningTasks()
76+
prepareRecords_ParallelPreparationNotEnabled_ExecutionExceptionThrownByTask_ShouldStopRunningTasks()
7777
throws ExecutionException, ValidationConflictException, CrudException {
7878
// Arrange
7979
when(config.isParallelPreparationEnabled()).thenReturn(false);
8080
doThrow(ExecutionException.class).when(task).run();
8181

8282
// Act Assert
83-
assertThatThrownBy(() -> parallelExecutor.prepare(tasks, TX_ID))
83+
assertThatThrownBy(() -> parallelExecutor.prepareRecords(tasks, TX_ID))
8484
.isInstanceOf(ExecutionException.class);
8585

8686
verify(task, only()).run();
8787
verify(parallelExecutorService, never()).execute(any());
8888
}
8989

9090
@Test
91-
public void prepare_ParallelPreparationEnabled_ShouldExecuteTasksInParallel()
91+
public void prepareRecords_ParallelPreparationEnabled_ShouldExecuteTasksInParallel()
9292
throws ExecutionException, ValidationConflictException, CrudException {
9393
// Arrange
9494
when(config.isParallelPreparationEnabled()).thenReturn(true);
9595

9696
// Act
97-
parallelExecutor.prepare(tasks, TX_ID);
97+
parallelExecutor.prepareRecords(tasks, TX_ID);
9898

9999
// Assert
100100
verify(task, times(tasks.size())).run();
101101
verify(parallelExecutorService, times(tasks.size())).execute(any());
102102
}
103103

104104
@Test
105-
public void prepare_ParallelPreparationEnabled_SingleTaskGiven_ShouldExecuteTasksSerially()
105+
public void prepareRecords_ParallelPreparationEnabled_SingleTaskGiven_ShouldExecuteTasksSerially()
106106
throws ExecutionException, ValidationConflictException, CrudException {
107107
// Arrange
108108
when(config.isParallelPreparationEnabled()).thenReturn(true);
@@ -111,7 +111,7 @@ public void prepare_ParallelPreparationEnabled_SingleTaskGiven_ShouldExecuteTask
111111
tasks = Collections.singletonList(task);
112112

113113
// Act
114-
parallelExecutor.prepare(tasks, TX_ID);
114+
parallelExecutor.prepareRecords(tasks, TX_ID);
115115

116116
// Assert
117117
verify(task, times(tasks.size())).run();
@@ -120,28 +120,28 @@ public void prepare_ParallelPreparationEnabled_SingleTaskGiven_ShouldExecuteTask
120120

121121
@Test
122122
public void
123-
prepare_ParallelPreparationEnabled_ExecutionExceptionThrownByTask_ShouldNotStopRunningTasks()
123+
prepareRecords_ParallelPreparationEnabled_ExecutionExceptionThrownByTask_ShouldNotStopRunningTasks()
124124
throws ExecutionException, ValidationConflictException, CrudException {
125125
// Arrange
126126
when(config.isParallelPreparationEnabled()).thenReturn(true);
127127
doThrow(ExecutionException.class).when(task).run();
128128

129129
// Act Assert
130-
assertThatThrownBy(() -> parallelExecutor.prepare(tasks, TX_ID))
130+
assertThatThrownBy(() -> parallelExecutor.prepareRecords(tasks, TX_ID))
131131
.isInstanceOf(ExecutionException.class);
132132

133133
verify(task, times(tasks.size())).run();
134134
verify(parallelExecutorService, times(tasks.size())).execute(any());
135135
}
136136

137137
@Test
138-
public void validate_ParallelValidationNotEnabled_ShouldExecuteTasksSerially()
138+
public void validateRecords_ParallelValidationNotEnabled_ShouldExecuteTasksSerially()
139139
throws ExecutionException, ValidationConflictException, CrudException {
140140
// Arrange
141141
when(config.isParallelValidationEnabled()).thenReturn(false);
142142

143143
// Act
144-
parallelExecutor.validate(tasks, TX_ID);
144+
parallelExecutor.validateRecords(tasks, TX_ID);
145145

146146
// Assert
147147
verify(task, times(tasks.size())).run();
@@ -150,14 +150,14 @@ public void validate_ParallelValidationNotEnabled_ShouldExecuteTasksSerially()
150150

151151
@Test
152152
public void
153-
validate_ParallelValidationNotEnabled_ExecutionExceptionThrownByTask_ShouldStopRunningTasks()
153+
validateRecords_ParallelValidationNotEnabled_ExecutionExceptionThrownByTask_ShouldStopRunningTasks()
154154
throws ExecutionException, ValidationConflictException, CrudException {
155155
// Arrange
156156
when(config.isParallelValidationEnabled()).thenReturn(false);
157157
doThrow(ExecutionException.class).when(task).run();
158158

159159
// Act Assert
160-
assertThatThrownBy(() -> parallelExecutor.validate(tasks, TX_ID))
160+
assertThatThrownBy(() -> parallelExecutor.validateRecords(tasks, TX_ID))
161161
.isInstanceOf(ExecutionException.class);
162162

163163
verify(task, only()).run();
@@ -166,36 +166,36 @@ public void validate_ParallelValidationNotEnabled_ShouldExecuteTasksSerially()
166166

167167
@Test
168168
public void
169-
validate_ParallelValidationNotEnabled_ValidationConflictExceptionThrownByTask_ShouldStopRunningTasks()
169+
validateRecords_ParallelValidationNotEnabled_ValidationConflictExceptionThrownByTask_ShouldStopRunningTasks()
170170
throws ExecutionException, ValidationConflictException, CrudException {
171171
// Arrange
172172
when(config.isParallelValidationEnabled()).thenReturn(false);
173173
doThrow(ValidationConflictException.class).when(task).run();
174174

175175
// Act Assert
176-
assertThatThrownBy(() -> parallelExecutor.validate(tasks, TX_ID))
176+
assertThatThrownBy(() -> parallelExecutor.validateRecords(tasks, TX_ID))
177177
.isInstanceOf(ValidationConflictException.class);
178178

179179
verify(task, only()).run();
180180
verify(parallelExecutorService, never()).execute(any());
181181
}
182182

183183
@Test
184-
public void validate_ParallelValidationEnabled_ShouldExecuteTasksInParallel()
184+
public void validateRecords_ParallelValidationEnabled_ShouldExecuteTasksInParallel()
185185
throws ExecutionException, ValidationConflictException, CrudException {
186186
// Arrange
187187
when(config.isParallelValidationEnabled()).thenReturn(true);
188188

189189
// Act
190-
parallelExecutor.validate(tasks, TX_ID);
190+
parallelExecutor.validateRecords(tasks, TX_ID);
191191

192192
// Assert
193193
verify(task, times(tasks.size())).run();
194194
verify(parallelExecutorService, times(tasks.size())).execute(any());
195195
}
196196

197197
@Test
198-
public void validate_ParallelValidationEnabled_SingleTaskGiven_ShouldExecuteTasksSerially()
198+
public void validateRecords_ParallelValidationEnabled_SingleTaskGiven_ShouldExecuteTasksSerially()
199199
throws ExecutionException, ValidationConflictException, CrudException {
200200
// Arrange
201201
when(config.isParallelValidationEnabled()).thenReturn(true);
@@ -204,7 +204,7 @@ public void validate_ParallelValidationEnabled_SingleTaskGiven_ShouldExecuteTask
204204
tasks = Collections.singletonList(task);
205205

206206
// Act
207-
parallelExecutor.validate(tasks, TX_ID);
207+
parallelExecutor.validateRecords(tasks, TX_ID);
208208

209209
// Assert
210210
verify(task, times(tasks.size())).run();
@@ -213,14 +213,14 @@ public void validate_ParallelValidationEnabled_SingleTaskGiven_ShouldExecuteTask
213213

214214
@Test
215215
public void
216-
validate_ParallelValidationEnabled_ExecutionExceptionThrownByTask_ShouldStopRunningTasks()
216+
validateRecords_ParallelValidationEnabled_ExecutionExceptionThrownByTask_ShouldStopRunningTasks()
217217
throws ExecutionException, ValidationConflictException, CrudException {
218218
// Arrange
219219
when(config.isParallelValidationEnabled()).thenReturn(true);
220220
doThrow(ExecutionException.class).when(task).run();
221221

222222
// Act Assert
223-
assertThatThrownBy(() -> parallelExecutor.validate(tasks, TX_ID))
223+
assertThatThrownBy(() -> parallelExecutor.validateRecords(tasks, TX_ID))
224224
.isInstanceOf(ExecutionException.class);
225225

226226
verify(task, atMost(tasks.size())).run();
@@ -229,14 +229,14 @@ public void validate_ParallelValidationEnabled_SingleTaskGiven_ShouldExecuteTask
229229

230230
@Test
231231
public void
232-
validate_ParallelValidationEnabled_ValidationConflictExceptionThrownByTask_ShouldStopRunningTasks()
232+
validateRecords_ParallelValidationEnabled_ValidationConflictExceptionThrownByTask_ShouldStopRunningTasks()
233233
throws ExecutionException, ValidationConflictException, CrudException {
234234
// Arrange
235235
when(config.isParallelValidationEnabled()).thenReturn(true);
236236
doThrow(ValidationConflictException.class).when(task).run();
237237

238238
// Act Assert
239-
assertThatThrownBy(() -> parallelExecutor.validate(tasks, TX_ID))
239+
assertThatThrownBy(() -> parallelExecutor.validateRecords(tasks, TX_ID))
240240
.isInstanceOf(ValidationConflictException.class);
241241

242242
verify(task, atMost(tasks.size())).run();

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ public void mutate_PutAndDeleteGiven_ShouldCallCrudHandlerPutAndDelete()
706706
}
707707

708708
@Test
709-
public void prepare_ProcessedCrudGiven_ShouldPrepareWithSnapshot()
709+
public void prepare_ProcessedCrudGiven_ShouldPrepareRecordsWithSnapshot()
710710
throws PreparationException, CrudException {
711711
// Arrange
712712
when(crud.getSnapshot()).thenReturn(snapshot);
@@ -716,7 +716,7 @@ public void prepare_ProcessedCrudGiven_ShouldPrepareWithSnapshot()
716716

717717
// Assert
718718
verify(crud).readIfImplicitPreReadEnabled();
719-
verify(commit).prepare(snapshot);
719+
verify(commit).prepareRecords(snapshot);
720720
}
721721

722722
@Test
@@ -775,7 +775,7 @@ public void prepare_ScannerNotClosed_ShouldThrowIllegalStateException() {
775775
}
776776

777777
@Test
778-
public void validate_ProcessedCrudGiven_ShouldPerformValidationWithSnapshot()
778+
public void validate_ProcessedCrudGiven_ShouldValidateRecordsWithSnapshot()
779779
throws ValidationException, PreparationException {
780780
// Arrange
781781
transaction.prepare();
@@ -785,7 +785,7 @@ public void validate_ProcessedCrudGiven_ShouldPerformValidationWithSnapshot()
785785
transaction.validate();
786786

787787
// Assert
788-
verify(commit).validate(snapshot);
788+
verify(commit).validateRecords(snapshot);
789789
}
790790

791791
@Test
@@ -855,7 +855,7 @@ public void rollback_CalledAfterPrepareFails_ShouldAbortStateAndRollbackRecords(
855855
throws TransactionException {
856856
// Arrange
857857
when(crud.getSnapshot()).thenReturn(snapshot);
858-
doThrow(PreparationException.class).when(commit).prepare(snapshot);
858+
doThrow(PreparationException.class).when(commit).prepareRecords(snapshot);
859859

860860
// Act
861861
assertThatThrownBy(transaction::prepare).isInstanceOf(PreparationException.class);

integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitSpecificIntegrationTestBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3123,7 +3123,7 @@ void put_WhenTheOtherTransactionsIsDelayed_ShouldBeCommittedWithoutBlocked() thr
31233123
@EnabledIf("isGroupCommitEnabled")
31243124
void put_WhenTheOtherTransactionsFails_ShouldBeCommittedWithoutBlocked() throws Exception {
31253125
// Arrange
3126-
doThrow(PreparationConflictException.class).when(commit).prepare(any());
3126+
doThrow(PreparationConflictException.class).when(commit).prepareRecords(any());
31273127

31283128
// Act
31293129
DistributedTransaction failingTxn = manager.begin();
@@ -3203,7 +3203,7 @@ void put_WhenAllTransactionsAbort_ShouldBeAbortedProperly() throws Exception {
32033203
DistributedTransaction failingTxn1 = manager.begin(Isolation.SERIALIZABLE);
32043204
DistributedTransaction failingTxn2 = manager.begin(Isolation.SERIALIZABLE);
32053205

3206-
doThrow(PreparationConflictException.class).when(commit).prepare(any());
3206+
doThrow(PreparationConflictException.class).when(commit).prepareRecords(any());
32073207

32083208
failingTxn1.put(preparePut(0, 0, namespace1, TABLE_1));
32093209
failingTxn2.put(preparePut(1, 0, namespace1, TABLE_1));

0 commit comments

Comments
 (0)