imbajin commented on code in PR #704:
URL: 
https://github.com/apache/incubator-hugegraph-toolchain/pull/704#discussion_r2704454200


##########
hugegraph-loader/src/main/java/org/apache/hugegraph/loader/task/TaskManager.java:
##########
@@ -137,6 +138,9 @@ public void shutdown() {
 
     public void submitBatch(InputStruct struct, ElementMapping mapping,
                             List<Record> batch) {
+        if (this.context.stopped()) {

Review Comment:
   ‼️ **Critical - 竞态条件:停止检查时机过早**
   
   在 `submitBatch` 开头检查 `this.context.stopped()` 存在竞态问题:
   
   **问题场景:**
   1. 线程 A 通过停止检查,开始执行 `batchSemaphore.acquire()`
   2. 线程 B 批量插入失败,调用 `stopLoading()`
   3. 线程 A 在 acquire 后继续提交任务到线程池
   4. 任务仍会被执行,违背了停止加载的意图
   
   **影响:**
   - 停止信号不能立即生效
   - 可能继续消耗资源执行无用任务
   - 用户期望停止但实际仍在运行
   
   **建议修复:**
   1. 在 acquire 成功后再次检查停止状态
   2. 或在 `BatchInsertTask.run()` 开头检查停止状态
   
   ```suggestion
           long start = System.currentTimeMillis();
           try {
               this.batchSemaphore.acquire();
               if (this.context.stopped()) {
                   this.batchSemaphore.release();
                   return;
               }
           } catch (InterruptedException e) {
               throw new LoadException("Interrupted while waiting to submit %s 
batch",
                                       e, mapping.type());
           }
   ```
   
   **需要测试:**
   1. 并发场景:多线程同时提交 batch,其中一个失败触发停止
   2. 验证其他线程能快速感知停止信号并退出
   3. 确认没有任务在停止后仍被提交



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

Reply via email to