You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "DanielLeens (via GitHub)" <gi...@apache.org> on 2026/04/20 06:56:10 UTC

Re: [PR] [Improve][Connector-V2][starrocks-source] Improve source not close reader if open failed [seatunnel]

DanielLeens commented on PR #10292:
URL: https://github.com/apache/seatunnel/pull/10292#issuecomment-4278480790

   Hi @LiJie20190102, thanks for the focused fix. I reviewed this locally on branch `seatunnel-review-10292`, with PR head `afcfbd29c4cea81bd60efb98da3b614a59dc5ec9` and merge base `81834f26a7ac2653810b7d07ac512dbfe909b2e2`.
   
   # What This PR Solves
   - User pain point: when StarRocks BE scanner open fails, `contextId` may never be created, but the cleanup path can still try to close a scanner with an invalid/null context and add noisy secondary errors.
   - Fix approach: `StarRocksBeReadClient#close()` now returns early when `contextId == null`, and retries `close_scanner` up to three times when a scanner was opened.
   - One sentence: this makes StarRocks Source cleanup quieter and safer when scanner open fails.
   
   Simple example: if `open_scanner` fails before returning a context id, close now detects that there is no scanner context to close and skips the invalid close call.
   
   # 1. Code Change Review
   
   ## 1.1 Core Logic Analysis
   The runtime path is:
   
   ```text
   Source split assigned to reader
     -> StarRocksSourceReader.pollNext() [StarRocksSourceReader.java:71-86]
         -> read(split, output) [StarRocksSourceReader.java:104-124]
             -> create/reuse StarRocksBeReadClient by beAddress [L109-115]
             -> client.openScanner(partition, rowType) [L118]
                 -> StarRocksBeReadClient.openScanner() [StarRocksBeReadClient.java:92-139]
                     -> client.open_scanner(params)
                     -> contextId is assigned only after success [L127]
             -> while (client.hasNext()) output.collect(row)
   
   Close path
     -> StarRocksSourceReader.close() [StarRocksSourceReader.java:132-147]
         -> client.close()
             -- openScanner never set contextId
                -> return early [StarRocksBeReadClient.java:185-190]
             -- openScanner succeeded
                -> close_scanner(contextId), retry up to 3 times [L191-210]
   ```
   
   Before:
   
   ```java
   TScanCloseParams tScanCloseParams = new TScanCloseParams();
   tScanCloseParams.setContext_id(this.contextId);
   try {
       this.client.close_scanner(tScanCloseParams);
   } catch (TException e) {
       log.error("Failed to close reader {}:{} with context id {}", ip, port, contextId, e);
       throw new StarRocksConnectorException(CLOSE_BE_READER_FAILED, e);
   }
   ```
   
   After:
   
   ```java
   if (contextId == null) {
       return;
   }
   TScanCloseParams tScanCloseParams = new TScanCloseParams();
   tScanCloseParams.setContext_id(this.contextId);
   for (int i = 0; i < 3; i++) {
       try {
           this.client.close_scanner(tScanCloseParams);
           break;
       } catch (Exception e) {
           log.error("Failed to close reader {}:{} with context id {}", ip, port, contextId, e);
       }
       Thread.sleep(1000);
   }
   ```
   
   Key findings:
   - The normal StarRocks Source close path does hit this change.
   - The successful read path, split lifecycle, and checkpoint state are unchanged.
   - This is a precise defensive cleanup fix.
   - No blocking issue was found.
   
   ## 1.2 Compatibility Impact
   Judgment: fully compatible.
   
   No API, config, default value, protocol, or serialization format is changed. Existing successful scanner close still uses the StarRocks Thrift `close_scanner` call.
   
   ## 1.3 Performance / Side Effects
   There is no impact on the hot read path. Only close failures can now retry up to two extra times, with a 1 second sleep between attempts. This is acceptable for cleanup.
   
   ## 1.4 Error Handling And Logs
   The cleanup path is improved, but I found one small follow-up.
   
   Issue 1: Interrupted close retry sleep does not restore the interrupt flag
   - Location: `seatunnel-connectors-v2/connector-starrocks/src/main/java/org/apache/seatunnel/connectors/seatunnel/starrocks/client/source/StarRocksBeReadClient.java:201`
   - Description: when `Thread.sleep(1000)` is interrupted, the code logs the event but does not call `Thread.currentThread().interrupt()` or break out of the retry loop.
   - Risk: task shutdown/cancellation may be slightly less responsive in this rare close-failure path.
   - Suggested fix: restore the interrupt flag and break the retry loop.
   - Severity: Low
   
   # 2. Code Quality
   The patch is small and readable. `git diff --check upstream/dev...HEAD` is clean, and local merge-tree shows no conflict markers. No docs update is needed.
   
   The PR does not add a focused test. A small test for `contextId == null` close behavior would be helpful, but I do not consider it blocking for this defensive cleanup change.
   
   # 3. Architecture
   This is a precise fix at the correct boundary: `contextId` is the signal that the scanner was actually opened. Skipping `close_scanner` before that point avoids a secondary cleanup error.
   
   # 4. Issue Summary
   | # | Issue | Location | Severity |
   |---|---|---|---|
   | 1 | Interrupted close retry sleep does not restore interrupt flag | `StarRocksBeReadClient.java:201` | Low |
   
   # 5. Merge Decision
   ### Conclusion: can merge
   
   Blocking items:
   - None.
   
   Recommended non-blocking follow-up:
   - Issue 1: restore the interrupt flag if close retry sleep is interrupted.
   
   Overall, this is a good defensive fix. It keeps the main StarRocks Source read path unchanged and reduces noisy cleanup behavior after scanner open 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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org