HBASE-12819 ExportSnapshot doesn't close FileSystem instances

This commit is contained in:
tedyu 2015-01-08 08:51:25 -08:00
parent 9246af8dac
commit ee32eebeab
1 changed files with 14 additions and 0 deletions

View File

@ -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.FSUtils;
import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.io.BytesWritable; import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.io.NullWritable; import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Writable; import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Job;
@ -152,12 +153,14 @@ public class ExportSnapshot extends Configured implements Tool {
testFailures = conf.getBoolean(CONF_TEST_FAILURE, false); testFailures = conf.getBoolean(CONF_TEST_FAILURE, false);
try { try {
conf.setBoolean("fs." + inputRoot.toUri().getScheme() + ".impl.disable.cache", true);
inputFs = FileSystem.get(inputRoot.toUri(), conf); inputFs = FileSystem.get(inputRoot.toUri(), conf);
} catch (IOException e) { } catch (IOException e) {
throw new IOException("Could not get the input FileSystem with root=" + inputRoot, e); throw new IOException("Could not get the input FileSystem with root=" + inputRoot, e);
} }
try { try {
conf.setBoolean("fs." + outputRoot.toUri().getScheme() + ".impl.disable.cache", true);
outputFs = FileSystem.get(outputRoot.toUri(), conf); outputFs = FileSystem.get(outputRoot.toUri(), conf);
} catch (IOException e) { } catch (IOException e) {
throw new IOException("Could not get the output FileSystem with root="+ outputRoot, 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 @Override
public void map(BytesWritable key, NullWritable value, Context context) public void map(BytesWritable key, NullWritable value, Context context)
throws InterruptedException, IOException { throws InterruptedException, IOException {
@ -854,8 +863,10 @@ public class ExportSnapshot extends Configured implements Tool {
targetName = snapshotName; targetName = snapshotName;
} }
conf.setBoolean("fs." + inputRoot.toUri().getScheme() + ".impl.disable.cache", true);
FileSystem inputFs = FileSystem.get(inputRoot.toUri(), conf); FileSystem inputFs = FileSystem.get(inputRoot.toUri(), conf);
LOG.debug("inputFs=" + inputFs.getUri().toString() + " inputRoot=" + inputRoot); 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); FileSystem outputFs = FileSystem.get(outputRoot.toUri(), conf);
LOG.debug("outputFs=" + outputFs.getUri().toString() + " outputRoot=" + outputRoot.toString()); LOG.debug("outputFs=" + outputFs.getUri().toString() + " outputRoot=" + outputRoot.toString());
@ -949,6 +960,9 @@ public class ExportSnapshot extends Configured implements Tool {
} }
outputFs.delete(outputSnapshotDir, true); outputFs.delete(outputSnapshotDir, true);
return 1; return 1;
} finally {
IOUtils.closeStream(inputFs);
IOUtils.closeStream(outputFs);
} }
} }