rpuch commented on code in PR #6552:
URL: https://github.com/apache/ignite-3/pull/6552#discussion_r2324715338


##########
modules/network/src/main/java/org/apache/ignite/internal/network/netty/InboundRecoveryHandler.java:
##########
@@ -61,15 +81,52 @@ public void channelRead(ChannelHandlerContext ctx, Object 
msg) throws Exception
 
             descriptor.acknowledge(receivedMessages);
         } else if (message.needAck()) {
-            AcknowledgementMessage ackMsg = factory.acknowledgementMessage()
-                    .receivedMessages(descriptor.onReceive()).build();
-
-            ctx.channel().writeAndFlush(new OutNetworkObject(ackMsg, 
Collections.emptyList(), false));
+            sentOrScheduleAcknowledgement(ctx);
         }
 
         super.channelRead(ctx, message);
     }
 
+    /**
+     * Sends or schedules an acknowledgement message based on the received 
message count.
+     *
+     * @param ctx Channel handler context.
+     */
+    private void sentOrScheduleAcknowledgement(ChannelHandlerContext ctx) {
+        long receiveCnt = descriptor.onReceive();
+
+        if (receiveCnt - lastSentReceivedCount > syncAckThreshold) {
+            sentAcknowledgement(ctx, receiveCnt);
+        } else if (scheduleAcknowledgement) {
+            scheduleAcknowledgement = false;
+
+            ctx.channel().eventLoop().schedule(
+                    () -> {
+                        scheduleAcknowledgement = true;
+
+                        sentAcknowledgement(ctx, descriptor.receivedCount());
+                    },
+                    postponeAckMillis,
+                    TimeUnit.MILLISECONDS
+            );
+        }
+    }
+
+    /**
+     * Sends an acknowledgement message with the given received message count.
+     *
+     * @param ctx Channel handler context.
+     * @param receiveCnt Count of received messages to include in the 
acknowledgement.
+     */
+    private void sentAcknowledgement(ChannelHandlerContext ctx, long 
receiveCnt) {

Review Comment:
   ```suggestion
       private void sendAcknowledgement(ChannelHandlerContext ctx, long 
receiveCnt) {
   ```



##########
modules/network/src/main/java/org/apache/ignite/internal/network/configuration/AcknowledgeConfigurationSchema.java:
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.ignite.internal.network.configuration;
+
+import org.apache.ignite.configuration.annotation.Config;
+import org.apache.ignite.configuration.annotation.PublicName;
+import org.apache.ignite.configuration.annotation.Value;
+import org.apache.ignite.configuration.validation.Range;
+
+/**
+ * Configuration schema for acknowledgment settings in the network module.
+ * This class defines the configuration properties related to acknowledgment 
thresholds and delays.
+ */
+@Config
+public class AcknowledgeConfigurationSchema {

Review Comment:
   Please add Javadoc describing both config properties



##########
modules/network/src/main/java/org/apache/ignite/internal/network/netty/InboundRecoveryHandler.java:
##########
@@ -61,15 +81,52 @@ public void channelRead(ChannelHandlerContext ctx, Object 
msg) throws Exception
 
             descriptor.acknowledge(receivedMessages);
         } else if (message.needAck()) {
-            AcknowledgementMessage ackMsg = factory.acknowledgementMessage()
-                    .receivedMessages(descriptor.onReceive()).build();
-
-            ctx.channel().writeAndFlush(new OutNetworkObject(ackMsg, 
Collections.emptyList(), false));
+            sentOrScheduleAcknowledgement(ctx);
         }
 
         super.channelRead(ctx, message);
     }
 
+    /**
+     * Sends or schedules an acknowledgement message based on the received 
message count.
+     *
+     * @param ctx Channel handler context.
+     */
+    private void sentOrScheduleAcknowledgement(ChannelHandlerContext ctx) {

Review Comment:
   ```suggestion
       private void sendOrScheduleAcknowledgement(ChannelHandlerContext ctx) {
   ```



##########
modules/network/src/test/java/org/apache/ignite/internal/network/netty/RecoveryHandshakeTest.java:
##########
@@ -705,8 +718,19 @@ private void exchangeInitiatorToAcceptor(EmbeddedChannel 
acceptorSideChannel, Em
     }
 
     private void runPendingTasks(EmbeddedChannel channel1, EmbeddedChannel 
channel2) {
-        channel1.runPendingTasks();
-        channel2.runPendingTasks();
+        Queue<?> evtLoop1Queue = getFieldValue(channel1.eventLoop(), 
AbstractScheduledEventExecutor.class, "scheduledTaskQueue");
+        Queue<?> evtLoop2Queue = getFieldValue(channel2.eventLoop(), 
AbstractScheduledEventExecutor.class, "scheduledTaskQueue");
+
+        try {
+            IgniteTestUtils.waitForCondition(() -> {

Review Comment:
   Is it intentional that we don't check the return value of 
`waitForCondition()`?



##########
modules/network/src/main/java/org/apache/ignite/internal/network/configuration/AcknowledgeConfigurationSchema.java:
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.ignite.internal.network.configuration;
+
+import org.apache.ignite.configuration.annotation.Config;
+import org.apache.ignite.configuration.annotation.PublicName;
+import org.apache.ignite.configuration.annotation.Value;
+import org.apache.ignite.configuration.validation.Range;
+
+/**
+ * Configuration schema for acknowledgment settings in the network module.
+ * This class defines the configuration properties related to acknowledgment 
thresholds and delays.
+ */
+@Config
+public class AcknowledgeConfigurationSchema {

Review Comment:
   Also, after we finish the review, maybe we should call someone like Pavel 
Tupitsin to take a look at this as this is a public API change



-- 
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]

Reply via email to