hangc0276 commented on code in PR #4843:
URL: https://github.com/apache/bookkeeper/pull/4843#discussion_r4758647602


##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java:
##########
@@ -807,6 +807,10 @@ public void checkpoint(Checkpoint checkpoint) throws 
IOException {
 
         try {
             if (writeCache.isEmpty()) {
+                // Ledger metadata updates can be journaled without any 
pending entry data.
+                // Persist them before allowing the journal checkpoint mark to 
advance.
+                flushLedgerIndex();
+                lastCheckpoint = thisCheckpoint;
                 return;

Review Comment:
   Nit (test gap): deleting `lastCheckpoint = thisCheckpoint;` still passes 
both new tests, so this line is untested. Also, `flushLedgerIndex()` records 
the flush-ledger-index success event on every idle checkpoint (from reading the 
code, not measured), so that stat now ticks at near-zero latency when nothing 
is pending. `LedgerMetadataIndex.flush()` itself returns immediately when 
nothing is pending, so there is no extra I/O.
   
   Related suggestion: a test with only `setMasterKey` and no entries (flush, 
restart, `ledgerExists`) passes on this PR and fails on the merge-base code, so 
the fix covers it. It would be a cheap third regression test.



##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java:
##########
@@ -807,6 +807,10 @@ public void checkpoint(Checkpoint checkpoint) throws 
IOException {
 
         try {
             if (writeCache.isEmpty()) {
+                // Ledger metadata updates can be journaled without any 
pending entry data.
+                // Persist them before allowing the journal checkpoint mark to 
advance.
+                flushLedgerIndex();
+                lastCheckpoint = thisCheckpoint;

Review Comment:
   **Reproduced (pre-existing, but in this branch): after a failed flush, an 
empty-cache checkpoint is treated as clean.**
   
   This branch only checks `writeCache`. If a previous flush swapped the caches 
and then failed (for example `entryLogger.flush()` throws), the entries stay in 
`writeCacheBeingFlushed` while `writeCache` is empty. A retry `flush()` with no 
new writes then flushes the metadata index, sets `lastCheckpoint`, and returns 
normally. The caller runs `checkpointComplete`, so the journal mark advances 
while the entries exist only in memory.
   
   Proof (uncommitted test in `DbLedgerStorageTest`, with a Mockito spy on 
`entryLogger` that throws once from `flush()`):
   - `testAdvRetryAfterFailedFlushStillPersistsEntries` fails with `entries 
stranded in writeCacheBeingFlushed were never retried expected:<2> but was:<1>` 
(counting `entryLogger.addEntry` calls).
   - The control `testAdvControlSuccessfulFlushWritesEntryOnce` passes.
   - The same test also fails on the merge-base code, so this PR did not 
introduce it. It touches the same branch and now also moves `lastCheckpoint` 
forward here.
   
   I did not crash and replay the bookie. The data loss is inferred from 
`checkpointComplete` following a normal return. This is the same scenario as 
Copilot's first comment.
   
   Suggested fix: gate the early return on both caches, e.g. 
`writeCache.isEmpty() && writeCacheBeingFlushed.isEmpty()`, so the normal flush 
path retries the stranded entries.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to