Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-12551. Replace dnsToUuidMap with dnsToDnIdMap in SCMNodeManager #8087

Merged
merged 4 commits into from
Mar 16, 2025
Merged
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 @@ -53,6 +53,7 @@
import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.protocol.DatanodeID;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeOperationalState;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeState;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos;
Expand Down Expand Up @@ -126,7 +127,7 @@ public class SCMNodeManager implements NodeManager {
private final NetworkTopology clusterMap;
private final Function<String, String> nodeResolver;
private final boolean useHostname;
private final Map<String, Set<UUID>> dnsToUuidMap = new ConcurrentHashMap<>();
private final Map<String, Set<DatanodeID>> dnsToDnIdMap = new ConcurrentHashMap<>();
private final int numPipelinesPerMetadataVolume;
private final int heavyNodeCriteria;
private final HDDSLayoutVersionManager scmLayoutVersionManager;
Expand All @@ -151,6 +152,7 @@ public class SCMNodeManager implements NodeManager {
* Constructs SCM machine Manager.
*/
public SCMNodeManager(

OzoneConfiguration conf,
SCMStorageConfig scmStorageConfig,
EventPublisher eventPublisher,
Expand Down Expand Up @@ -409,15 +411,15 @@ public RegisteredCommand register(
datanodeDetails.setNetworkLocation(networkLocation);
}

final UUID uuid = datanodeDetails.getUuid();
final DatanodeID dnId = datanodeDetails.getID();
if (!isNodeRegistered(datanodeDetails)) {
try {
clusterMap.add(datanodeDetails);
nodeStateManager.addNode(datanodeDetails, layoutInfo);
// Check that datanode in nodeStateManager has topology parent set
DatanodeDetails dn = nodeStateManager.getNode(datanodeDetails);
Preconditions.checkState(dn.getParent() != null);
addToDnsToUuidMap(uuid, ipAddress, hostName);
addToDnsToDnIdMap(dnId, ipAddress, hostName);
// Updating Node Report, as registration is successful
processNodeReport(datanodeDetails, nodeReport);
LOG.info("Registered datanode: {}", datanodeDetails.toDebugString());
Expand All @@ -435,8 +437,8 @@ public RegisteredCommand register(
// Update datanode if it is registered but the ip or hostname changes
try {
final DatanodeInfo oldNode = nodeStateManager.getNode(datanodeDetails);
if (updateDnsToUuidMap(oldNode.getHostName(), oldNode.getIpAddress(),
hostName, ipAddress, uuid)) {
if (updateDnsToDnIdMap(oldNode.getHostName(), oldNode.getIpAddress(),
hostName, ipAddress, dnId)) {
LOG.info("Updating datanode {} from {} to {}",
datanodeDetails.getUuidString(),
oldNode,
Expand Down Expand Up @@ -472,42 +474,42 @@ public RegisteredCommand register(
* and each host can have multiple addresses,
* this is a many to many mapping.
*
* @param uuid the UUID of the registered node.
* @param datanodeID the DataNodeID of the registered node.
* @param addresses hostname and/or IP of the node
*/
private synchronized void addToDnsToUuidMap(UUID uuid, String... addresses) {
private synchronized void addToDnsToDnIdMap(DatanodeID datanodeID, String... addresses) {
for (String addr : addresses) {
if (!Strings.isNullOrEmpty(addr)) {
dnsToUuidMap.computeIfAbsent(addr, k -> ConcurrentHashMap.newKeySet())
.add(uuid);
dnsToDnIdMap.computeIfAbsent(addr, k -> ConcurrentHashMap.newKeySet())
.add(datanodeID);
}
}
}

private synchronized void removeFromDnsToUuidMap(UUID uuid, String address) {
private synchronized void removeFromDnsToDnIdMap(DatanodeID datanodeID, String address) {
if (address != null) {
Set<UUID> dnSet = dnsToUuidMap.get(address);
if (dnSet != null && dnSet.remove(uuid) && dnSet.isEmpty()) {
dnsToUuidMap.remove(address);
Set<DatanodeID> dnSet = dnsToDnIdMap.get(address);
if (dnSet != null && dnSet.remove(datanodeID) && dnSet.isEmpty()) {
dnsToDnIdMap.remove(address);
}
}
}

private boolean updateDnsToUuidMap(
private boolean updateDnsToDnIdMap(
String oldHostName, String oldIpAddress,
String newHostName, String newIpAddress,
UUID uuid) {
DatanodeID datanodeID) {
final boolean ipChanged = !Objects.equals(oldIpAddress, newIpAddress);
final boolean hostNameChanged = !Objects.equals(oldHostName, newHostName);
if (ipChanged || hostNameChanged) {
synchronized (this) {
if (ipChanged) {
removeFromDnsToUuidMap(uuid, oldIpAddress);
addToDnsToUuidMap(uuid, newIpAddress);
removeFromDnsToDnIdMap(datanodeID, oldIpAddress);
addToDnsToDnIdMap(datanodeID, newIpAddress);
}
if (hostNameChanged) {
removeFromDnsToUuidMap(uuid, oldHostName);
addToDnsToUuidMap(uuid, newHostName);
removeFromDnsToDnIdMap(datanodeID, oldHostName);
addToDnsToDnIdMap(datanodeID, newHostName);
}
}
}
Expand Down Expand Up @@ -1725,24 +1727,28 @@ public DatanodeDetails getNodeByUuid(UUID uuid) {
*/
@Override
public List<DatanodeDetails> getNodesByAddress(String address) {
List<DatanodeDetails> allNodes = getAllNodes();
List<DatanodeDetails> results = new LinkedList<>();
if (Strings.isNullOrEmpty(address)) {
LOG.warn("address is null");
return results;
}
Set<UUID> uuids = dnsToUuidMap.get(address);
if (uuids == null) {
Set<DatanodeID> datanodeIDS = dnsToDnIdMap.get(address);
if (datanodeIDS == null) {
LOG.debug("Cannot find node for address {}", address);
return results;
}

for (UUID uuid : uuids) {
datanodeIDS.forEach(datanodeID -> {
try {
results.add(nodeStateManager.getNode(uuid));
} catch (NodeNotFoundException e) {
LOG.warn("Cannot find node for uuid {}", uuid);
List<DatanodeDetails> datanodeDetails = allNodes.stream().
filter(node -> node.getID().equals(datanodeID)).
collect(Collectors.toList());
results.addAll(datanodeDetails);
} catch (Exception e) {
LOG.warn("Error find node for DataNode ID {}", datanodeID);
}
}
});
return results;
}

Expand Down Expand Up @@ -1845,7 +1851,7 @@ public void removeNode(DatanodeDetails datanodeDetails) throws NodeNotFoundExcep
clusterMap.remove(datanodeDetails);
}
nodeStateManager.removeNode(datanodeDetails);
removeFromDnsToUuidMap(datanodeDetails.getUuid(), datanodeDetails.getIpAddress());
removeFromDnsToDnIdMap(datanodeDetails.getID(), datanodeDetails.getIpAddress());
final List<SCMCommand<?>> cmdList = getCommandQueue(datanodeDetails.getUuid());
LOG.info("Clearing command queue of size {} for DN {}", cmdList.size(), datanodeDetails);
} else {
Expand Down