xichen01 commented on code in PR #7997:
URL: https://github.com/apache/ozone/pull/7997#discussion_r1997611182
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/SCMNodeManager.java:
##########
@@ -634,9 +634,30 @@ protected void updateDatanodeOpState(DatanodeDetails
reportedDn)
}
}
DatanodeDetails scmDnd = nodeStateManager.getNode(reportedDn);
+ NodeOperationalState oldPersistedOpState = scmDnd.getPersistedOpState();
+ NodeOperationalState newPersistedOpState =
reportedDn.getPersistedOpState();
+
scmDnd.setPersistedOpStateExpiryEpochSec(
reportedDn.getPersistedOpStateExpiryEpochSec());
- scmDnd.setPersistedOpState(reportedDn.getPersistedOpState());
+ scmDnd.setPersistedOpState(newPersistedOpState);
+
+ maybeNotifyReplicationManager(reportedDn, oldPersistedOpState,
newPersistedOpState);
+ }
+
+ private void maybeNotifyReplicationManager(
Review Comment:
We should only notify when current SCM is leader.
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationManager.java:
##########
@@ -1470,5 +1479,31 @@ public boolean hasHealthyPipeline(ContainerInfo
container) {
return false;
}
}
+
+ /**
+ * Notify the ReplicationManager that a node state has changed, which might
+ * require container replication. This will wake up the replication monitor
+ * thread if it's sleeping and there's no active replication work in
progress.
+ *
+ * @return true if the replication monitor was woken up, false otherwise
+ */
+ public synchronized boolean notifyNodeStateChange() {
+ if (!running || serviceStatus == ServiceStatus.PAUSING) {
+ return false;
+ }
+
+ // Only wake up the thread if there's no active replication work
+ // This prevents creating a new replication queue over and over
+ // when multiple nodes change state in quick succession
+ if (getQueue().isEmpty()) {
Review Comment:
We can check `isThreadWaiting` too, only the `wait` thread can be notified.
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationManagerEventHandler.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hdds.scm.container.replication;
+
+import org.apache.hadoop.hdds.protocol.DatanodeDetails;
+import org.apache.hadoop.hdds.server.events.EventHandler;
+import org.apache.hadoop.hdds.server.events.EventPublisher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Handles events related to the ReplicationManager.
+ */
+public class ReplicationManagerEventHandler implements
EventHandler<DatanodeDetails> {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(ReplicationManagerEventHandler.class);
+
+ private final ReplicationManager replicationManager;
+
+ public ReplicationManagerEventHandler(ReplicationManager replicationManager)
{
+ this.replicationManager = replicationManager;
+ }
+
+ @Override
+ public void onMessage(DatanodeDetails datanodeDetails, EventPublisher
eventPublisher) {
Review Comment:
A leader check should be added.
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/DeadNodeHandler.java:
##########
@@ -96,6 +97,11 @@ public void onMessage(final DatanodeDetails datanodeDetails,
if (!nodeManager.getNodeStatus(datanodeDetails).isInMaintenance()) {
removeContainerReplicas(datanodeDetails);
}
+
+ // Notify ReplicationManager
+ LOG.info("Notifying ReplicationManager about dead node: {}",
+ datanodeDetails);
+ publisher.fireEvent(SCMEvents.REPLICATION_MANAGER_NOTIFY,
datanodeDetails);
Review Comment:
We can only notify when this node is not IN_MAINTENANCE status.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]