HDFS-12053. Ozone: ozone server should create missing metadata directory if it has permission to. Contributed by Weiwei Yang.
This commit is contained in:
parent
b23b01645b
commit
ebbc04c2d5
@ -128,8 +128,15 @@ public void init(
|
|||||||
readLock();
|
readLock();
|
||||||
try {
|
try {
|
||||||
for (StorageLocation path : containerDirs) {
|
for (StorageLocation path : containerDirs) {
|
||||||
LOG.info("Loading containers under {}", path);
|
|
||||||
File directory = Paths.get(path.getNormalizedUri()).toFile();
|
File directory = Paths.get(path.getNormalizedUri()).toFile();
|
||||||
|
if (!directory.exists() && !directory.mkdirs()) {
|
||||||
|
LOG.error("Container metadata directory doesn't exist "
|
||||||
|
+ "and cannot be created. Path: {}", path.toString());
|
||||||
|
throw new StorageContainerException("Container metadata "
|
||||||
|
+ "directory doesn't exist and cannot be created " + path
|
||||||
|
.toString(), INVALID_CONFIG);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: This will fail if any directory is invalid.
|
// TODO: This will fail if any directory is invalid.
|
||||||
// We should fix this to handle invalid directories and continue.
|
// We should fix this to handle invalid directories and continue.
|
||||||
// Leaving it this way to fail fast for time being.
|
// Leaving it this way to fail fast for time being.
|
||||||
@ -139,6 +146,7 @@ public void init(
|
|||||||
throw new StorageContainerException("Invalid path to container " +
|
throw new StorageContainerException("Invalid path to container " +
|
||||||
"metadata directory." + path, INVALID_CONFIG);
|
"metadata directory." + path, INVALID_CONFIG);
|
||||||
}
|
}
|
||||||
|
LOG.info("Loading containers under {}", path);
|
||||||
File[] files = directory.listFiles(new ContainerFilter());
|
File[] files = directory.listFiles(new ContainerFilter());
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
for (File containerFile : files) {
|
for (File containerFile : files) {
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
import org.apache.hadoop.hdfs.DFSTestUtil;
|
import org.apache.hadoop.hdfs.DFSTestUtil;
|
||||||
import org.apache.hadoop.hdfs.protocol.DatanodeID;
|
import org.apache.hadoop.hdfs.protocol.DatanodeID;
|
||||||
import org.apache.hadoop.ipc.RPC;
|
import org.apache.hadoop.ipc.RPC;
|
||||||
|
import org.apache.hadoop.ozone.OzoneConfigKeys;
|
||||||
import org.apache.hadoop.ozone.container.common.helpers.ContainerUtils;
|
import org.apache.hadoop.ozone.container.common.helpers.ContainerUtils;
|
||||||
import org.apache.hadoop.scm.ScmConfigKeys;
|
import org.apache.hadoop.scm.ScmConfigKeys;
|
||||||
import org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine;
|
import org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine;
|
||||||
@ -70,6 +71,7 @@ public class TestDatanodeStateMachine {
|
|||||||
private List<ScmTestMock> mockServers;
|
private List<ScmTestMock> mockServers;
|
||||||
private ExecutorService executorService;
|
private ExecutorService executorService;
|
||||||
private Configuration conf;
|
private Configuration conf;
|
||||||
|
private File testRoot;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
@ -95,11 +97,14 @@ public void setUp() throws Exception {
|
|||||||
URL p = this.getClass().getResource("");
|
URL p = this.getClass().getResource("");
|
||||||
String path = p.getPath().concat(
|
String path = p.getPath().concat(
|
||||||
TestDatanodeStateMachine.class.getSimpleName());
|
TestDatanodeStateMachine.class.getSimpleName());
|
||||||
File f = new File(path);
|
testRoot = new File(path);
|
||||||
if (!f.mkdirs()) {
|
if (!testRoot.mkdirs()) {
|
||||||
LOG.info("Required directories already exist.");
|
LOG.info("Required directories already exist.");
|
||||||
}
|
}
|
||||||
conf.set(DFS_DATANODE_DATA_DIR_KEY, path);
|
conf.set(DFS_DATANODE_DATA_DIR_KEY,
|
||||||
|
new File(testRoot, "data").getAbsolutePath());
|
||||||
|
conf.set(OzoneConfigKeys.OZONE_CONTAINER_METADATA_DIRS,
|
||||||
|
new File(testRoot, "scm").getAbsolutePath());
|
||||||
path = Paths.get(path.toString(),
|
path = Paths.get(path.toString(),
|
||||||
TestDatanodeStateMachine.class.getSimpleName() + ".id").toString();
|
TestDatanodeStateMachine.class.getSimpleName() + ".id").toString();
|
||||||
conf.set(ScmConfigKeys.OZONE_SCM_DATANODE_ID, path);
|
conf.set(ScmConfigKeys.OZONE_SCM_DATANODE_ID, path);
|
||||||
@ -131,6 +136,8 @@ public void tearDown() throws Exception {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//ignore all execption from the shutdown
|
//ignore all execption from the shutdown
|
||||||
|
} finally {
|
||||||
|
testRoot.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user