HBASE-15291 FileSystem not closed in secure bulkLoad

Signed-off-by: Ashish Singhi <ashishsinghi@apache.org>
This commit is contained in:
Ashish Singhi 2018-04-11 12:01:28 +05:30
parent 95ca38a539
commit 828a1c76c7
1 changed files with 54 additions and 28 deletions

View File

@ -145,6 +145,7 @@ public class SecureBulkLoadManager {
public void cleanupBulkLoad(final HRegion region, final CleanupBulkLoadRequest request)
throws IOException {
try {
region.getCoprocessorHost().preCleanupBulkLoad(getActiveUser());
Path path = new Path(request.getBulkToken());
@ -154,6 +155,16 @@ public class SecureBulkLoadManager {
}
}
LOG.info("Cleaned up " + path + " successfully.");
} finally {
UserGroupInformation ugi = getActiveUser().getUGI();
try {
if (!UserGroupInformation.getLoginUser().equals(ugi)) {
FileSystem.closeAllForUGI(ugi);
}
} catch (IOException e) {
LOG.error("Failed to close FileSystem for: " + ugi, e);
}
}
}
public Map<byte[], List<Path>> secureBulkLoadHFiles(final HRegion region,
@ -304,7 +315,7 @@ public class SecureBulkLoadManager {
}
if (srcFs == null) {
srcFs = FileSystem.get(p.toUri(), conf);
srcFs = FileSystem.newInstance(p.toUri(), conf);
}
if(!isFile(p)) {
@ -334,17 +345,28 @@ public class SecureBulkLoadManager {
@Override
public void doneBulkLoad(byte[] family, String srcPath) throws IOException {
LOG.debug("Bulk Load done for: " + srcPath);
closeSrcFs();
}
private void closeSrcFs() throws IOException {
if (srcFs != null) {
srcFs.close();
srcFs = null;
}
}
@Override
public void failedBulkLoad(final byte[] family, final String srcPath) throws IOException {
try {
Path p = new Path(srcPath);
if (srcFs == null) {
srcFs = FileSystem.newInstance(p.toUri(), conf);
}
if (!FSHDFSUtils.isSameHdfs(conf, srcFs, fs)) {
// files are copied so no need to move them back
return;
}
Path p = new Path(srcPath);
Path stageP = new Path(stagingDir,
new Path(Bytes.toString(family), p.getName()));
Path stageP = new Path(stagingDir, new Path(Bytes.toString(family), p.getName()));
// In case of Replication for bulk load files, hfiles are not renamed by end point during
// prepare stage, so no need of rename here again
@ -354,8 +376,9 @@ public class SecureBulkLoadManager {
}
LOG.debug("Moving " + stageP + " back to " + p);
if(!fs.rename(stageP, p))
if (!fs.rename(stageP, p)) {
throw new IOException("Failed to move HFile: " + stageP + " to " + p);
}
// restore original permission
if (origPermissions.containsKey(srcPath)) {
@ -363,6 +386,9 @@ public class SecureBulkLoadManager {
} else {
LOG.warn("Can't find previous permission for path=" + srcPath);
}
} finally {
closeSrcFs();
}
}
/**