From 165bbb9e8de0c620a4cdbb8f0de61a9eb02c508b Mon Sep 17 00:00:00 2001 From: tedyu Date: Thu, 8 Jan 2015 08:52:13 -0800 Subject: [PATCH] HBASE-12819 ExportSnapshot doesn't close FileSystem instances --- .../hadoop/hbase/snapshot/ExportSnapshot.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java index 02ae346ca7e..2655e2b6db9 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java @@ -59,6 +59,7 @@ import org.apache.hadoop.hbase.protobuf.generated.SnapshotProtos.SnapshotRegionM import org.apache.hadoop.hbase.util.FSUtils; import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.io.BytesWritable; +import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.NullWritable; import org.apache.hadoop.io.Writable; import org.apache.hadoop.mapreduce.Job; @@ -152,12 +153,14 @@ public class ExportSnapshot extends Configured implements Tool { testFailures = conf.getBoolean(CONF_TEST_FAILURE, false); try { + conf.setBoolean("fs." + inputRoot.toUri().getScheme() + ".impl.disable.cache", true); inputFs = FileSystem.get(inputRoot.toUri(), conf); } catch (IOException e) { throw new IOException("Could not get the input FileSystem with root=" + inputRoot, e); } try { + conf.setBoolean("fs." + outputRoot.toUri().getScheme() + ".impl.disable.cache", true); outputFs = FileSystem.get(outputRoot.toUri(), conf); } catch (IOException e) { throw new IOException("Could not get the output FileSystem with root="+ outputRoot, e); @@ -173,6 +176,12 @@ public class ExportSnapshot extends Configured implements Tool { } } + @Override + protected void cleanup(Context context) { + IOUtils.closeStream(inputFs); + IOUtils.closeStream(outputFs); + } + @Override public void map(BytesWritable key, NullWritable value, Context context) throws InterruptedException, IOException { @@ -854,8 +863,10 @@ public class ExportSnapshot extends Configured implements Tool { targetName = snapshotName; } + conf.setBoolean("fs." + inputRoot.toUri().getScheme() + ".impl.disable.cache", true); FileSystem inputFs = FileSystem.get(inputRoot.toUri(), conf); LOG.debug("inputFs=" + inputFs.getUri().toString() + " inputRoot=" + inputRoot); + conf.setBoolean("fs." + outputRoot.toUri().getScheme() + ".impl.disable.cache", true); FileSystem outputFs = FileSystem.get(outputRoot.toUri(), conf); LOG.debug("outputFs=" + outputFs.getUri().toString() + " outputRoot=" + outputRoot.toString()); @@ -949,6 +960,9 @@ public class ExportSnapshot extends Configured implements Tool { } outputFs.delete(outputSnapshotDir, true); return 1; + } finally { + IOUtils.closeStream(inputFs); + IOUtils.closeStream(outputFs); } }