@@ -119,7 +119,7 @@ public Optional<MasterObserver> getMasterObserver() {
119119 public void preMasterInitialization (ObserverContext <MasterCoprocessorEnvironment > c )
120120 throws IOException {
121121 if (c .getEnvironment ().getConfiguration ()
122- .getBoolean (SnapshotScannerHDFSAclHelper .USER_SCAN_SNAPSHOT_ENABLE , false )) {
122+ .getBoolean (SnapshotScannerHDFSAclHelper .ACL_SYNC_TO_HDFS_ENABLE , false )) {
123123 MasterCoprocessorEnvironment mEnv = c .getEnvironment ();
124124 if (!(mEnv instanceof HasMasterServices )) {
125125 throw new IOException ("Does not implement HMasterServices" );
@@ -133,7 +133,7 @@ public void preMasterInitialization(ObserverContext<MasterCoprocessorEnvironment
133133 userProvider = UserProvider .instantiate (c .getEnvironment ().getConfiguration ());
134134 } else {
135135 LOG .warn ("Try to initialize the coprocessor SnapshotScannerHDFSAclController but failure "
136- + "because the config " + SnapshotScannerHDFSAclHelper .USER_SCAN_SNAPSHOT_ENABLE
136+ + "because the config " + SnapshotScannerHDFSAclHelper .ACL_SYNC_TO_HDFS_ENABLE
137137 + " is false." );
138138 }
139139 }
@@ -213,6 +213,7 @@ public void postCompletedSnapshotAction(ObserverContext<MasterCoprocessorEnviron
213213 public void postCompletedTruncateTableAction (ObserverContext <MasterCoprocessorEnvironment > c ,
214214 TableName tableName ) throws IOException {
215215 if (needHandleTableHdfsAcl (tableName , "truncateTable " + tableName )) {
216+ hdfsAclHelper .createTableDirectories (tableName );
216217 // Since the table directories is recreated, so add HDFS acls again
217218 Set <String > users = hdfsAclHelper .getUsersWithTableReadAction (tableName , false , false );
218219 hdfsAclHelper .addTableAcl (tableName , users , "truncate" );
@@ -233,9 +234,11 @@ public void postDeleteTable(ObserverContext<MasterCoprocessorEnvironment> ctx,
233234 try (Table aclTable =
234235 ctx .getEnvironment ().getConnection ().getTable (PermissionStorage .ACL_TABLE_NAME )) {
235236 Set <String > users = SnapshotScannerHDFSAclStorage .getTableUsers (aclTable , tableName );
236- // 1. Delete table owner permission is synced to HDFS in acl table
237+ // 1. Remove table archive directory default ACLs
238+ hdfsAclHelper .removeTableDefaultAcl (tableName , users );
239+ // 2. Delete table owner permission is synced to HDFS in acl table
237240 SnapshotScannerHDFSAclStorage .deleteTableHdfsAcl (aclTable , tableName );
238- // 2 . Remove namespace access acls
241+ // 3 . Remove namespace access acls
239242 Set <String > removeUsers = filterUsersToRemoveNsAccessAcl (aclTable , tableName , users );
240243 if (removeUsers .size () > 0 ) {
241244 hdfsAclHelper .removeNamespaceAccessAcl (tableName , removeUsers , "delete" );
@@ -251,7 +254,7 @@ public void postModifyTable(ObserverContext<MasterCoprocessorEnvironment> ctx,
251254 try (Table aclTable =
252255 ctx .getEnvironment ().getConnection ().getTable (PermissionStorage .ACL_TABLE_NAME )) {
253256 if (needHandleTableHdfsAcl (currentDescriptor , "modifyTable " + tableName )
254- && !hdfsAclHelper .isTableUserScanSnapshotEnabled (oldDescriptor )) {
257+ && !hdfsAclHelper .isAclSyncToHdfsEnabled (oldDescriptor )) {
255258 // 1. Create table directories used for acl inherited
256259 hdfsAclHelper .createTableDirectories (tableName );
257260 // 2. Add table users HDFS acls
@@ -264,7 +267,7 @@ public void postModifyTable(ObserverContext<MasterCoprocessorEnvironment> ctx,
264267 SnapshotScannerHDFSAclStorage .addUserTableHdfsAcl (ctx .getEnvironment ().getConnection (),
265268 tableUsers , tableName );
266269 } else if (needHandleTableHdfsAcl (oldDescriptor , "modifyTable " + tableName )
267- && !hdfsAclHelper .isTableUserScanSnapshotEnabled (currentDescriptor )) {
270+ && !hdfsAclHelper .isAclSyncToHdfsEnabled (currentDescriptor )) {
268271 // 1. Remove empty table directories
269272 List <Path > tableRootPaths = hdfsAclHelper .getTableRootPaths (tableName , false );
270273 for (Path path : tableRootPaths ) {
@@ -290,17 +293,24 @@ public void postModifyTable(ObserverContext<MasterCoprocessorEnvironment> ctx,
290293 public void postDeleteNamespace (ObserverContext <MasterCoprocessorEnvironment > ctx ,
291294 String namespace ) throws IOException {
292295 if (checkInitialized ("deleteNamespace " + namespace )) {
293- // 1. Record namespace user acl is not synced to HDFS
294- SnapshotScannerHDFSAclStorage .deleteNamespaceHdfsAcl (ctx .getEnvironment ().getConnection (),
295- namespace );
296- // 2. Delete tmp namespace directory
297- /**
298- * Delete namespace tmp directory because it's created by this coprocessor when namespace is
299- * created to make namespace default acl can be inherited by tables. The namespace data
300- * directory is deleted by DeleteNamespaceProcedure, the namespace archive directory is
301- * deleted by HFileCleaner.
302- */
303- hdfsAclHelper .deleteEmptyDir (pathHelper .getTmpNsDir (namespace ));
296+ try (Table aclTable =
297+ ctx .getEnvironment ().getConnection ().getTable (PermissionStorage .ACL_TABLE_NAME )) {
298+ // 1. Delete namespace archive dir default ACLs
299+ Set <String > users = SnapshotScannerHDFSAclStorage .getEntryUsers (aclTable ,
300+ PermissionStorage .toNamespaceEntry (Bytes .toBytes (namespace )));
301+ hdfsAclHelper .removeNamespaceDefaultAcl (namespace , users );
302+ // 2. Record namespace user acl is not synced to HDFS
303+ SnapshotScannerHDFSAclStorage .deleteNamespaceHdfsAcl (ctx .getEnvironment ().getConnection (),
304+ namespace );
305+ // 3. Delete tmp namespace directory
306+ /**
307+ * Delete namespace tmp directory because it's created by this coprocessor when namespace is
308+ * created to make namespace default acl can be inherited by tables. The namespace data
309+ * directory is deleted by DeleteNamespaceProcedure, the namespace archive directory is
310+ * deleted by HFileCleaner.
311+ */
312+ hdfsAclHelper .deleteEmptyDir (pathHelper .getTmpNsDir (namespace ));
313+ }
304314 }
305315 }
306316
@@ -364,7 +374,9 @@ public void postGrant(ObserverContext<MasterCoprocessorEnvironment> c,
364374 UserPermission tPerm = getUserTablePermission (conf , userName , tableName );
365375 if (tPerm != null && hdfsAclHelper .containReadAction (tPerm )) {
366376 if (!isHdfsAclSet (aclTable , userName , tableName )) {
367- // 1. Add HDFS acl
377+ // 1. create table dirs
378+ hdfsAclHelper .createTableDirectories (tableName );
379+ // 2. Add HDFS acl
368380 hdfsAclHelper .grantAcl (userPermission , new HashSet <>(0 ), new HashSet <>(0 ));
369381 }
370382 // 2. Record table acl is synced to HDFS
@@ -547,13 +559,13 @@ private boolean needHandleTableHdfsAcl(TablePermission tablePermission) throws I
547559
548560 private boolean needHandleTableHdfsAcl (TableName tableName , String operation ) throws IOException {
549561 return !tableName .isSystemTable () && checkInitialized (operation ) && hdfsAclHelper
550- .isTableUserScanSnapshotEnabled (masterServices .getTableDescriptors ().get (tableName ));
562+ .isAclSyncToHdfsEnabled (masterServices .getTableDescriptors ().get (tableName ));
551563 }
552564
553565 private boolean needHandleTableHdfsAcl (TableDescriptor tableDescriptor , String operation ) {
554566 TableName tableName = tableDescriptor .getTableName ();
555567 return !tableName .isSystemTable () && checkInitialized (operation )
556- && hdfsAclHelper .isTableUserScanSnapshotEnabled (tableDescriptor );
568+ && hdfsAclHelper .isAclSyncToHdfsEnabled (tableDescriptor );
557569 }
558570
559571 private User getActiveUser (ObserverContext <?> ctx ) throws IOException {
0 commit comments