Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ boolean leaveSafeMode(boolean force) {
BlockManagerSafeMode.STEP_AWAITING_REPORTED_BLOCKS);
prog.endPhase(Phase.SAFEMODE);
}

namesystem.checkAndProvisionSnapshotTrashRoots();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@
import org.apache.hadoop.hdfs.server.namenode.metrics.ReplicatedBlocksMBean;
import org.apache.hadoop.hdfs.server.protocol.SlowDiskReports;
import org.apache.hadoop.ipc.ObserverRetryOnActiveException;
import org.apache.hadoop.util.Time;
import org.apache.hadoop.util.*;

import static org.apache.hadoop.util.Time.now;
import static org.apache.hadoop.util.Time.monotonicNow;
import static org.apache.hadoop.hdfs.server.namenode.top.metrics.TopMetrics.TOPMETRICS_METRICS_SOURCE_NAME;
Expand Down Expand Up @@ -329,11 +330,6 @@
import org.apache.hadoop.security.token.Token;
import org.apache.hadoop.security.token.TokenIdentifier;
import org.apache.hadoop.security.token.delegation.DelegationKey;
import org.apache.hadoop.util.Daemon;
import org.apache.hadoop.util.DataChecksum;
import org.apache.hadoop.util.ReflectionUtils;
import org.apache.hadoop.util.StringUtils;
import org.apache.hadoop.util.VersionInfo;
import org.apache.log4j.Logger;
import org.apache.log4j.Appender;
import org.apache.log4j.AsyncAppender;
Expand Down Expand Up @@ -8531,25 +8527,37 @@ void checkAccess(String src, FsAction mode) throws IOException {
* Check if snapshot roots are created for all existing snapshottable
* directories. Create them if not.
*/
void checkAndProvisionSnapshotTrashRoots() throws IOException {
SnapshottableDirectoryStatus[] dirStatusList = getSnapshottableDirListing();
if (dirStatusList == null) {
return;
}
for (SnapshottableDirectoryStatus dirStatus : dirStatusList) {
String currDir = dirStatus.getFullPath().toString();
if (!currDir.endsWith(Path.SEPARATOR)) {
currDir += Path.SEPARATOR;
}
String trashPath = currDir + FileSystem.TRASH_PREFIX;
HdfsFileStatus fileStatus = getFileInfo(trashPath, false, false, false);
if (fileStatus == null) {
LOG.info("Trash doesn't exist for snapshottable directory {}. "
+ "Creating trash at {}", currDir, trashPath);
PermissionStatus permissionStatus = new PermissionStatus(getRemoteUser()
.getShortUserName(), null, SHARED_TRASH_PERMISSION);
mkdirs(trashPath, permissionStatus, false);
@Override
public void checkAndProvisionSnapshotTrashRoots() {
if (isSnapshotTrashRootEnabled) {
try {
SnapshottableDirectoryStatus[] dirStatusList =
getSnapshottableDirListing();
if (dirStatusList == null) {
return;
}
for (SnapshottableDirectoryStatus dirStatus : dirStatusList) {
String currDir = dirStatus.getFullPath().toString();
if (!currDir.endsWith(Path.SEPARATOR)) {
currDir += Path.SEPARATOR;
}
String trashPath = currDir + FileSystem.TRASH_PREFIX;
HdfsFileStatus fileStatus = getFileInfo(trashPath, false, false, false);
if (fileStatus == null) {
LOG.info("Trash doesn't exist for snapshottable directory {}. " + "Creating trash at {}", currDir, trashPath);
PermissionStatus permissionStatus =
new PermissionStatus(getRemoteUser().getShortUserName(), null,
SHARED_TRASH_PERMISSION);
mkdirs(trashPath, permissionStatus, false);
}
}
} catch (IOException e) {
final String msg =
"Could not provision Trash directory for existing "
+ "snapshottable directories. Exiting Namenode.";
ExitUtil.terminate(1, msg);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pro: Terminating NN in this case is a sure good way of uncovering an unexpected problems instead of hiding it in the logs.

Con: I wonder if we really should terminate NN when Trash directory fails to be deployed. We could just throw a warning message?

Either way, I'm fine with both. Just a thought.

}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2011,9 +2011,6 @@ public HAState getState() {
public void startActiveServices() throws IOException {
try {
namesystem.startActiveServices();
if (namesystem.isSnapshotTrashRootEnabled()) {
namesystem.checkAndProvisionSnapshotTrashRoots();
}
startTrashEmptier(getConf());
} catch (Throwable t) {
doImmediateShutdown(t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
/** Namesystem operations. */
@InterfaceAudience.Private
public interface Namesystem extends RwLock, SafeMode {
/** Is this name system running? */
/**
* Is this name system running?
*/
boolean isRunning();

BlockCollection getBlockCollection(long id);
Expand Down Expand Up @@ -55,4 +57,10 @@ public interface Namesystem extends RwLock, SafeMode {
* @throws IOException
*/
void removeXattr(long id, String xattrName) throws IOException;

/**
* Check if snapshot roots are created for all existing snapshottable
* directories. Create them if not.
*/
void checkAndProvisionSnapshotTrashRoots();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2524,7 +2524,7 @@ public void testNameNodeCreateSnapshotTrashRootOnStartup()
MiniDFSCluster cluster =
new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
try {
final DistributedFileSystem dfs = cluster.getFileSystem();
DistributedFileSystem dfs = cluster.getFileSystem();
final Path testDir = new Path("/disallowss/test2/");
final Path file0path = new Path(testDir, "file-0");
dfs.create(file0path).close();
Expand All @@ -2535,7 +2535,20 @@ public void testNameNodeCreateSnapshotTrashRootOnStartup()
// Set dfs.namenode.snapshot.trashroot.enabled=true
conf.setBoolean("dfs.namenode.snapshot.trashroot.enabled", true);
cluster.setNameNodeConf(0, conf);
cluster.shutdown();
conf.setInt(DFSConfigKeys.DFS_NAMENODE_SAFEMODE_EXTENSION_KEY, 0);
conf.setInt(DFSConfigKeys.DFS_NAMENODE_SAFEMODE_MIN_DATANODES_KEY, 1);
cluster.restartNameNode(0);
dfs = cluster.getFileSystem();
assertTrue(cluster.getNameNode().isInSafeMode());
// Check .Trash existence, won't be created now
assertFalse(dfs.exists(trashRoot));
// Start a datanode
cluster.startDataNodes(conf, 1, true, null, null);
// Wait long enough for safemode check to retire
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {}
// Check .Trash existence, should be created now
assertTrue(dfs.exists(trashRoot));
// Check permission
Expand All @@ -2553,4 +2566,6 @@ public void testNameNodeCreateSnapshotTrashRootOnStartup()
}
}
}


}