-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HBASE-22578 HFileCleaner should not delete empty ns/table directories…
… used for user san snapshot feature (#337)
Showing
4 changed files
with
211 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
.../src/main/java/org/apache/hadoop/hbase/security/access/SnapshotScannerHDFSAclCleaner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.hbase.security.access; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FileStatus; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.hbase.HBaseInterfaceAudience; | ||
import org.apache.hadoop.hbase.HConstants; | ||
import org.apache.hadoop.hbase.MetaTableAccessor; | ||
import org.apache.hadoop.hbase.TableName; | ||
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; | ||
import org.apache.hadoop.hbase.master.HMaster; | ||
import org.apache.hadoop.hbase.master.cleaner.BaseHFileCleanerDelegate; | ||
import org.apache.yetus.audience.InterfaceAudience; | ||
import org.apache.yetus.audience.InterfaceStability; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting; | ||
|
||
/** | ||
* Implementation of a file cleaner that checks if a empty directory with no subdirs and subfiles is | ||
* deletable when user scan snapshot feature is enabled | ||
*/ | ||
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG) | ||
@InterfaceStability.Evolving | ||
public class SnapshotScannerHDFSAclCleaner extends BaseHFileCleanerDelegate { | ||
private static final Logger LOG = LoggerFactory.getLogger(SnapshotScannerHDFSAclCleaner.class); | ||
|
||
private HMaster master; | ||
private boolean userScanSnapshotEnabled = false; | ||
|
||
@Override | ||
public void init(Map<String, Object> params) { | ||
if (params != null && params.containsKey(HMaster.MASTER)) { | ||
this.master = (HMaster) params.get(HMaster.MASTER); | ||
} | ||
} | ||
|
||
@Override | ||
public void setConf(Configuration conf) { | ||
super.setConf(conf); | ||
userScanSnapshotEnabled = isUserScanSnapshotEnabled(conf); | ||
} | ||
|
||
@Override | ||
protected boolean isFileDeletable(FileStatus fStat) { | ||
// This plugin does not handle the file deletions, so return true by default | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isEmptyDirDeletable(Path dir) { | ||
if (userScanSnapshotEnabled) { | ||
/* | ||
* If user scan snapshot feature is enabled(see HBASE-21995), then when namespace or table | ||
* exists, the archive namespace or table directories should not be deleted because the HDFS | ||
* acls are set at these directories; the archive data directory should not be deleted because | ||
* the HDFS acls of global permission is set at this directory. | ||
*/ | ||
return isEmptyArchiveDirDeletable(dir); | ||
} | ||
return true; | ||
} | ||
|
||
private boolean isUserScanSnapshotEnabled(Configuration conf) { | ||
String masterCoprocessors = conf.get(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY); | ||
return conf.getBoolean(SnapshotScannerHDFSAclHelper.USER_SCAN_SNAPSHOT_ENABLE, false) | ||
&& masterCoprocessors.contains(SnapshotScannerHDFSAclController.class.getName()) | ||
&& masterCoprocessors.contains(AccessController.class.getName()); | ||
} | ||
|
||
private boolean isEmptyArchiveDirDeletable(Path dir) { | ||
try { | ||
if (isArchiveDataDir(dir)) { | ||
return false; | ||
} else if (isArchiveNamespaceDir(dir) && namespaceExists(dir.getName())) { | ||
return false; | ||
} else if (isArchiveTableDir(dir) | ||
&& tableExists(TableName.valueOf(dir.getParent().getName(), dir.getName()))) { | ||
return false; | ||
} | ||
return true; | ||
} catch (IOException e) { | ||
LOG.warn("Check if empty dir {} is deletable error", dir, e); | ||
return false; | ||
} | ||
} | ||
|
||
@VisibleForTesting | ||
static boolean isArchiveDataDir(Path path) { | ||
if (path != null && path.getName().equals(HConstants.BASE_NAMESPACE_DIR)) { | ||
Path parent = path.getParent(); | ||
return parent != null && parent.getName().equals(HConstants.HFILE_ARCHIVE_DIRECTORY); | ||
} | ||
return false; | ||
} | ||
|
||
@VisibleForTesting | ||
static boolean isArchiveNamespaceDir(Path path) { | ||
return path != null && isArchiveDataDir(path.getParent()); | ||
} | ||
|
||
@VisibleForTesting | ||
static boolean isArchiveTableDir(Path path) { | ||
return path != null && isArchiveNamespaceDir(path.getParent()); | ||
} | ||
|
||
private boolean namespaceExists(String namespace) throws IOException { | ||
return master != null && master.listNamespaces().contains(namespace); | ||
} | ||
|
||
private boolean tableExists(TableName tableName) throws IOException { | ||
return master != null && MetaTableAccessor.tableExists(master.getConnection(), tableName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters