Copilot commented on code in PR #3739:
URL: https://github.com/apache/celeborn/pull/3739#discussion_r3593187247


##########
client/src/main/scala/org/apache/celeborn/client/ApplicationHeartbeater.scala:
##########
@@ -47,6 +48,13 @@ class ApplicationHeartbeater(
   private var stopped = false
   private val reviseLostShuffles = conf.reviseLostShufflesEnabled
 
+  private val gcOnOverloadEnabled = conf.clientGcOnOverloadEnabled
+  private val gcOnOverloadMinIntervalMs = conf.clientGcOnOverloadMinIntervalMs
+  private val gcOnOverloadMinIntervalNs = gcOnOverloadMinIntervalMs * 1000000L

Review Comment:
   `gcOnOverloadMinIntervalMs * 1000000L` can overflow for large configured 
intervals, which would make the cooldown logic behave incorrectly (potentially 
triggering GC too frequently). Use `TimeUnit.MILLISECONDS.toNanos` to convert 
safely (it saturates on overflow).



##########
client/src/test/scala/org/apache/celeborn/client/ApplicationHeartbeaterSuite.scala:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.celeborn.client
+
+import java.util.concurrent.ConcurrentHashMap
+
+import org.apache.celeborn.CelebornFunSuite
+import org.apache.celeborn.common.CelebornConf
+
+class ApplicationHeartbeaterSuite extends CelebornFunSuite {
+
+  private def makeHeartbeater(
+      gcEnabled: Boolean = true,
+      minIntervalMs: Long = 60000L): ApplicationHeartbeater = {
+    val conf = new CelebornConf()
+    conf.set(CelebornConf.CLIENT_GC_ON_CLUSTER_OVERLOAD_ENABLED, gcEnabled)
+    conf.set(CelebornConf.CLIENT_GC_ON_CLUSTER_OVERLOAD_MIN_INTERVAL, 
minIntervalMs)
+
+    val registeredShuffles = ConcurrentHashMap.newKeySet[Int]()
+      .asInstanceOf[ConcurrentHashMap.KeySetView[Int, java.lang.Boolean]]
+
+    new ApplicationHeartbeater(
+      "test-app",
+      conf,
+      null, // MasterClient not needed for handleGcSignal unit tests
+      () => (0L, 0L) -> (0L, 0L, Map.empty, Map.empty),
+      null, // WorkerStatusTracker not needed
+      registeredShuffles,
+      _ => ())
+  }
+
+  test("GC is not triggered when feature is disabled") {
+    val hb = makeHeartbeater(gcEnabled = false)
+    hb.handleGcSignal(shouldTriggerGc = true)
+    assert(hb.lastGcTriggerTimeNs == 0L)
+  }
+
+  test("GC is not triggered when signal is false") {
+    val hb = makeHeartbeater(gcEnabled = true)
+    hb.handleGcSignal(shouldTriggerGc = false)
+    assert(hb.lastGcTriggerTimeNs == 0L)
+  }
+
+  test("GC is triggered on first signal when enabled") {
+    val hb = makeHeartbeater(gcEnabled = true, minIntervalMs = 0L)
+    val before = System.nanoTime()
+    hb.handleGcSignal(shouldTriggerGc = true)
+    assert(hb.lastGcTriggerTimeNs >= before)
+  }
+
+  test("GC is skipped when called again within the cooldown interval") {
+    val hb = makeHeartbeater(gcEnabled = true, minIntervalMs = 60000L)
+
+    hb.handleGcSignal(shouldTriggerGc = true)
+    val firstTrigger = hb.lastGcTriggerTimeNs
+    assert(firstTrigger > 0L)
+
+    // Second call immediately — well within 60s cooldown
+    hb.handleGcSignal(shouldTriggerGc = true)
+    assert(
+      hb.lastGcTriggerTimeNs == firstTrigger,
+      "lastGcTriggerTimeMs should not change on second call")

Review Comment:
   The assertion message refers to `lastGcTriggerTimeMs`, but the field being 
asserted is `lastGcTriggerTimeNs` (nanoseconds). This makes test failures 
confusing.



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