hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From x...@apache.org
Subject hadoop git commit: HDFS-11805. Ensure LevelDB DBIterator is closed. Contributed by Chen Liang.
Date Sun, 14 May 2017 13:09:18 GMT
Repository: hadoop
Updated Branches:
  refs/heads/HDFS-7240 7e8b3e254 -> b8e063ebc


HDFS-11805. Ensure LevelDB DBIterator is closed. Contributed by Chen Liang.


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

Branch: refs/heads/HDFS-7240
Commit: b8e063ebcb4debe39123787930140c783079099c
Parents: 7e8b3e2
Author: Xiaoyu Yao <xyao@apache.org>
Authored: Sun May 14 06:06:58 2017 -0700
Committer: Xiaoyu Yao <xyao@apache.org>
Committed: Sun May 14 06:06:58 2017 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/cblock/CBlockManager.java | 26 ++++-----
 .../web/localstorage/OzoneMetadataManager.java  | 57 ++++++++++----------
 2 files changed, 42 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/b8e063eb/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/cblock/CBlockManager.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/cblock/CBlockManager.java
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/cblock/CBlockManager.java
index 9f8d5b1..4095530 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/cblock/CBlockManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/cblock/CBlockManager.java
@@ -74,7 +74,6 @@ import static org.apache.hadoop.cblock.CBlockConfigKeys.DFS_CBLOCK_SERVICERPC_HA
 import static org.apache.hadoop.cblock.CBlockConfigKeys.DFS_CBLOCK_SERVICERPC_HANDLER_COUNT_KEY;
 import static org.apache.hadoop.cblock.CBlockConfigKeys.DFS_CBLOCK_SERVICE_LEVELDB_PATH_DEFAULT;
 import static org.apache.hadoop.cblock.CBlockConfigKeys.DFS_CBLOCK_SERVICE_LEVELDB_PATH_KEY;
-import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT_DEFAULT;
 
 /**
  * The main entry point of CBlock operations, ALL the CBlock operations
@@ -269,18 +268,19 @@ public class CBlockManager implements CBlockServiceProtocol,
     levelDBStore.delete(key);
   }
 
-  public void readFromPersistentStore() {
-    DBIterator iter = levelDBStore.getIterator();
-    iter.seekToFirst();
-    while (iter.hasNext()) {
-      Map.Entry<byte[], byte[]> entry = iter.next();
-      String volumeKey = new String(entry.getKey(), encoding);
-      try {
-        VolumeDescriptor volumeDescriptor =
-            VolumeDescriptor.fromProtobuf(entry.getValue());
-        storageManager.addVolume(volumeDescriptor);
-      } catch (IOException e) {
-        LOG.error("Loading volume " + volumeKey + " error " + e);
+  public void readFromPersistentStore() throws IOException {
+    try (DBIterator iter = levelDBStore.getIterator()) {
+      iter.seekToFirst();
+      while (iter.hasNext()) {
+        Map.Entry<byte[], byte[]> entry = iter.next();
+        String volumeKey = new String(entry.getKey(), encoding);
+        try {
+          VolumeDescriptor volumeDescriptor =
+              VolumeDescriptor.fromProtobuf(entry.getValue());
+          storageManager.addVolume(volumeDescriptor);
+        } catch (IOException e) {
+          LOG.error("Loading volume " + volumeKey + " error " + e);
+        }
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/b8e063eb/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/localstorage/OzoneMetadataManager.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/localstorage/OzoneMetadataManager.java
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/localstorage/OzoneMetadataManager.java
index 52c192c..c63707c 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/localstorage/OzoneMetadataManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/localstorage/OzoneMetadataManager.java
@@ -452,45 +452,46 @@ public final class OzoneMetadataManager {
     String prevKey = args.getPrevKey();
     int maxCount = args.getMaxKeys();
     String userName = null;
-    DBIterator iterator = this.userDB.getDB().iterator();
+    try (DBIterator iterator = this.userDB.getDB().iterator()) {
 
-    if (prevKey != null) {
-      // Format is username/volumeName
+      if (prevKey != null) {
+        // Format is username/volumeName
+
+        String[] volName = args.getPrevKey().split("/");
+        if (volName.length < 2) {
+          throw ErrorTable.newError(ErrorTable.USER_NOT_FOUND, args.getArgs());
+        }
+        seekToUser(iterator, volName[0]);
+        userName = new String(iterator.peekNext().getKey(), encoding);
+        prevKey = volName[1];
+      } else {
+        userName = getFirstUser(iterator);
+      }
 
-      String[] volName = args.getPrevKey().split("/");
-      if (volName.length < 2) {
+      if (userName == null || userName.isEmpty()) {
         throw ErrorTable.newError(ErrorTable.USER_NOT_FOUND, args.getArgs());
       }
-      seekToUser(iterator, volName[0]);
-      userName = new String(iterator.peekNext().getKey(), encoding);
-      prevKey = volName[1];
-    } else {
-      userName = getFirstUser(iterator);
-    }
 
-    if (userName == null || userName.isEmpty()) {
-      throw ErrorTable.newError(ErrorTable.USER_NOT_FOUND, args.getArgs());
-    }
+      ListVolumes returnSet = new ListVolumes();
+      int count = maxCount - returnSet.getVolumes().size();
 
-    ListVolumes returnSet = new ListVolumes();
-    int count = maxCount - returnSet.getVolumes().size();
+      // we need to iterate through users until we get maxcount volumes
+      // or no more volumes are left.
+      while (iterator.hasNext() && count > 0) {
 
-    // we need to iterate through users until we get maxcount volumes
-    // or no more volumes are left.
-    while (iterator.hasNext() && count > 0) {
+        userName = new String(iterator.next().getKey(), encoding);
 
-      userName = new String(iterator.next().getKey(), encoding);
+        byte[] volumeList = userDB.get(userName.getBytes(encoding));
+        if (volumeList == null) {
+          throw ErrorTable.newError(ErrorTable.USER_NOT_FOUND, args.getArgs());
+        }
 
-      byte[] volumeList = userDB.get(userName.getBytes(encoding));
-      if (volumeList == null) {
-        throw ErrorTable.newError(ErrorTable.USER_NOT_FOUND, args.getArgs());
+        returnSet.getVolumes().addAll(getFilteredVolumes(
+            volumeList, prefix, prevKey, count).getVolumes());
+        count = maxCount - returnSet.getVolumes().size();
       }
-
-      returnSet.getVolumes().addAll(
-          getFilteredVolumes(volumeList, prefix, prevKey, count).getVolumes());
-      count = maxCount - returnSet.getVolumes().size();
+      return returnSet;
     }
-    return returnSet;
   }
 
   /**


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message