HDFS-5448. Datanode should generate its ID on first registration

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-2832@1538496 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Arpit Agarwal 2013-11-04 02:13:04 +00:00
parent 7e46025f91
commit 9660bfa84c
4 changed files with 25 additions and 26 deletions

View File

@ -61,4 +61,7 @@ IMPROVEMENTS:
HDFS-5447. Fix TestJspHelper. (Arpit Agarwal) HDFS-5447. Fix TestJspHelper. (Arpit Agarwal)
HDFS-5452. Fix TestReplicationPolicy and TestBlocksScheduledCounter. HDFS-5452. Fix TestReplicationPolicy and TestBlocksScheduledCounter.
(szetszwo)
HDFS-5448. Datanode should generate its ID on first registration. (Arpit
Agarwal)

View File

@ -113,11 +113,6 @@ private String checkDatanodeUuid(String uuid) {
} }
} }
public String generateNewDatanodeUuid() {
datanodeUuid = UUID.randomUUID().toString();
return datanodeUuid;
}
/** /**
* @return ipAddr; * @return ipAddr;
*/ */

View File

@ -845,18 +845,6 @@ nodes with its data cleared (or user can just remove the StorageID
return; return;
} }
// This is a new datanode.
if (nodeReg.getDatanodeUuid() == null ||
nodeReg.getDatanodeUuid().isEmpty()) {
// this data node has never been registered
nodeReg.generateNewDatanodeUuid();
if (NameNode.stateChangeLog.isDebugEnabled()) {
NameNode.stateChangeLog.debug(
"BLOCK* NameSystem.registerDatanode: "
+ "new Datanode UUID " + nodeReg.getDatanodeUuid() + " assigned.");
}
}
DatanodeDescriptor nodeDescr DatanodeDescriptor nodeDescr
= new DatanodeDescriptor(nodeReg, NetworkTopology.DEFAULT_RACK); = new DatanodeDescriptor(nodeReg, NetworkTopology.DEFAULT_RACK);
boolean success = false; boolean success = false;

View File

@ -693,16 +693,35 @@ void startDataNode(Configuration conf,
readaheadPool = ReadaheadPool.getInstance(); readaheadPool = ReadaheadPool.getInstance();
} }
/**
* Verify that the DatanodeUuid has been initialized. If this is a new
* datanode then we generate a new Datanode Uuid and persist it to disk.
*
* @throws IOException
*/
private synchronized void checkDatanodeUuid() throws IOException {
if (storage.getDatanodeUuid() == null) {
storage.setDatanodeUuid(UUID.randomUUID().toString());
storage.writeAll();
LOG.info("Generated and persisted new Datanode UUID " +
storage.getDatanodeUuid());
}
}
/** /**
* Create a DatanodeRegistration for a specific block pool. * Create a DatanodeRegistration for a specific block pool.
* @param nsInfo the namespace info from the first part of the NN handshake * @param nsInfo the namespace info from the first part of the NN handshake
*/ */
DatanodeRegistration createBPRegistration(NamespaceInfo nsInfo) { DatanodeRegistration createBPRegistration(NamespaceInfo nsInfo)
throws IOException {
StorageInfo storageInfo = storage.getBPStorage(nsInfo.getBlockPoolID()); StorageInfo storageInfo = storage.getBPStorage(nsInfo.getBlockPoolID());
if (storageInfo == null) { if (storageInfo == null) {
// it's null in the case of SimulatedDataSet // it's null in the case of SimulatedDataSet
storageInfo = new StorageInfo(nsInfo); storageInfo = new StorageInfo(nsInfo);
} }
checkDatanodeUuid();
DatanodeID dnId = new DatanodeID( DatanodeID dnId = new DatanodeID(
streamingAddr.getAddress().getHostAddress(), hostName, streamingAddr.getAddress().getHostAddress(), hostName,
storage.getDatanodeUuid(), getXferPort(), getInfoPort(), storage.getDatanodeUuid(), getXferPort(), getInfoPort(),
@ -724,13 +743,7 @@ synchronized void bpRegistrationSucceeded(DatanodeRegistration bpRegistration,
id = bpRegistration; id = bpRegistration;
} }
if (storage.getDatanodeUuid() == null) { if(!storage.getDatanodeUuid().equals(bpRegistration.getDatanodeUuid())) {
// This is a fresh datanode, persist the NN-provided Datanode ID
storage.setDatanodeUuid(bpRegistration.getDatanodeUuid());
storage.writeAll();
LOG.info("Datanode ID " + bpRegistration.getDatanodeUuid()
+ " is assigned to new storage " + bpRegistration);
} else if(!storage.getDatanodeUuid().equals(bpRegistration.getDatanodeUuid())) {
throw new IOException("Inconsistent Datanode IDs. Name-node returned " throw new IOException("Inconsistent Datanode IDs. Name-node returned "
+ bpRegistration.getDatanodeUuid() + bpRegistration.getDatanodeUuid()
+ ". Expecting " + storage.getDatanodeUuid()); + ". Expecting " + storage.getDatanodeUuid());