This is an automated email from the ASF dual-hosted git repository.

smengcl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new f2195ff720d HDDS-16723. Cap reports per heartbeat to avoid oversized 
datanode heartbeats (#11423)
f2195ff720d is described below

commit f2195ff720d416e219f065d99544554ec4a661ce
Author: hani-fouladgar <[email protected]>
AuthorDate: Tue Nov 3 14:09:13 2026 -0600

    HDDS-16723. Cap reports per heartbeat to avoid oversized datanode 
heartbeats (#11423)
---
 .../org/apache/hadoop/hdds/HddsConfigKeys.java     |  6 ++
 .../common/src/main/resources/ozone-default.xml    | 11 +++
 .../common/statemachine/StateContext.java          | 38 +++++++--
 .../states/endpoint/HeartbeatEndpointTask.java     | 11 ++-
 .../common/statemachine/TestStateContext.java      | 43 ++++++++++
 .../states/endpoint/TestHeartbeatEndpointTask.java | 96 ++++++++++++++++++++++
 6 files changed, 197 insertions(+), 8 deletions(-)

diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsConfigKeys.java 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsConfigKeys.java
index 4804bfdebac..aae7259d813 100644
--- 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsConfigKeys.java
+++ 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsConfigKeys.java
@@ -67,6 +67,12 @@ public final class HddsConfigKeys {
       "hdds.pipeline.action.max.limit";
   public static final int HDDS_PIPELINE_ACTION_MAX_LIMIT_DEFAULT =
       20;
+  // Maximum number of report messages (node, pipeline, command status, full 
and
+  // incremental container reports) a datanode includes in a single heartbeat.
+  public static final String HDDS_HEARTBEAT_REPORT_MAX_LIMIT =
+      "hdds.heartbeat.report.max.limit";
+  public static final int HDDS_HEARTBEAT_REPORT_MAX_LIMIT_DEFAULT =
+      10000;
   // Configuration to allow volume choosing policy.
   public static final String HDDS_DATANODE_VOLUME_CHOOSING_POLICY =
       "hdds.datanode.volume.choosing.policy";
diff --git a/hadoop-hdds/common/src/main/resources/ozone-default.xml 
b/hadoop-hdds/common/src/main/resources/ozone-default.xml
index 7a681646847..19b8bce6b5d 100644
--- a/hadoop-hdds/common/src/main/resources/ozone-default.xml
+++ b/hadoop-hdds/common/src/main/resources/ozone-default.xml
@@ -1845,6 +1845,17 @@
       single heartbeat.
     </description>
   </property>
+  <property>
+    <name>hdds.heartbeat.report.max.limit</name>
+    <value>10000</value>
+    <tag>DATANODE</tag>
+    <description>
+      Maximum number of report messages (not containers) a datanode includes in
+      a single heartbeat to an SCM or Recon endpoint. Reports beyond the limit
+      stay queued and are sent in an immediate follow-up heartbeat. Values 
below
+      1 are treated as 1.
+    </description>
+  </property>
   <property>
     <name>hdds.db.profile</name>
     <value>DISK</value>
diff --git 
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/StateContext.java
 
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/StateContext.java
index 4dcb74b40d5..ae5352169eb 100644
--- 
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/StateContext.java
+++ 
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/StateContext.java
@@ -375,16 +375,40 @@ public void putBackReports(List<Message> reportsToPutBack,
    */
   public List<Message> getAllAvailableReports(
       HostAndPort endpoint) {
-    int maxLimit = Integer.MAX_VALUE;
-    // TODO: It is highly unlikely that we will reach maxLimit for the number
-    //       for the number of reports, specially as it does not apply to the
-    //       number of entries in a report. But if maxLimit is hit, should a
-    //       heartbeat be scheduled ASAP? Should full reports not included be
-    //       dropped? Currently this code will keep the full reports not sent
-    //       and include it in the next heartbeat.
+    return getAllAvailableReportsUpToLimit(endpoint, Integer.MAX_VALUE);
+  }
+
+  /**
+   * Returns up to {@code maxLimit} available reports for the endpoint,
+   * removing them from the queue. Any reports beyond the limit stay queued
+   * and are returned by a later call; callers can use {@link
+   * #hasPendingReports(HostAndPort)} to detect that case and schedule a
+   * follow-up heartbeat.
+   *
+   * @return List of reports
+   */
+  public List<Message> getAllAvailableReports(
+      HostAndPort endpoint, int maxLimit) {
     return getAllAvailableReportsUpToLimit(endpoint, maxLimit);
   }
 
+  /**
+   * Returns true if any reports are still queued for the endpoint.
+   */
+  public boolean hasPendingReports(HostAndPort endpoint) {
+    synchronized (incrementalReportsQueue) {
+      List<Message> reportsForEndpoint = incrementalReportsQueue.get(endpoint);
+      if (reportsForEndpoint != null && !reportsForEndpoint.isEmpty()) {
+        return true;
+      }
+    }
+    Map<String, AtomicBoolean> fullReports =
+        isFullReportReadyToBeSent.get(endpoint);
+    return fullReports != null && fullReports.entrySet().stream()
+        .anyMatch(report -> report.getValue().get()
+            && type2Reports.get(report.getKey()).get() != null);
+  }
+
   /**
    * Gets a point in time snapshot of all containers, any pending incremental
    * container reports (ICR) for containers will be included in this report
diff --git 
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/states/endpoint/HeartbeatEndpointTask.java
 
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/states/endpoint/HeartbeatEndpointTask.java
index c752b6bbc5b..76358e4755c 100644
--- 
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/states/endpoint/HeartbeatEndpointTask.java
+++ 
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/states/endpoint/HeartbeatEndpointTask.java
@@ -21,6 +21,8 @@
 import static 
org.apache.hadoop.hdds.HddsConfigKeys.HDDS_CONTAINER_ACTION_MAX_LIMIT_DEFAULT;
 import static 
org.apache.hadoop.hdds.HddsConfigKeys.HDDS_HEARTBEAT_ADDRESS_REFRESH_MISSED_COUNT_THRESHOLD;
 import static 
org.apache.hadoop.hdds.HddsConfigKeys.HDDS_HEARTBEAT_ADDRESS_REFRESH_MISSED_COUNT_THRESHOLD_DEFAULT;
+import static 
org.apache.hadoop.hdds.HddsConfigKeys.HDDS_HEARTBEAT_REPORT_MAX_LIMIT;
+import static 
org.apache.hadoop.hdds.HddsConfigKeys.HDDS_HEARTBEAT_REPORT_MAX_LIMIT_DEFAULT;
 import static 
org.apache.hadoop.hdds.HddsConfigKeys.HDDS_PIPELINE_ACTION_MAX_LIMIT;
 import static 
org.apache.hadoop.hdds.HddsConfigKeys.HDDS_PIPELINE_ACTION_MAX_LIMIT_DEFAULT;
 import static 
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CLIENT_FAILOVER_RESOLVE_NEEDED_DEFAULT;
@@ -83,6 +85,7 @@ public class HeartbeatEndpointTask
   private StateContext context;
   private int maxContainerActionsPerHB;
   private int maxPipelineActionsPerHB;
+  private int maxReportsPerHB;
   private final DatanodeVersionManager versionManager;
   // Test-only override for the version this datanode advertises to clients; 
null in production.
   private final HDDSVersion testCurrentVersion;
@@ -104,6 +107,8 @@ public HeartbeatEndpointTask(EndpointStateMachine 
rpcEndpoint,
         HDDS_CONTAINER_ACTION_MAX_LIMIT_DEFAULT);
     this.maxPipelineActionsPerHB = conf.getInt(HDDS_PIPELINE_ACTION_MAX_LIMIT,
         HDDS_PIPELINE_ACTION_MAX_LIMIT_DEFAULT);
+    this.maxReportsPerHB = Math.max(1, 
conf.getInt(HDDS_HEARTBEAT_REPORT_MAX_LIMIT,
+        HDDS_HEARTBEAT_REPORT_MAX_LIMIT_DEFAULT));
     this.datanodeDetails = context.getParent().getDatanodeDetails();
     this.versionManager = context.getParent().getVersionManager();
 
@@ -154,6 +159,10 @@ public EndpointStateMachine.EndPointStates call() throws 
Exception {
       processResponse(response, datanodeDetailsProto);
       rpcEndpoint.setLastSuccessfulHeartbeat(ZonedDateTime.now());
       rpcEndpoint.zeroMissedCount();
+      if (context.hasPendingReports(rpcEndpoint.getAddress())) {
+        // addReports was capped at maxReportsPerHB and left reports queued. 
Trigger immediately.
+        context.getParent().setNextHB(Time.monotonicNow());
+      }
     } catch (IOException ex) {
       Preconditions.checkState(requestBuilder != null);
       // put back the reports which failed to be sent
@@ -209,7 +218,7 @@ private void putBackIncrementalReports(
    */
   private void addReports(SCMHeartbeatRequestProto.Builder requestBuilder) {
     for (Message report :
-        context.getAllAvailableReports(rpcEndpoint.getAddress())) {
+        context.getAllAvailableReports(rpcEndpoint.getAddress(), 
maxReportsPerHB)) {
       String reportName = report.getDescriptorForType().getFullName();
       for (Descriptors.FieldDescriptor descriptor :
           SCMHeartbeatRequestProto.getDescriptor().getFields()) {
diff --git 
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/statemachine/TestStateContext.java
 
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/statemachine/TestStateContext.java
index ce0b2420291..249b0ac788c 100644
--- 
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/statemachine/TestStateContext.java
+++ 
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/statemachine/TestStateContext.java
@@ -227,6 +227,49 @@ public void testReportQueueWithAddReports() throws 
IOException {
         StateContext.CONTAINER_REPORTS_PROTO_NAME);
   }
 
+  @Test
+  public void testGetAllAvailableReportsRespectsLimit() throws IOException {
+    StateContext ctx = createSubject();
+    HostAndPort scm1 = new HostAndPort("scm1", 9001);
+    ctx.addEndpoint(scm1);
+
+    // Queue 10 ICRs; no full report is refreshed, so only ICRs are returned.
+    batchAddIncrementalReport(ctx,
+        StateContext.INCREMENTAL_CONTAINER_REPORT_PROTO_NAME, 10);
+
+    // A limited collection returns at most the limit and leaves the rest.
+    assertEquals(4, ctx.getAllAvailableReports(scm1, 4).size());
+    assertTrue(ctx.hasPendingReports(scm1));
+    assertEquals(4, ctx.getAllAvailableReports(scm1, 4).size());
+    assertTrue(ctx.hasPendingReports(scm1));
+    // Last chunk drains the queue.
+    assertEquals(2, ctx.getAllAvailableReports(scm1, 4).size());
+    assertFalse(ctx.hasPendingReports(scm1));
+    assertEquals(0, ctx.getAllAvailableReports(scm1, 4).size());
+  }
+
+  @Test
+  public void testHasPendingReportsWithFullReports() throws IOException {
+    StateContext ctx = createSubject();
+    HostAndPort scm1 = new HostAndPort("scm1", 9001);
+    ctx.addEndpoint(scm1);
+
+    // addEndpoint marks the full-report ready flags true, but no full report
+    // value has been generated yet, so nothing is actually pending.
+    assertFalse(ctx.hasPendingReports(scm1));
+
+    // Generate all three full reports; now values exist and flags are ready.
+    batchRefreshfullReports(ctx, StateContext.CONTAINER_REPORTS_PROTO_NAME, 1);
+    batchRefreshfullReports(ctx, StateContext.NODE_REPORT_PROTO_NAME, 1);
+    batchRefreshfullReports(ctx, StateContext.PIPELINE_REPORTS_PROTO_NAME, 1);
+    assertTrue(ctx.hasPendingReports(scm1));
+
+    // With a cap of one, a heartbeat takes a single full report but the others
+    // stay ready, so a follow-up is still needed.
+    assertEquals(1, ctx.getAllAvailableReports(scm1, 1).size());
+    assertTrue(ctx.hasPendingReports(scm1));
+  }
+
   void batchRefreshfullReports(StateContext ctx, String reportName, int count) 
{
     for (int i = 0; i < count; i++) {
       ctx.refreshFullReport(newMockReport(reportName));
diff --git 
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/states/endpoint/TestHeartbeatEndpointTask.java
 
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/states/endpoint/TestHeartbeatEndpointTask.java
index 18156e9839b..4f90b767cdc 100644
--- 
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/states/endpoint/TestHeartbeatEndpointTask.java
+++ 
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/states/endpoint/TestHeartbeatEndpointTask.java
@@ -18,6 +18,7 @@
 package org.apache.hadoop.ozone.container.common.states.endpoint;
 
 import static java.util.Collections.emptyList;
+import static 
org.apache.hadoop.hdds.HddsConfigKeys.HDDS_HEARTBEAT_REPORT_MAX_LIMIT;
 import static 
org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMCommandProto.Type.reconcileContainerCommand;
 import static 
org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMCommandProto.Type.reconstructECContainersCommand;
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -25,7 +26,10 @@
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyLong;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import com.google.protobuf.UnsafeByteOperations;
@@ -45,6 +49,7 @@
 import 
org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CommandStatusReportsProto;
 import 
org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerAction;
 import 
org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerReportsProto;
+import 
org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.IncrementalContainerReportProto;
 import 
org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.NodeReportProto;
 import 
org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMCommandProto;
 import 
org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMHeartbeatRequestProto;
@@ -62,6 +67,8 @@
 import 
org.apache.hadoop.ozone.protocol.commands.ReconstructECContainersCommand;
 import 
org.apache.hadoop.ozone.protocolPB.StorageContainerDatanodeProtocolClientSideTranslatorPB;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 import org.mockito.ArgumentCaptor;
 
 /**
@@ -397,6 +404,95 @@ public void testheartbeatWithAllReports() throws Exception 
{
     }
   }
 
+  @Test
+  public void testHeartbeatCapsReportsAndSchedulesFollowup() throws Exception {
+    OzoneConfiguration conf = new OzoneConfiguration();
+    conf.setInt(HDDS_HEARTBEAT_REPORT_MAX_LIMIT, 2);
+    DatanodeStateMachine datanodeStateMachine = mockDatanodeStateMachine();
+    StateContext context = new StateContext(conf, DatanodeStates.RUNNING,
+        datanodeStateMachine, "");
+
+    when(datanodeStateMachine.getQueuedCommandCount())
+        .thenReturn(new EnumCounters<>(SCMCommandProto.Type.class));
+
+    StorageContainerDatanodeProtocolClientSideTranslatorPB scm =
+        mock(StorageContainerDatanodeProtocolClientSideTranslatorPB.class);
+    ArgumentCaptor<SCMHeartbeatRequestProto> argument = ArgumentCaptor
+        .forClass(SCMHeartbeatRequestProto.class);
+    when(scm.sendHeartbeat(argument.capture()))
+        .thenAnswer(invocation ->
+            SCMHeartbeatResponseProto.newBuilder()
+                .setDatanodeUUID(
+                    ((SCMHeartbeatRequestProto) invocation.getArgument(0))
+                        .getDatanodeDetails().getUuid())
+                .build());
+
+    HeartbeatEndpointTask endpointTask = getHeartbeatEndpointTask(
+        conf, context, scm);
+    context.addEndpoint(TEST_SCM_ENDPOINT);
+    // Queue more ICRs than the per-heartbeat limit.
+    for (int i = 0; i < 5; i++) {
+      context.addIncrementalReport(
+          IncrementalContainerReportProto.getDefaultInstance());
+    }
+
+    endpointTask.call();
+
+    // Only the capped number of ICRs is sent in this heartbeat.
+    SCMHeartbeatRequestProto heartbeat = argument.getValue();
+    assertEquals(2, heartbeat.getIncrementalContainerReportCount());
+    // The remainder stays queued and a follow-up heartbeat is scheduled now.
+    assertTrue(context.hasPendingReports(TEST_SCM_ENDPOINT));
+    verify(datanodeStateMachine).setNextHB(anyLong());
+
+    // The follow-ups drain the rest; the last one sends 1 ICR and schedules 
nothing.
+    endpointTask.call();
+    endpointTask.call();
+    assertEquals(1, argument.getValue().getIncrementalContainerReportCount());
+    assertFalse(context.hasPendingReports(TEST_SCM_ENDPOINT));
+    verify(datanodeStateMachine, times(2)).setNextHB(anyLong());
+  }
+
+  @ParameterizedTest
+  @ValueSource(ints = {0, -1})
+  public void testHeartbeatClampsNonPositiveReportLimit(int configuredLimit)
+      throws Exception {
+    OzoneConfiguration conf = new OzoneConfiguration();
+    conf.setInt(HDDS_HEARTBEAT_REPORT_MAX_LIMIT, configuredLimit);
+    DatanodeStateMachine datanodeStateMachine = mockDatanodeStateMachine();
+    StateContext context = new StateContext(conf, DatanodeStates.RUNNING,
+        datanodeStateMachine, "");
+
+    when(datanodeStateMachine.getQueuedCommandCount())
+        .thenReturn(new EnumCounters<>(SCMCommandProto.Type.class));
+
+    StorageContainerDatanodeProtocolClientSideTranslatorPB scm =
+        mock(StorageContainerDatanodeProtocolClientSideTranslatorPB.class);
+    ArgumentCaptor<SCMHeartbeatRequestProto> argument = ArgumentCaptor
+        .forClass(SCMHeartbeatRequestProto.class);
+    when(scm.sendHeartbeat(argument.capture()))
+        .thenAnswer(invocation ->
+            SCMHeartbeatResponseProto.newBuilder()
+                .setDatanodeUUID(
+                    ((SCMHeartbeatRequestProto) invocation.getArgument(0))
+                        .getDatanodeDetails().getUuid())
+                .build());
+
+    HeartbeatEndpointTask endpointTask = getHeartbeatEndpointTask(
+        conf, context, scm);
+    context.addEndpoint(TEST_SCM_ENDPOINT);
+    for (int i = 0; i < 3; i++) {
+      context.addIncrementalReport(
+          IncrementalContainerReportProto.getDefaultInstance());
+    }
+
+    // A non-positive configured limit is clamped to 1, so the heartbeat makes
+    // progress (one ICR) rather than sending nothing (0) or throwing (-1).
+    endpointTask.call();
+    assertEquals(1, argument.getValue().getIncrementalContainerReportCount());
+    assertTrue(context.hasPendingReports(TEST_SCM_ENDPOINT));
+  }
+
   @Test
   public void testDatanodeCurrentVersionPassThrough() throws Exception {
     OzoneConfiguration conf = new OzoneConfiguration();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to