Skip to content
Permalink
Browse files
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 <elserj@apache.org>
  • Loading branch information
wchevreuil committed Sep 1, 2020
1 parent de65b4a commit 9b8155dd9aa946a0e62789629d63c553cdb14abc
Showing 3 changed files with 67 additions and 5 deletions.
@@ -35,7 +35,6 @@
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 void close() throws IOException {
// FS must close first so that FileSystem.processDeleteOnExit() can run
// while locking is still available.
fs.close();
super.close();
sync.close();
}

@@ -25,7 +25,6 @@
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 @@ private void waitForCuratorToConnect() {
}

@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 @@ protected void readUnlock(Path p) throws IOException {
}
}

/*
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 @@ private boolean isLocked(InterProcessMutex lock) throws IOException {
} catch (KeeperException.NoNodeException e){
return false;
} catch (Exception e) {
logCaller();
throw new IOException("Exception while testing a lock", e);
}
}
@@ -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));
}
}

0 comments on commit 9b8155d

Please sign in to comment.