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-863: Potential resource leak with unclosed LedgerManager in BookieShell (Ted Yu via sijie)
Date Wed, 12 Aug 2015 02:01:18 GMT
Repository: bookkeeper
Updated Branches:
  refs/heads/master 8bf97fb5b -> c29a4f260


BOOKKEEPER-863: Potential resource leak with unclosed LedgerManager in BookieShell (Ted Yu
via sijie)


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

Branch: refs/heads/master
Commit: c29a4f2601f72f8543cc4b1db419c84b01de75ce
Parents: 8bf97fb
Author: Sijie Guo <sijie@apache.org>
Authored: Tue Aug 11 19:00:52 2015 -0700
Committer: Sijie Guo <sijie@apache.org>
Committed: Tue Aug 11 19:00:52 2015 -0700

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 ++
 .../apache/bookkeeper/bookie/BookieShell.java   | 28 +++++++++++++++++---
 2 files changed, 26 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/c29a4f26/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 8590200..8547c26 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -87,6 +87,8 @@ Trunk (unreleased changes)
 
       BOOKKEEPER-687: Use static final Logger for hedwig related modules (Ankur Garg via
sijie)
 
+      BOOKKEEPER-863: Potential resource leak with unclosed LedgerManager in BookieShell
(Ted Yu via sijie)
+
       bookkeeper-client:
 
         BOOKKEEPER-810: Allow to configure TCP connect timeout (Charles Xie via sijie)

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/c29a4f26/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
index c7a65a1..98d311b 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
@@ -457,13 +457,15 @@ public class BookieShell implements Tool {
         @Override
         public int runCmd(CommandLine cmdLine) throws Exception {
             ZooKeeper zk = null;
+            LedgerManagerFactory mFactory = null;
+            LedgerManager m = null;
             try {
                 zk = ZooKeeperClient.newBuilder()
                         .connectString(bkConf.getZkServers())
                         .sessionTimeoutMs(bkConf.getZkTimeout())
                         .build();
-                LedgerManagerFactory mFactory = LedgerManagerFactory.newLedgerManagerFactory(bkConf,
zk);
-                LedgerManager m = mFactory.newLedgerManager();
+                mFactory = LedgerManagerFactory.newLedgerManagerFactory(bkConf, zk);
+                m = mFactory.newLedgerManager();
                 LedgerRangeIterator iter = m.getLedgerRanges();
                 if (cmdLine.hasOption("m")) {
                     List<ReadMetadataCallback> futures
@@ -495,6 +497,14 @@ public class BookieShell implements Tool {
                     }
                 }
             } finally {
+                if (m != null) {
+                    try {
+                      m.close();
+                      mFactory.uninitialize();
+                    } catch (IOException ioe) {
+                      LOG.error("Failed to close ledger manager : ", ioe);
+                    }
+                }
                 if (zk != null) {
                     zk.close();
                 }
@@ -566,17 +576,27 @@ public class BookieShell implements Tool {
             }
 
             ZooKeeper zk = null;
+            LedgerManagerFactory mFactory = null;
+            LedgerManager m = null;
             try {
                 zk = ZooKeeperClient.newBuilder()
                         .connectString(bkConf.getZkServers())
                         .sessionTimeoutMs(bkConf.getZkTimeout())
                         .build();
-                LedgerManagerFactory mFactory = LedgerManagerFactory.newLedgerManagerFactory(bkConf,
zk);
-                LedgerManager m = mFactory.newLedgerManager();
+                mFactory = LedgerManagerFactory.newLedgerManagerFactory(bkConf, zk);
+                m = mFactory.newLedgerManager();
                 ReadMetadataCallback cb = new ReadMetadataCallback(lid);
                 m.readLedgerMetadata(lid, cb);
                 printLedgerMetadata(cb);
             } finally {
+                if (m != null) {
+                    try {
+                        m.close();
+                        mFactory.uninitialize();
+                    } catch (IOException ioe) {
+                        LOG.error("Failed to close ledger manager : ", ioe);
+                    }
+                }
                 if (zk != null) {
                     zk.close();
                 }


Mime
View raw message