Copilot commented on code in PR #3638:
URL: https://github.com/apache/celeborn/pull/3638#discussion_r3013791318
##########
client/src/test/scala/org/apache/celeborn/client/WorkerStatusTrackerSuite.scala:
##########
@@ -92,6 +94,54 @@ class WorkerStatusTrackerSuite extends CelebornFunSuite {
Assert.assertFalse(statusTracker.excludedWorkers.containsKey(mock("host1")))
}
+ test("concurrent access to shuttingWorkers should not throw
ConcurrentModificationException") {
+ val celebornConf = new CelebornConf()
+ val statusTracker = new WorkerStatusTracker(celebornConf, null)
+ val executor = Executors.newFixedThreadPool(10)
+ val latch = new CountDownLatch(1)
+ val errors = new AtomicInteger(0)
+
+ // Writers: concurrently add and remove workers
+ (1 to 5).foreach { i =>
+ executor.submit(new Runnable {
+ override def run(): Unit = {
+ latch.await()
+ (1 to 1000).foreach { j =>
+ val worker = mock(s"host-$i-$j")
+ statusTracker.shuttingWorkers.add(worker)
+ statusTracker.shuttingWorkers.remove(worker)
+ }
+ }
+ })
+ }
+
+ // Readers: iterate shuttingWorkers via currentFailedWorkers (called
through recordWorkerFailure)
+ (1 to 5).foreach { i =>
+ executor.submit(new Runnable {
+ override def run(): Unit = {
+ try {
+ latch.await()
+ (1 to 1000).foreach { _ =>
+ // Iterate over shuttingWorkers the same way
currentFailedWorkers does
+ statusTracker.shuttingWorkers.forEach(_ => ())
+ }
+ } catch {
+ case _: java.util.ConcurrentModificationException =>
+ errors.incrementAndGet()
+ }
+ }
+ })
+ }
+
+ latch.countDown()
Review Comment:
This test is timing-dependent: even with a non-thread-safe HashSet it may
pass if no modification happens during iteration. To avoid flakiness, consider
coordinating threads so that a modification is guaranteed to occur between
creating an iterator over shuttingWorkers and advancing it (old code should
reliably throw CME; new code should not).
```suggestion
val executor = Executors.newFixedThreadPool(2)
val iterCreatedLatch = new CountDownLatch(1)
val modDoneLatch = new CountDownLatch(1)
val errors = new AtomicInteger(0)
// Pre-populate shuttingWorkers so that the iterator has elements to
traverse
val initialWorker = mock("initial-host")
statusTracker.shuttingWorkers.add(initialWorker)
// Reader: create iterator, then iterate after writer has modified the
set
executor.submit(new Runnable {
override def run(): Unit = {
try {
val it = statusTracker.shuttingWorkers.iterator()
// Signal that the iterator has been created
iterCreatedLatch.countDown()
// Wait for modification to happen while this iterator is "live"
modDoneLatch.await()
while (it.hasNext) {
it.next()
}
} catch {
case _: java.util.ConcurrentModificationException =>
errors.incrementAndGet()
}
}
})
// Writer: wait until iterator is created, then modify shuttingWorkers
executor.submit(new Runnable {
override def run(): Unit = {
// Ensure modification happens after iterator creation
iterCreatedLatch.await()
val worker = mock("writer-host")
statusTracker.shuttingWorkers.add(worker)
statusTracker.shuttingWorkers.remove(worker)
// Signal that modification is complete
modDoneLatch.countDown()
}
})
```
##########
client/src/test/scala/org/apache/celeborn/client/WorkerStatusTrackerSuite.scala:
##########
@@ -92,6 +94,54 @@ class WorkerStatusTrackerSuite extends CelebornFunSuite {
Assert.assertFalse(statusTracker.excludedWorkers.containsKey(mock("host1")))
}
+ test("concurrent access to shuttingWorkers should not throw
ConcurrentModificationException") {
+ val celebornConf = new CelebornConf()
+ val statusTracker = new WorkerStatusTracker(celebornConf, null)
+ val executor = Executors.newFixedThreadPool(10)
+ val latch = new CountDownLatch(1)
+ val errors = new AtomicInteger(0)
+
+ // Writers: concurrently add and remove workers
+ (1 to 5).foreach { i =>
+ executor.submit(new Runnable {
+ override def run(): Unit = {
+ latch.await()
+ (1 to 1000).foreach { j =>
+ val worker = mock(s"host-$i-$j")
+ statusTracker.shuttingWorkers.add(worker)
+ statusTracker.shuttingWorkers.remove(worker)
+ }
+ }
+ })
+ }
+
+ // Readers: iterate shuttingWorkers via currentFailedWorkers (called
through recordWorkerFailure)
+ (1 to 5).foreach { i =>
+ executor.submit(new Runnable {
+ override def run(): Unit = {
+ try {
+ latch.await()
+ (1 to 1000).foreach { _ =>
+ // Iterate over shuttingWorkers the same way
currentFailedWorkers does
Review Comment:
The comment says currentFailedWorkers is exercised “called through
recordWorkerFailure”, but the test iterates shuttingWorkers directly and never
calls recordWorkerFailure/currentFailedWorkers. Please update the comment to
match the actual behavior (or adjust the test to cover the real path).
```suggestion
// Readers: iterate shuttingWorkers directly, mirroring how
currentFailedWorkers iterates it
(1 to 5).foreach { i =>
executor.submit(new Runnable {
override def run(): Unit = {
try {
latch.await()
(1 to 1000).foreach { _ =>
// Iterate over shuttingWorkers in the same way as
currentFailedWorkers
```
##########
client/src/test/scala/org/apache/celeborn/client/WorkerStatusTrackerSuite.scala:
##########
@@ -92,6 +94,54 @@ class WorkerStatusTrackerSuite extends CelebornFunSuite {
Assert.assertFalse(statusTracker.excludedWorkers.containsKey(mock("host1")))
}
+ test("concurrent access to shuttingWorkers should not throw
ConcurrentModificationException") {
+ val celebornConf = new CelebornConf()
+ val statusTracker = new WorkerStatusTracker(celebornConf, null)
+ val executor = Executors.newFixedThreadPool(10)
+ val latch = new CountDownLatch(1)
+ val errors = new AtomicInteger(0)
+
+ // Writers: concurrently add and remove workers
+ (1 to 5).foreach { i =>
+ executor.submit(new Runnable {
+ override def run(): Unit = {
+ latch.await()
+ (1 to 1000).foreach { j =>
Review Comment:
executor.submit(...) returns Futures that are ignored here. Any exception in
writer threads, or any non-CME exception in reader threads, will be captured by
the Future and won’t fail the test, which can hide regressions. Please collect
the Futures and assert successful completion, and shut down the executor in a
finally block (shutdownNow on failure).
--
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]