|
@@ -760,8 +760,11 @@ public class MiniDFSCluster {
|
|
|
|
|
|
if (!federation && nnTopology.countNameNodes() == 1) {
|
|
if (!federation && nnTopology.countNameNodes() == 1) {
|
|
NNConf onlyNN = nnTopology.getOnlyNameNode();
|
|
NNConf onlyNN = nnTopology.getOnlyNameNode();
|
|
- // we only had one NN, set DEFAULT_NAME for it
|
|
|
|
- conf.set(FS_DEFAULT_NAME_KEY, "127.0.0.1:" + onlyNN.getIpcPort());
|
|
|
|
|
|
+ // we only had one NN, set DEFAULT_NAME for it. If not explicitly
|
|
|
|
+ // specified initially, the port will be 0 to make NN bind to any
|
|
|
|
+ // available port. It will be set to the right address after
|
|
|
|
+ // NN is started.
|
|
|
|
+ conf.set(FS_DEFAULT_NAME_KEY, "hdfs://127.0.0.1:" + onlyNN.getIpcPort());
|
|
}
|
|
}
|
|
|
|
|
|
List<String> allNsIds = Lists.newArrayList();
|
|
List<String> allNsIds = Lists.newArrayList();
|
|
@@ -777,6 +780,7 @@ public class MiniDFSCluster {
|
|
int nnCounter = 0;
|
|
int nnCounter = 0;
|
|
for (MiniDFSNNTopology.NSConf nameservice : nnTopology.getNameservices()) {
|
|
for (MiniDFSNNTopology.NSConf nameservice : nnTopology.getNameservices()) {
|
|
String nsId = nameservice.getId();
|
|
String nsId = nameservice.getId();
|
|
|
|
+ String lastDefaultFileSystem = null;
|
|
|
|
|
|
Preconditions.checkArgument(
|
|
Preconditions.checkArgument(
|
|
!federation || nsId != null,
|
|
!federation || nsId != null,
|
|
@@ -860,10 +864,19 @@ public class MiniDFSCluster {
|
|
for (NNConf nn : nameservice.getNNs()) {
|
|
for (NNConf nn : nameservice.getNNs()) {
|
|
initNameNodeConf(conf, nsId, nn.getNnId(), manageNameDfsDirs,
|
|
initNameNodeConf(conf, nsId, nn.getNnId(), manageNameDfsDirs,
|
|
enableManagedDfsDirsRedundancy, nnCounter);
|
|
enableManagedDfsDirsRedundancy, nnCounter);
|
|
- createNameNode(nnCounter++, conf, numDataNodes, false, operation,
|
|
|
|
|
|
+ createNameNode(nnCounter, conf, numDataNodes, false, operation,
|
|
clusterId, nsId, nn.getNnId());
|
|
clusterId, nsId, nn.getNnId());
|
|
|
|
+ // Record the last namenode uri
|
|
|
|
+ if (nameNodes[nnCounter] != null && nameNodes[nnCounter].conf != null) {
|
|
|
|
+ lastDefaultFileSystem =
|
|
|
|
+ nameNodes[nnCounter].conf.get(FS_DEFAULT_NAME_KEY);
|
|
|
|
+ }
|
|
|
|
+ nnCounter++;
|
|
|
|
+ }
|
|
|
|
+ if (!federation && lastDefaultFileSystem != null) {
|
|
|
|
+ // Set the default file system to the actual bind address of NN.
|
|
|
|
+ conf.set(FS_DEFAULT_NAME_KEY, lastDefaultFileSystem);
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -977,7 +990,8 @@ public class MiniDFSCluster {
|
|
operation.setClusterId(clusterId);
|
|
operation.setClusterId(clusterId);
|
|
}
|
|
}
|
|
|
|
|
|
- // Start the NameNode
|
|
|
|
|
|
+ // Start the NameNode after saving the default file system.
|
|
|
|
+ String originalDefaultFs = conf.get(FS_DEFAULT_NAME_KEY);
|
|
String[] args = createArgs(operation);
|
|
String[] args = createArgs(operation);
|
|
NameNode nn = NameNode.createNameNode(args, conf);
|
|
NameNode nn = NameNode.createNameNode(args, conf);
|
|
if (operation == StartupOption.RECOVER) {
|
|
if (operation == StartupOption.RECOVER) {
|
|
@@ -1001,6 +1015,12 @@ public class MiniDFSCluster {
|
|
DFS_NAMENODE_HTTP_ADDRESS_KEY);
|
|
DFS_NAMENODE_HTTP_ADDRESS_KEY);
|
|
nameNodes[nnIndex] = new NameNodeInfo(nn, nameserviceId, nnId,
|
|
nameNodes[nnIndex] = new NameNodeInfo(nn, nameserviceId, nnId,
|
|
operation, new Configuration(conf));
|
|
operation, new Configuration(conf));
|
|
|
|
+ // Restore the default fs name
|
|
|
|
+ if (originalDefaultFs == null) {
|
|
|
|
+ conf.set(FS_DEFAULT_NAME_KEY, "");
|
|
|
|
+ } else {
|
|
|
|
+ conf.set(FS_DEFAULT_NAME_KEY, originalDefaultFs);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|