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-804: Client program is not terminated when using openLedgerNoRecovery (ivank via sijie)
Date Sat, 06 Dec 2014 06:42:29 GMT
Repository: bookkeeper
Updated Branches:
  refs/heads/branch-4.3 36e92f56e -> 3c8633922


BOOKKEEPER-804: Client program is not terminated when using openLedgerNoRecovery (ivank via
sijie)


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

Branch: refs/heads/branch-4.3
Commit: 3c8633922a233acb366142e9e9b122b8bd63f64d
Parents: 36e92f5
Author: Sijie Guo <sijie@apache.org>
Authored: Fri Dec 5 22:42:07 2014 -0800
Committer: Sijie Guo <sijie@apache.org>
Committed: Fri Dec 5 22:42:07 2014 -0800

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 +
 .../meta/AbstractZkLedgerManager.java           |  1 -
 .../bookkeeper/meta/CleanupLedgerManager.java   |  1 +
 .../bookkeeper/client/BookKeeperCloseTest.java  | 58 ++++++++++++++++++++
 4 files changed, 61 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/3c863392/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 4f47e7f..1d3f26a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -12,6 +12,8 @@ Release 4.3.1 - unreleased
 
       BOOKKEEPER-809: Wrong metric on LedgerDeleteOp and LedgerOpenOp (Charles Xie via sijie)
 
+      BOOKKEEPER-804: Client program is not terminated when using openLedgerNoRecovery (ivank
via sijie)
+
     IMPROVEMENTS:
 
       BOOKKEEPER-800: Expose whether a ledger is closed or not (ivank)

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/3c863392/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/AbstractZkLedgerManager.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/AbstractZkLedgerManager.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/AbstractZkLedgerManager.java
index 0fc8afe..f3f680d 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/AbstractZkLedgerManager.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/AbstractZkLedgerManager.java
@@ -134,7 +134,6 @@ abstract class AbstractZkLedgerManager implements LedgerManager, Watcher
{
         this.conf = conf;
         this.zk = zk;
         this.ledgerRootPath = conf.getZkLedgersRootPath();
-        this.scheduler = Executors.newSingleThreadScheduledExecutor();
         ThreadFactoryBuilder tfb = new ThreadFactoryBuilder().setNameFormat(
                 "ZkLedgerManagerScheduler-%d");
         this.scheduler = Executors

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/3c863392/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/CleanupLedgerManager.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/CleanupLedgerManager.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/CleanupLedgerManager.java
index a873112..a7fbcf5 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/CleanupLedgerManager.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/CleanupLedgerManager.java
@@ -222,5 +222,6 @@ public class CleanupLedgerManager implements LedgerManager {
                 callback.operationComplete(BKException.Code.ClientClosedException, null);
             }
         }
+        underlying.close();
     }
 }

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/3c863392/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperCloseTest.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperCloseTest.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperCloseTest.java
index 89790f6..13ccfe5 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperCloseTest.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/BookKeeperCloseTest.java
@@ -37,6 +37,8 @@ import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.util.concurrent.SettableFuture;
+
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.Enumeration;
@@ -522,6 +524,62 @@ public class BookKeeperCloseTest extends BookKeeperClusterTestCase {
         }
     }
 
+    /**
+     * Test that the bookkeeper client doesn't leave any threads hanging around.
+     * See {@link https://issues.apache.org/jira/browse/BOOKKEEPER-804}
+     */
+    @Test(timeout = 60000)
+    public void testBookKeeperCloseThreads() throws Exception {
+        ThreadGroup group = new ThreadGroup("test-group");
+        final SettableFuture<Void> future = SettableFuture.<Void>create();
+
+        Thread t = new Thread(group, "TestThread") {
+                @Override
+                public void run() {
+                    try {
+                        BookKeeper bk = new BookKeeper(baseClientConf);
+                        // 9 is a ledger id of an existing ledger
+                        LedgerHandle lh = bk.createLedger(BookKeeper.DigestType.CRC32, "passwd".getBytes());
+                        lh.addEntry("foobar".getBytes());
+                        lh.close();
+                        long id = lh.getId();
+                        // 9 is a ledger id of an existing ledger
+                        lh = bk.openLedgerNoRecovery(id, BookKeeper.DigestType.CRC32, "passwd".getBytes());
+                        Enumeration<LedgerEntry> entries = lh.readEntries(0, 0);
+
+                        lh.close();
+                        bk.close();
+                        future.set(null);
+                    } catch (InterruptedException ie) {
+                        Thread.currentThread().interrupt();
+                        future.setException(ie);
+                    } catch (Exception e) {
+                        future.setException(e);
+                    }
+                }
+            };
+        t.start();
+
+        future.get();
+        t.join();
+
+        // check in a loop for 10 seconds
+        // because sometimes it takes a while to threads to go away
+        for (int i = 0; i < 10; i++) {
+            if (group.activeCount() > 0) {
+                Thread[] threads = new Thread[group.activeCount()];
+                group.enumerate(threads);
+                for (Thread leftover : threads) {
+                    LOG.error("Leftover thread after {} secs: {}", i, leftover);
+                }
+                Thread.sleep(1000);
+            } else {
+                break;
+            }
+        }
+        assertEquals("Should be no threads left in group", 0, group.activeCount());
+    }
+
     private LedgerHandle createLedgerWithEntries(BookKeeper bk, int numOfEntries)
             throws Exception {
         LedgerHandle lh = bk


Mime
View raw message