bookkeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From si...@apache.org
Subject bookkeeper git commit: BOOKKEEPER-957: LedgerHandleAdv fixes
Date Wed, 09 Nov 2016 07:45:00 GMT
Repository: bookkeeper
Updated Branches:
  refs/heads/master cc3d27016 -> 8f0bed9f8


BOOKKEEPER-957: LedgerHandleAdv fixes

- making addToLength call synchronized
- adding op to pendingAddOps after doing sanity check

Author: Charan Reddy Guttapalem <cguttapalem@salesforce.com>

Reviewers: Sijie Guo <sijie@apache.org>

Closes #65 from reddycharan/ledgerhandleadvfix


Project: http://git-wip-us.apache.org/repos/asf/bookkeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/bookkeeper/commit/8f0bed9f
Tree: http://git-wip-us.apache.org/repos/asf/bookkeeper/tree/8f0bed9f
Diff: http://git-wip-us.apache.org/repos/asf/bookkeeper/diff/8f0bed9f

Branch: refs/heads/master
Commit: 8f0bed9f8401001abd683c420757610996cf96d8
Parents: cc3d270
Author: Charan Reddy Guttapalem <cguttapalem@salesforce.com>
Authored: Tue Nov 8 23:44:54 2016 -0800
Committer: Sijie Guo <sijie@apache.org>
Committed: Tue Nov 8 23:44:54 2016 -0800

----------------------------------------------------------------------
 .../bookkeeper/client/LedgerHandleAdv.java      | 23 +++++++++++++++-----
 1 file changed, 17 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/8f0bed9f/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandleAdv.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandleAdv.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandleAdv.java
index 4a7de57..4cdcdca 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandleAdv.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandleAdv.java
@@ -150,9 +150,7 @@ public class LedgerHandleAdv extends LedgerHandle {
             cb.addComplete(BKException.Code.DuplicateEntryIdException,
                     LedgerHandleAdv.this, entryId, ctx);
             return;
-        }
-        pendingAddOps.add(op);
-
+        }       
         doAsyncAddEntry(op, data, offset, length, cb, ctx);
     }
 
@@ -174,7 +172,22 @@ public class LedgerHandleAdv extends LedgerHandle {
             throttler.acquire();
         }
 
-        if (metadata.isClosed()) {
+        final long currentLength;
+        boolean wasClosed = false;
+        synchronized (this) {
+            // synchronized on this to ensure that
+            // the ledger isn't closed between checking and
+            // updating lastAddPushed
+            if (metadata.isClosed()) {
+                wasClosed = true;
+                currentLength = 0;
+            } else {
+                currentLength = addToLength(length);
+                pendingAddOps.add(op);
+            }
+        }
+
+        if (wasClosed) {
             // make sure the callback is triggered in main worker pool
             try {
                 bk.mainWorkerPool.submit(new SafeRunnable() {
@@ -197,8 +210,6 @@ public class LedgerHandleAdv extends LedgerHandle {
         }
 
         try {
-            final long currentLength = addToLength(length);
-
             bk.mainWorkerPool.submit(new SafeRunnable() {
                 @Override
                 public void safeRun() {


Mime
View raw message