diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-2832.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-2832.txt index 20ec6aafdd2..74483081067 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-2832.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-2832.txt @@ -61,4 +61,7 @@ IMPROVEMENTS: HDFS-5447. Fix TestJspHelper. (Arpit Agarwal) HDFS-5452. Fix TestReplicationPolicy and TestBlocksScheduledCounter. - (szetszwo) + + HDFS-5448. Datanode should generate its ID on first registration. (Arpit + Agarwal) + diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/DatanodeID.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/DatanodeID.java index b8b84f56662..a00fdf47fab 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/DatanodeID.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/DatanodeID.java @@ -113,11 +113,6 @@ public class DatanodeID implements Comparable { } } - public String generateNewDatanodeUuid() { - datanodeUuid = UUID.randomUUID().toString(); - return datanodeUuid; - } - /** * @return ipAddr; */ diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java index 892caa0c596..ec943a5a094 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java @@ -845,18 +845,6 @@ public class DatanodeManager { 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 = new DatanodeDescriptor(nodeReg, NetworkTopology.DEFAULT_RACK); boolean success = false; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java index a493423695a..fbccecae67f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java @@ -693,16 +693,35 @@ public class DataNode extends Configured 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. * @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()); if (storageInfo == null) { // it's null in the case of SimulatedDataSet storageInfo = new StorageInfo(nsInfo); } + + checkDatanodeUuid(); + DatanodeID dnId = new DatanodeID( streamingAddr.getAddress().getHostAddress(), hostName, storage.getDatanodeUuid(), getXferPort(), getInfoPort(), @@ -724,13 +743,7 @@ public class DataNode extends Configured id = bpRegistration; } - if (storage.getDatanodeUuid() == null) { - // 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())) { + if(!storage.getDatanodeUuid().equals(bpRegistration.getDatanodeUuid())) { throw new IOException("Inconsistent Datanode IDs. Name-node returned " + bpRegistration.getDatanodeUuid() + ". Expecting " + storage.getDatanodeUuid());