Skip to content

Commit f3d1696

Browse files
committed
HBASE-22842 Tmp directory should not be deleted when master restart used for user scan snapshot feature
1 parent 53db390 commit f3d1696

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.apache.hadoop.hbase.procedure2.store.wal.WALProcedureStore;
4343
import org.apache.hadoop.hbase.regionserver.HRegion;
4444
import org.apache.hadoop.hbase.replication.ReplicationUtils;
45+
import org.apache.hadoop.hbase.security.access.SnapshotScannerHDFSAclHelper;
4546
import org.apache.hadoop.hbase.util.Bytes;
4647
import org.apache.hadoop.hbase.util.FSTableDescriptors;
4748
import org.apache.hadoop.hbase.util.FSUtils;
@@ -318,20 +319,26 @@ void checkTempDir(final Path tmpdir, final Configuration c, final FileSystem fs)
318319
for (Path tableDir: FSUtils.getTableDirs(fs, tmpdir)) {
319320
HFileArchiver.archiveRegions(c, fs, this.rootdir, tableDir,
320321
FSUtils.getRegionDirs(fs, tableDir));
322+
if (!FSUtils.getRegionDirs(fs, tableDir).isEmpty()) {
323+
LOG.warn("Found regions in tmp dir after archiving table regions, {}", tableDir);
324+
}
321325
}
322-
if (!fs.delete(tmpdir, true)) {
326+
// if acl sync to hdfs is enabled, then skip delete tmp dir because ACLs are set
327+
if (!SnapshotScannerHDFSAclHelper.isAclSyncToHdfsEnabled(c) && !fs.delete(tmpdir, true)) {
323328
throw new IOException("Unable to clean the temp directory: " + tmpdir);
324329
}
325330
}
326331

327332
// Create the temp directory
328-
if (isSecurityEnabled) {
329-
if (!fs.mkdirs(tmpdir, secureRootSubDirPerms)) {
330-
throw new IOException("HBase temp directory '" + tmpdir + "' creation failure.");
331-
}
332-
} else {
333-
if (!fs.mkdirs(tmpdir)) {
334-
throw new IOException("HBase temp directory '" + tmpdir + "' creation failure.");
333+
if (!fs.exists(tmpdir)) {
334+
if (isSecurityEnabled) {
335+
if (!fs.mkdirs(tmpdir, secureRootSubDirPerms)) {
336+
throw new IOException("HBase temp directory '" + tmpdir + "' creation failure.");
337+
}
338+
} else {
339+
if (!fs.mkdirs(tmpdir)) {
340+
throw new IOException("HBase temp directory '" + tmpdir + "' creation failure.");
341+
}
335342
}
336343
}
337344
}

hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestSnapshotScannerHDFSAclController.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import org.apache.hadoop.hbase.testclassification.LargeTests;
5959
import org.apache.hadoop.hbase.testclassification.SecurityTests;
6060
import org.apache.hadoop.hbase.util.Bytes;
61+
import org.apache.hadoop.hbase.util.FSUtils;
6162
import org.apache.hadoop.hbase.util.HFileArchiveUtil;
6263
import org.junit.AfterClass;
6364
import org.junit.BeforeClass;
@@ -883,9 +884,24 @@ public void testRestartMaster() throws Exception {
883884
User grantUser = User.createUserForTesting(conf, grantUserName, new String[] {});
884885
String namespace = name.getMethodName();
885886
TableName table = TableName.valueOf(namespace, "t1");
887+
TableName table2 = TableName.valueOf(namespace, "t2");
886888
String snapshot = namespace + "t1";
887889
admin.createNamespace(NamespaceDescriptor.create(namespace).build());
888890

891+
// create table2
892+
TestHDFSAclHelper.createTableAndPut(TEST_UTIL, table2);
893+
// make some region files in tmp dir and check if master archive these region correctly
894+
Path tmpTableDir = helper.getPathHelper().getTmpTableDir(table2);
895+
// make a empty region dir, this is an error region
896+
fs.mkdirs(new Path(tmpTableDir, "1"));
897+
// copy regions from data dir, this is a valid region
898+
for (Path regionDir : FSUtils.getRegionDirs(fs,
899+
helper.getPathHelper().getDataTableDir(table2))) {
900+
FSUtils.copyFilesParallel(fs, regionDir, fs,
901+
new Path(tmpTableDir, regionDir.getName() + "abc"), conf, 1);
902+
}
903+
assertEquals(4, fs.listStatus(tmpTableDir).length);
904+
889905
// grant N(R)
890906
SecureTestUtil.grantOnNamespace(TEST_UTIL, grantUserName, namespace, READ);
891907
// restart cluster and tmp directory will not be deleted
@@ -894,15 +910,16 @@ public void testRestartMaster() throws Exception {
894910
TEST_UTIL.waitUntilNoRegionsInTransition();
895911

896912
Path tmpNsDir = helper.getPathHelper().getTmpNsDir(namespace);
897-
assertFalse(fs.exists(tmpNsDir));
913+
assertTrue(fs.exists(tmpNsDir));
914+
// check all regions in tmp table2 dir are archived
915+
assertEquals(0, fs.listStatus(tmpTableDir).length);
898916

899-
// create table2 and snapshot
917+
// create table1 and snapshot
900918
TestHDFSAclHelper.createTableAndPut(TEST_UTIL, table);
901919
admin = TEST_UTIL.getAdmin();
902920
aclTable = TEST_UTIL.getConnection().getTable(PermissionStorage.ACL_TABLE_NAME);
903921
admin.snapshot(snapshot, table);
904-
// TODO fix it in another patch
905-
TestHDFSAclHelper.canUserScanSnapshot(TEST_UTIL, grantUser, snapshot, -1);
922+
TestHDFSAclHelper.canUserScanSnapshot(TEST_UTIL, grantUser, snapshot, 6);
906923
}
907924

908925
private void checkUserAclEntry(List<Path> paths, String user, boolean requireAccessAcl,

0 commit comments

Comments
 (0)