You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by wc...@apache.org on 2020/09/01 08:32:59 UTC

[hbase-filesystem] branch master updated: HBASE-24961 [HBOSS] HBaseObjectStoreSemantics.close should call super.close to make sure its own instance always get removed from FileSystem.CACHE (#14)

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

wchevreuil pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase-filesystem.git


The following commit(s) were added to refs/heads/master by this push:
     new 9b8155d  HBASE-24961 [HBOSS] HBaseObjectStoreSemantics.close should call super.close to make sure its own instance always get removed from FileSystem.CACHE (#14)
9b8155d is described below

commit 9b8155dd9aa946a0e62789629d63c553cdb14abc
Author: Wellington Ramos Chevreuil <wc...@apache.org>
AuthorDate: Tue Sep 1 09:32:51 2020 +0100

    HBASE-24961 [HBOSS] HBaseObjectStoreSemantics.close should call super.close to make sure its own instance always get removed from FileSystem.CACHE (#14)
    
    Signed-off-by: Josh Elser <el...@apache.org>
---
 .../hbase/oss/HBaseObjectStoreSemantics.java       |  2 +-
 .../hadoop/hbase/oss/sync/ZKTreeLockManager.java   | 28 ++++++++++++---
 .../org/apache/hadoop/hbase/oss/TestClose.java     | 42 ++++++++++++++++++++++
 3 files changed, 67 insertions(+), 5 deletions(-)

diff --git a/hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/HBaseObjectStoreSemantics.java b/hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/HBaseObjectStoreSemantics.java
index be1bcff..a9b3d72 100644
--- a/hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/HBaseObjectStoreSemantics.java
+++ b/hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/HBaseObjectStoreSemantics.java
@@ -35,7 +35,6 @@ import org.apache.hadoop.fs.FileChecksum;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.FilterFileSystem;
-import org.apache.hadoop.fs.FsServerDefaults;
 import org.apache.hadoop.fs.FsStatus;
 import org.apache.hadoop.fs.LocatedFileStatus;
 import org.apache.hadoop.fs.Options.ChecksumOpt;
@@ -694,6 +693,7 @@ public class HBaseObjectStoreSemantics extends FilterFileSystem {
     // FS must close first so that FileSystem.processDeleteOnExit() can run
     // while locking is still available.
     fs.close();
+    super.close();
     sync.close();
   }
 
diff --git a/hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/sync/ZKTreeLockManager.java b/hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/sync/ZKTreeLockManager.java
index 35ce908..70c5433 100644
--- a/hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/sync/ZKTreeLockManager.java
+++ b/hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/sync/ZKTreeLockManager.java
@@ -25,7 +25,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 import org.apache.curator.RetryPolicy;
 import org.apache.curator.framework.CuratorFramework;
@@ -121,9 +120,26 @@ public class ZKTreeLockManager extends TreeLockManager {
   }
 
   @Override
-  public void close() throws IOException {
+  public void close() {
     if (curator != null) {
-      curator.close();
+      synchronized(this) {
+        curator.close();
+        lockCache.clear();
+        logCaller();
+      }
+    }
+  }
+
+  private void logCaller(){
+    if(LOG.isDebugEnabled()){
+      StringBuilder builder = new StringBuilder();
+      StackTraceElement[] elements = Thread.currentThread().getStackTrace();
+      for(StackTraceElement e : elements) {
+        builder.append(e.getClassName()).append(".").
+          append(e.getMethodName()).append("(").append(e.getLineNumber()).append(")").append("\n");
+      }
+      LOG.debug("logging call with curator {} for instance {} at: {}",
+        curator, this, builder.toString());
     }
   }
 
@@ -175,8 +191,11 @@ public class ZKTreeLockManager extends TreeLockManager {
     }
   }
 
+  /*
+  We need to protect this block against potential concurrent calls to close()
+   */
   @Override
-  protected boolean writeLockAbove(Path p) throws IOException {
+  protected synchronized boolean writeLockAbove(Path p) throws IOException {
     LOG.debug("Checking for write lock above {}", p);
     while (!p.isRoot()) {
       p = p.getParent();
@@ -309,6 +328,7 @@ public class ZKTreeLockManager extends TreeLockManager {
     } catch (KeeperException.NoNodeException e){
       return false;
     } catch (Exception e) {
+      logCaller();
       throw new IOException("Exception while testing a lock", e);
     }
   }
diff --git a/hbase-oss/src/test/java/org/apache/hadoop/hbase/oss/TestClose.java b/hbase-oss/src/test/java/org/apache/hadoop/hbase/oss/TestClose.java
new file mode 100644
index 0000000..930e7a9
--- /dev/null
+++ b/hbase-oss/src/test/java/org/apache/hadoop/hbase/oss/TestClose.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.oss;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.LocalFileSystem;
+import org.apache.hadoop.hbase.oss.sync.NullTreeLockManager;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class TestClose {
+
+  @Test
+  public void testCloseRemovesInstanceFromFileSystemCache() throws IOException {
+    Configuration conf = new Configuration();
+    conf.set("fs.defaultFS", "testFS://test");
+    conf.set("fs.testFS.impl", HBaseObjectStoreSemantics.class.getName());
+    conf.set("fs.hboss.fs.testFS.impl", LocalFileSystem.class.getName());
+    conf.set(Constants.SYNC_IMPL, NullTreeLockManager.class.getName());
+    FileSystem fileSystem = FileSystem.get(conf);
+    fileSystem.close();
+    Assert.assertFalse(fileSystem == FileSystem.get(conf));
+  }
+}