@@ -270,30 +270,33 @@ public class AsyncThread extends Thread { |
270 | 270 | // that closes the batch) can still tell every one of them onError instead of only the executor-wide |
271 | 271 | // callback. Thread-confined: only this worker touches it. Idempotent queries are never buffered - |
272 | 272 | // they wrote nothing, so there is nothing for a rollback to lose. |
273 | | - private final List<DatabaseAsyncCommand> pendingBatchCommands = new ArrayList<>(); |
274 | | - // #7615: true once some OTHER mutating task type (DatabaseAsyncCreateRecord/UpdateRecord/DeleteRecord, |
275 | | - // the graph edge-creation tasks, ...) has run against the shared batch since it was last committed. |
276 | | - // commitBatch() cannot replay those - only pendingBatchCommands is buffered - so replaying the batch |
277 | | - // after a rolled-back commit would silently omit their writes while still reporting success. Gates |
278 | | - // commitBatch()'s retry: set, a CME abandons immediately instead of attempting a replay that would |
279 | | - // fabricate a clean commit over data it actually dropped. |
280 | | - private boolean batchHasUnreplayableWrites = false; |
| 273 | + private final List<DatabaseAsyncCommand> pendingBatchCommands = new ArrayList<>(); |
| 274 | + // #7615: tasks of some OTHER mutating type (DatabaseAsyncCreateRecord/UpdateRecord/DeleteRecord, the |
| 275 | + // graph edge-creation tasks, ...) that ran against the shared batch and left it active since it was |
| 276 | + // last committed. commitBatch() cannot replay those - only pendingBatchCommands is buffered - so |
| 277 | + // replaying the batch after a rolled-back commit would silently omit their writes while still |
| 278 | + // reporting success. Non-empty gates commitBatch()'s retry off (a CME abandons immediately instead of |
| 279 | + // attempting a replay that would fabricate a clean commit over data it actually dropped), and on |
| 280 | + // abandonment each one's own notifyBatchAbandoned(Throwable) is called - a no-op for a task with no |
| 281 | + // per-task error callback (the edge tasks), otherwise the same "you were told success, this corrects |
| 282 | + // it" notification pendingBatchCommands' own commands get. |
| 283 | + private final List<DatabaseAsyncTask> pendingUnreplayableTasks = new ArrayList<>(); |
281 | 284 | // #7615: true only while commitBatch() is replaying pendingBatchCommands after a rolled-back |
282 | 285 | // commit. DatabaseAsyncCommand checks this to avoid re-invoking its userCallback.onComplete() (already |
283 | 286 | // fired on the first, now-discarded attempt) and to let a failure during replay propagate to |
284 | 287 | // commitBatch() instead of being handled - and the whole batch silently rolled back - locally. |
285 | | - private volatile boolean replayingBatch = false; |
| 288 | + private volatile boolean replayingBatch = false; |
286 | 289 | // Monotonic call counter feeding TEST_BEFORE_BATCH_COMMIT_HOOK's 1-based argument. Thread-confined, |
287 | 290 | // same as pendingBatchCommands - only this worker ever calls commitBatch() on itself. |
288 | | - private int batchCommitAttempt = 0; |
| 291 | + private int batchCommitAttempt = 0; |
289 | 292 |
|
290 | 293 | // #7615: single choke point for "the shared batch's non-durable bookkeeping is now moot" - every site |
291 | 294 | // that commits, rolls back, or otherwise closes the shared batch transaction goes through here instead |
292 | | - // of clearing pendingBatchCommands directly, so batchHasUnreplayableWrites can never drift out of sync |
293 | | - // with it. |
| 295 | + // of clearing pendingBatchCommands/pendingUnreplayableTasks directly, so the two can never drift out |
| 296 | + // of sync with each other. |
294 | 297 | private void clearBatchState() { |
295 | 298 | pendingBatchCommands.clear(); |
296 | | - batchHasUnreplayableWrites = false; |
| 299 | + pendingUnreplayableTasks.clear(); |
297 | 300 | } |
298 | 301 |
|
299 | 302 | boolean isReplayingBatch() { |
@@ -507,8 +510,8 @@ else if (message instanceof final DatabaseAsyncCommand command) { |
507 | 510 | // Some other mutating task type ran against the shared batch and left it active, i.e. it |
508 | 511 | // succeeded - DatabaseAsyncCreateRecord/UpdateRecord/DeleteRecord, the graph edge-creation |
509 | 512 | // tasks, ... commitBatch() only knows how to replay pendingBatchCommands, so it must not |
510 | | - // attempt to on a batch holding a write it cannot reconstruct (see batchHasUnreplayableWrites). |
511 | | - batchHasUnreplayableWrites = true; |
| 513 | + // attempt to on a batch holding a write it cannot reconstruct (see pendingUnreplayableTasks). |
| 514 | + pendingUnreplayableTasks.add(message); |
512 | 515 |
|
513 | 516 | count++; |
514 | 517 |
|
@@ -608,7 +611,7 @@ void commitBatch(final boolean currentUseWAL, final WALFile.FlushType currentSyn |
608 | 611 | lastFailure = e; |
609 | 612 | if (database.isTransactionActive()) |
610 | 613 | database.rollback(); |
611 | | - if (batchHasUnreplayableWrites) |
| 614 | + if (!pendingUnreplayableTasks.isEmpty()) |
612 | 615 | // A replay can only reconstruct pendingBatchCommands - committing one over a batch that also |
613 | 616 | // held a write it cannot reconstruct would silently omit that write while still reporting |
614 | 617 | // success. No safe retry available: stop here and fall through to the abandon path below, |
@@ -634,25 +637,24 @@ void commitBatch(final boolean currentUseWAL, final WALFile.FlushType currentSyn |
634 | 637 | } |
635 | 638 |
|
636 | 639 | /** |
637 | | - * Calls {@code onError} on every command still buffered in {@link #pendingBatchCommands} - the batch |
638 | | - * is being abandoned, so none of them will be replayed - and clears the buffer. Called wherever the |
639 | | - * worker's shared batch transaction is given up on instead of committed (issue #7615): a |
| 640 | + * Calls {@code onError} on every command still buffered in {@link #pendingBatchCommands}, and |
| 641 | + * {@link DatabaseAsyncTask#notifyBatchAbandoned} on every task in {@link #pendingUnreplayableTasks} - |
| 642 | + * the batch is being abandoned, so none of them will be replayed - then clears both. Called wherever |
| 643 | + * the worker's shared batch transaction is given up on instead of committed (issue #7615): a |
640 | 644 | * {@link #commitBatch} whose retries are exhausted, and the other commit sites that close this same |
641 | 645 | * shared transaction ({@link #closeTransactionBoundaryIfDurabilityPolicyChanged}, the shutdown commit |
642 | 646 | * in {@link #runLoop}, and the dangling-batch commit in {@link DatabaseAsyncTransaction#executeTransaction}). |
643 | 647 | */ |
644 | 648 | void notifyPendingBatchCommandsAndAbandon(final Throwable cause) { |
645 | | - if (pendingBatchCommands.isEmpty()) { |
646 | | - // #7615: still reset - a batch can be unreplayable (batchHasUnreplayableWrites) with nothing |
647 | | - // buffered at all (e.g. a lone DatabaseAsyncCreateRecord), and that flag must not outlive the |
648 | | - // batch it described or every later batch on this worker would be wrongly denied a replay too. |
649 | | - batchHasUnreplayableWrites = false; |
| 649 | + if (pendingBatchCommands.isEmpty() && pendingUnreplayableTasks.isEmpty()) |
650 | 650 | return; |
651 | | - } |
652 | | - final List<DatabaseAsyncCommand> abandoned = new ArrayList<>(pendingBatchCommands); |
| 651 | + final List<DatabaseAsyncCommand> abandonedCommands = new ArrayList<>(pendingBatchCommands); |
| 652 | + final List<DatabaseAsyncTask> abandonedTasks = new ArrayList<>(pendingUnreplayableTasks); |
653 | 653 | clearBatchState(); |
654 | | - for (final DatabaseAsyncCommand command : abandoned) |
| 654 | + for (final DatabaseAsyncCommand command : abandonedCommands) |
655 | 655 | command.notifyError(cause); |
| 656 | + for (final DatabaseAsyncTask task : abandonedTasks) |
| 657 | + task.notifyBatchAbandoned(cause); |
656 | 658 | } |
657 | 659 |
|
658 | 660 | /** |
|