This is an automated email from the ASF dual-hosted git repository.

ayegorov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 15a5b49c43 SingleDirectoryDbLedgerStorage skip optimistic cache put 
sometimes (#4306)
15a5b49c43 is described below

commit 15a5b49c4334598e983188e618b626aaea780bd8
Author: Michael Marshall <[email protected]>
AuthorDate: Thu May 30 19:58:46 2024 -0500

    SingleDirectoryDbLedgerStorage skip optimistic cache put sometimes (#4306)
    
    * SingleDirectoryDbLedgerStorage skip optimistic cache put
    
    When tryOptimisticRead returns 0, the lock is acquired
    by another thread and we will fail the validation step.
    We can therefore skip the eager cache insertion.
---
 .../bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java        | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java
 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java
index 884bb1a337..6ce2d4b4f5 100644
--- 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java
+++ 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java
@@ -484,8 +484,12 @@ public class SingleDirectoryDbLedgerStorage implements 
CompactableLedgerStorage
         long stamp = writeCacheRotationLock.tryOptimisticRead();
         boolean inserted = false;
 
-        inserted = writeCache.put(ledgerId, entryId, entry);
-        if (!writeCacheRotationLock.validate(stamp)) {
+        // If the stamp is 0, the lock was exclusively acquired, validation 
will fail, and we can skip this put.
+        if (stamp != 0) {
+            inserted = writeCache.put(ledgerId, entryId, entry);
+        }
+
+        if (stamp == 0 || !writeCacheRotationLock.validate(stamp)) {
             // The write cache was rotated while we were inserting. We need to 
acquire the proper read lock and repeat
             // the operation because we might have inserted in a write cache 
that was already being flushed and cleared,
             // without being sure about this last entry being flushed or not.

Reply via email to