You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "Davis-Zhang-Onehouse (via GitHub)" <gi...@apache.org> on 2026/07/28 23:56:40 UTC

[PR] perf(ingest): parallelize SQS receive and delete in the S3 events source [hudi]

Davis-Zhang-Onehouse opened a new pull request, #19396:
URL: https://github.com/apache/hudi/pull/19396

   ## What
   
   `S3EventsSource` drains its SQS queue serially, 10 messages at a time, for both receive and delete. `ReceiveMessage` and `DeleteMessageBatch` are capped by SQS at 10 entries per call, so draining a backlog is dominated by round-trip latency and concurrency is the only available lever. This fans both phases out across a shared bounded thread pool.
   
   ## Continuous dispatch rather than waves
   
   Calls are dispatched through an `ExecutorCompletionService`: the coordinating thread consumes each completion as it arrives and immediately refills the freed slot. The obvious alternative — `invokeAll` over a batch of calls in a loop — is a barrier, so each wave costs `max(latency)` rather than `avg(latency)`, and no worker starts its next call until the slowest sibling returns. All counters and termination state stay on the coordinating thread, so nothing is shared with the workers beyond a timing accumulator.
   
   Admission credits each in-flight call with a full `maxMessagesPerRequest`, so a call is never dispatched that the messages already in flight would make redundant. That bounds overshoot of `maxMessagePerBatch` to `maxMessagesPerRequest - 1`.
   
   ## Drain detection scaled to poll cost
   
   The previous loop ended the entire batch on the first empty response. AWS documents that as unreliable:
   
   > In rare cases, you might receive empty responses even when a queue still contains messages, especially if you specified a low value for the `WaitTimeSeconds` parameter.
   
   It is also the expensive case. Under long polling:
   
   > ReceiveMessage queries all servers for messages, sending a response once at least one message is available, up to the specified maximum. An empty response is sent only if the polling wait time expires.
   
   So an empty response costs a full `WaitTimeSeconds` (20 s at the maximum), while a non-empty one returns as soon as a message is available. Requiring however many empty responses fit in one ~20 s window bounds drain confirmation to roughly a single poll window at any setting, with no timer and nothing to abort mid-flight:
   
   | `WaitTimeSeconds` | empty responses required |
   |---|---|
   | 20 (AWS maximum) | 1 |
   | 10 | 2 |
   | 5 | 4 |
   | 1 | 20 |
   | 0 (short poll) | 5 |
   
   Short polling samples only a subset of servers, so its empty responses are weak evidence but nearly free — hence the higher fixed count there. Empty responses are counted as a batch total rather than consecutively, since resetting the count on a stray message lets a queue with slow ingress hold the phase for its entire call budget.
   
   Confirming a drain early never drops messages; whatever is not received stays in the queue for the next batch.
   
   ## Failure classification
   
   SQS status codes do not track severity — `RequestThrottled` and `OverLimit` are both HTTP 400, `ThrottlingException` is 403, `MalformedQueryString` is 404 — so failures are classified by error code, with the HTTP status used only as a fallback for codes that are not recognised (an unknown 5xx is transient, an unknown 4xx is not). `AwsErrorCode.THROTTLING_ERROR_CODES` omits `KmsThrottled`, which is therefore covered explicitly.
   
   `OverLimit` (the in-flight message ceiling) is treated as backpressure rather than an error: it stops dispatch and returns what was fetched, since the received messages become deletable once the batch commits, which is what frees the quota. Failing the job over normal saturation would be worse than pausing. Non-retryable failures stop at the first occurrence instead of consuming the retry budget on a condition no retry can fix.
   
   Calls already in flight when dispatch stops are drained and their messages kept, never cancelled — a `ReceiveMessage` that succeeded server-side has already made those messages invisible, so discarding the response would strand them for the full visibility timeout. For the same reason an empty result only surfaces as an error when nothing at all proved the queue reachable; a successful response, or an `OverLimit` returned by SQS itself, is evidence the endpoint, credentials and queue are healthy.
   
   ## Delete
   
   Partial failures are aggregated across all batches and retried with exponential backoff, since undeleted messages stay in flight, consume the in-flight quota, and are redelivered once the visibility timeout expires. Entries SQS marks `senderFault` are set aside rather than retried, as no retry can fix them. Failures that a retry genuinely cannot help — a deleted queue, revoked credentials — stop dispatch instead of being retried across every remaining batch.
   
   A synthetic per-entry id (the batch-local index) replaces the message id, so duplicate message ids within a batch under at-least-once delivery cannot collide and cause SQS to reject the whole batch. The id doubles as the reverse lookup, so no map is needed.
   
   Deletes remain in `Source.onCommit`. Deleting inside the receive loop would lift the in-flight ceiling but would break the coupling between message deletion and the commit that consumed those messages.
   
   ## Config
   
   New: `hoodie.streamer.s3.source.queue.processing.parallelism` (default 16). Set to 1 for the previous fully sequential behaviour.
   
   The shared `SqsClient` is thread-safe and intended to be shared. Its HTTP connection pool must be at least the worker count or workers block on connection acquisition; the SDK's default sync pool (`maxConnections=50`) already covers any value up to 50, so only a larger value causes the source to resize the pool.
   
   ## Testing
   
   `TestCloudObjectsSelector` 50/50, plus `TestS3EventsMetaSelector` and `TestS3EventsSource`.
   
   Covers concurrent receive and delete (every message fetched exactly once across 8 workers), the drain-count table, a spurious empty response not truncating a batch, overshoot bounded by in-flight accounting, each failure class end to end (transient tolerated, non-retryable failing fast, `OverLimit` returning cleanly), the classifier itself, and `Error` propagation.
   
   Two tests are regression detectors rather than plain assertions:
   
   - one holds a single call until its siblings have completed several further calls between them, so a return to wave-based dispatch fails the test rather than passing quietly;
   - one pins the deliberate short-poll trade-off, so a change to how empty responses are counted cannot alter it silently.
   


-- 
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@hudi.apache.org

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


Re: [PR] perf(ingest): parallelize SQS receive and delete in the S3 events source [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19396:
URL: https://github.com/apache/hudi/pull/19396#issuecomment-5111878616

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "aa531689bdcec179c432c6759a640c2faf49a7a9",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=15790",
       "triggerID" : "aa531689bdcec179c432c6759a640c2faf49a7a9",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * aa531689bdcec179c432c6759a640c2faf49a7a9 Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=15790) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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@hudi.apache.org

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


Re: [PR] perf(ingest): parallelize SQS receive and delete in the S3 events source [hudi]

Posted by "voonhous (via GitHub)" <gi...@apache.org>.
voonhous merged PR #19396:
URL: https://github.com/apache/hudi/pull/19396


-- 
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@hudi.apache.org

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


Re: [PR] perf(ingest): parallelize SQS receive and delete in the S3 events source [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19396:
URL: https://github.com/apache/hudi/pull/19396#issuecomment-5111123224

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "aa531689bdcec179c432c6759a640c2faf49a7a9",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=15790",
       "triggerID" : "aa531689bdcec179c432c6759a640c2faf49a7a9",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * aa531689bdcec179c432c6759a640c2faf49a7a9 Azure: [PENDING](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=15790) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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@hudi.apache.org

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


Re: [PR] perf(ingest): parallelize SQS receive and delete in the S3 events source [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19396:
URL: https://github.com/apache/hudi/pull/19396#issuecomment-5135690708

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "aa531689bdcec179c432c6759a640c2faf49a7a9",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=15790",
       "triggerID" : "aa531689bdcec179c432c6759a640c2faf49a7a9",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dd59373400cac8b9d5248d2f81d20bc89b1c943d",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "dd59373400cac8b9d5248d2f81d20bc89b1c943d",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * aa531689bdcec179c432c6759a640c2faf49a7a9 Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=15790) 
   * dd59373400cac8b9d5248d2f81d20bc89b1c943d UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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@hudi.apache.org

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


Re: [PR] perf(ingest): parallelize SQS receive and delete in the S3 events source [hudi]

Posted by "Davis-Zhang-Onehouse (via GitHub)" <gi...@apache.org>.
Davis-Zhang-Onehouse closed pull request #19396: perf(ingest): parallelize SQS receive and delete in the S3 events source
URL: https://github.com/apache/hudi/pull/19396


-- 
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@hudi.apache.org

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


Re: [PR] perf(ingest): parallelize SQS receive and delete in the S3 events source [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19396:
URL: https://github.com/apache/hudi/pull/19396#issuecomment-5111091152

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "aa531689bdcec179c432c6759a640c2faf49a7a9",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "aa531689bdcec179c432c6759a640c2faf49a7a9",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * aa531689bdcec179c432c6759a640c2faf49a7a9 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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@hudi.apache.org

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


Re: [PR] perf(ingest): parallelize SQS receive and delete in the S3 events source [hudi]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #19396:
URL: https://github.com/apache/hudi/pull/19396#issuecomment-5111166638

   ## [Codecov](https://app.codecov.io/gh/apache/hudi/pull/19396?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 72.49%. Comparing base ([`8e18999`](https://app.codecov.io/gh/apache/hudi/commit/8e18999a41645d4ae2fb240361615ae2430880c9?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`aa53168`](https://app.codecov.io/gh/apache/hudi/commit/aa531689bdcec179c432c6759a640c2faf49a7a9?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #19396      +/-   ##
   ============================================
   - Coverage     72.49%   72.49%   -0.01%     
   + Complexity    32888    32884       -4     
   ============================================
     Files          2574     2574              
     Lines        149010   148976      -34     
     Branches      18749    18744       -5     
   ============================================
   - Hits         108032   108007      -25     
   + Misses        32513    32508       -5     
   + Partials       8465     8461       -4     
   ```
   
   | [Components](https://app.codecov.io/gh/apache/hudi/pull/19396/components?src=pr&el=components&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [hudi-common](https://app.codecov.io/gh/apache/hudi/pull/19396/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `82.24% <ø> (ø)` | |
   | [hudi-client](https://app.codecov.io/gh/apache/hudi/pull/19396/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `81.79% <ø> (+<0.01%)` | :arrow_up: |
   | [hudi-flink](https://app.codecov.io/gh/apache/hudi/pull/19396/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `78.62% <ø> (ø)` | |
   | [hudi-spark-datasource](https://app.codecov.io/gh/apache/hudi/pull/19396/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `58.67% <ø> (ø)` | |
   | [hudi-utilities](https://app.codecov.io/gh/apache/hudi/pull/19396/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `71.19% <ø> (-0.03%)` | :arrow_down: |
   | [hudi-cli](https://app.codecov.io/gh/apache/hudi/pull/19396/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `15.32% <ø> (ø)` | |
   | [hudi-hadoop](https://app.codecov.io/gh/apache/hudi/pull/19396/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `63.49% <ø> (ø)` | |
   | [hudi-sync](https://app.codecov.io/gh/apache/hudi/pull/19396/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `70.62% <ø> (ø)` | |
   | [hudi-io](https://app.codecov.io/gh/apache/hudi/pull/19396/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `79.57% <ø> (ø)` | |
   | [hudi-timeline-service](https://app.codecov.io/gh/apache/hudi/pull/19396/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `83.44% <ø> (ø)` | |
   | [hudi-cloud](https://app.codecov.io/gh/apache/hudi/pull/19396/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `64.00% <ø> (ø)` | |
   | [hudi-kafka-connect](https://app.codecov.io/gh/apache/hudi/pull/19396/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `53.96% <ø> (ø)` | |
   
   | [Flag](https://app.codecov.io/gh/apache/hudi/pull/19396/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [hadoop-mr-java-client](https://app.codecov.io/gh/apache/hudi/pull/19396/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `43.38% <ø> (ø)` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/hudi/pull/19396?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [...g/apache/hudi/utilities/config/S3SourceConfig.java](https://app.codecov.io/gh/apache/hudi/pull/19396?src=pr&el=tree&filepath=hudi-utilities%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fhudi%2Futilities%2Fconfig%2FS3SourceConfig.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aHVkaS11dGlsaXRpZXMvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1ZGkvdXRpbGl0aWVzL2NvbmZpZy9TM1NvdXJjZUNvbmZpZy5qYXZh) | `97.56% <ø> (-0.06%)` | :arrow_down: |
   | [...tilities/sources/helpers/CloudObjectsSelector.java](https://app.codecov.io/gh/apache/hudi/pull/19396?src=pr&el=tree&filepath=hudi-utilities%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fhudi%2Futilities%2Fsources%2Fhelpers%2FCloudObjectsSelector.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aHVkaS11dGlsaXRpZXMvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1ZGkvdXRpbGl0aWVzL3NvdXJjZXMvaGVscGVycy9DbG91ZE9iamVjdHNTZWxlY3Rvci5qYXZh) | `80.55% <ø> (+0.55%)` | :arrow_up: |
   
   ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/apache/hudi/pull/19396/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   </details>
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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@hudi.apache.org

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


Re: [PR] perf(ingest): parallelize SQS receive and delete in the S3 events source [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19396:
URL: https://github.com/apache/hudi/pull/19396#issuecomment-5135744048

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "aa531689bdcec179c432c6759a640c2faf49a7a9",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=15790",
       "triggerID" : "aa531689bdcec179c432c6759a640c2faf49a7a9",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dd59373400cac8b9d5248d2f81d20bc89b1c943d",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=15867",
       "triggerID" : "dd59373400cac8b9d5248d2f81d20bc89b1c943d",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * aa531689bdcec179c432c6759a640c2faf49a7a9 Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=15790) 
   * dd59373400cac8b9d5248d2f81d20bc89b1c943d Azure: [PENDING](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=15867) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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@hudi.apache.org

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


Re: [PR] perf(ingest): parallelize SQS receive and delete in the S3 events source [hudi]

Posted by "hudi-agent (via GitHub)" <gi...@apache.org>.
hudi-agent commented on code in PR #19396:
URL: https://github.com/apache/hudi/pull/19396#discussion_r3686693236


##########
hudi-utilities/src/main/java/org/apache/hudi/utilities/config/S3SourceConfig.java:
##########
@@ -90,4 +96,18 @@ public class S3SourceConfig extends HoodieConfig {
       .markAdvanced()
       .withDocumentation("Visibility timeout for messages in queue. After we consume the message, queue will move the consumed "
           + "messages to in-flight state, these messages can't be consumed again by source for this timeout period.");
+
+  public static final ConfigProperty<Integer> S3_SOURCE_QUEUE_PROCESSING_PARALLELISM = ConfigProperty
+      .key(S3_SOURCE_PREFIX + "queue.processing.parallelism")
+      .defaultValue(16)

Review Comment:
   🤖 The default here is 16, so every existing `S3EventsSource` deployment flips from serial to 16-way concurrent SQS calls on upgrade rather than opting in. The design does mitigate this well — worker count is `min(parallelism, plannedReceiveCalls)` so idle/small queues stay effectively serial, and the SDK's default pool of 50 covers 16 — but was a non-1 default intended for all existing users here, or would defaulting to 1 (preserve today's behaviour, let operators opt into the speedup) be the safer rollout? @yihua does the ingestion behaviour change on upgrade seem acceptable to you?
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub>



##########
hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/helpers/CloudObjectsSelector.java:
##########
@@ -197,48 +789,452 @@ protected List<List<MessageTracker>> createListPartitions(List<MessageTracker> s
   }
 
   /**
-   * Delete batch of messages from queue.
+   * Deletes one batch (at most {@value #SQS_BATCH_MAX_ENTRIES} entries, the SQS API cap) of messages
+   * and returns the trackers SQS reported as failed, so the caller can retry them. DeleteMessageBatch
+   * can return partial failures even on an HTTP 200, and undeleted messages stay in-flight and are
+   * redelivered once the visibility timeout expires, so failures must be surfaced rather than only
+   * counted.
+   *
+   * <p>A synthetic per-entry id (the batch-local index) is used instead of the message id: the id
+   * only has to be unique within the batch, and under at-least-once delivery the same message id can
+   * appear twice, which would otherwise collide and make SQS reject the whole batch.
    */
-  protected void deleteBatchOfMessages(SqsClient sqs, String queueUrl, List<MessageTracker> messagesToBeDeleted) {
+  protected List<FailedDelete> deleteBatchOfMessages(SqsClient sqs, String queueUrl, List<MessageTracker> messagesToBeDeleted) {
     if (messagesToBeDeleted.isEmpty()) {
-      return;
+      return Collections.emptyList();
     }
-    DeleteMessageBatchRequest.Builder builder = DeleteMessageBatchRequest.builder().queueUrl(queueUrl);
-    List<DeleteMessageBatchRequestEntry> deleteEntries = new ArrayList<>();
-
-    for (MessageTracker message : messagesToBeDeleted) {
+    ValidationUtils.checkArgument(messagesToBeDeleted.size() <= SQS_BATCH_MAX_ENTRIES,
+        "DeleteMessageBatch accepts at most " + SQS_BATCH_MAX_ENTRIES + " entries per call, got "
+            + messagesToBeDeleted.size());
+    List<DeleteMessageBatchRequestEntry> deleteEntries = new ArrayList<>(messagesToBeDeleted.size());
+    for (int i = 0; i < messagesToBeDeleted.size(); i++) {
       deleteEntries.add(
           DeleteMessageBatchRequestEntry.builder()
-                  .id(message.messageId)
-                  .receiptHandle(message.receiptHandle)
+                  .id(String.valueOf(i))
+                  .receiptHandle(messagesToBeDeleted.get(i).receiptHandle)
                   .build());
     }
-    builder.entries(deleteEntries);
-    DeleteMessageBatchResponse deleteResponse = sqs.deleteMessageBatch(builder.build());
-    List<String> deleteFailures =
-        deleteResponse.failed().stream()
-            .map(BatchResultErrorEntry::id)
-            .collect(Collectors.toList());
-    if (!deleteFailures.isEmpty()) {
-      log.warn(
-          "Failed to delete {} messages out of {} from queue.", deleteFailures.size(), deleteEntries.size());
-    } else {
+    DeleteMessageBatchResponse deleteResponse = sqs.deleteMessageBatch(
+        DeleteMessageBatchRequest.builder().queueUrl(queueUrl).entries(deleteEntries).build());
+    if (deleteResponse.failed().isEmpty()) {
       log.debug("Successfully deleted {} messages from queue.", deleteEntries.size());
+      return Collections.emptyList();
+    }
+    // Keep the SQS-provided reason (code + senderFault) with each failed tracker so the caller can log
+    // why deletion failed once at the end rather than per batch.
+    List<FailedDelete> failed = new ArrayList<>(deleteResponse.failed().size());
+    for (BatchResultErrorEntry error : deleteResponse.failed()) {
+      MessageTracker tracker = trackerForEntryId(messagesToBeDeleted, error.id());
+      if (tracker == null) {
+        // SQS echoed an entry id that was never sent (ids are batch-local indices assigned just above, so
+        // this is a protocol violation rather than something that happens in practice). The failure cannot
+        // be attributed to a message: there is no receipt handle to retry with, and it cannot be added to
+        // the residual set either, since that set is counted against processedMessages to derive the
+        // deleted total and a phantom entry would corrupt it. So it is reported here and nowhere else -
+        // meaning the summary's deleted count is an upper bound whenever this WARN fires. The affected
+        // message stays in-flight and is redelivered after the visibility timeout regardless.
+        log.warn("SQS reported a delete failure for unknown entry id \"{}\" on queue {} (code={}); it cannot be "
+            + "mapped back to a message, so that message's deletion status is unknown and the deleted count "
+            + "below may over-count by one.",
+            error.id(), queueUrl, error.code());
+        continue;
+      }
+      failed.add(FailedDelete.reported(tracker, error));
+    }
+    // Per-batch detail at DEBUG only; residual failures are summarized once at WARN in
+    // deleteProcessedMessages so a transient blip across many batches does not flood the logs.
+    log.debug("Failed to delete {} messages out of {} from queue {}.", failed.size(), deleteEntries.size(), queueUrl);
+    return failed;
+  }
+
+  /**
+   * Resolves an entry id assigned by {@link #deleteBatchOfMessages} back to its message. The id is the
+   * batch-local index, so no lookup map is needed. Returns {@code null} when SQS echoes an id that was
+   * never sent (non-numeric or out of range), which the caller reports rather than ignores.
+   */
+  private static MessageTracker trackerForEntryId(List<MessageTracker> batch, String entryId) {
+    try {
+      int index = Integer.parseInt(entryId);
+      return index >= 0 && index < batch.size() ? batch.get(index) : null;
+    } catch (NumberFormatException e) {
+      return null;
     }
   }
 
   /**
    * Delete Queue Messages after hudi commit. This method will be invoked by source.onCommit.
+   * Deletes run concurrently across a fixed pool of up to {@link #processingParallelism} threads;
+   * batches that fail - whether SQS reported the entry as failed on an HTTP 200 or the call threw
+   * outright - are collected across all batches and retried up to {@value #DELETE_MAX_RETRIES} times
+   * with exponential backoff, since undeleted messages stay in-flight, consume the in-flight quota, and
+   * are redelivered once the visibility timeout expires. Any residual failures after the retries are
+   * logged with their reason (see {@link #logDeleteFailures}).
+   *
+   * <p>A failed delete is deliberately not fatal. This runs from {@code Source.onCommit}, which
+   * StreamSync calls <em>after</em> the Hudi commit has already landed, and HoodieStreamer turns any
+   * exception out of the sync round into a job shutdown - so aborting here on one throttled call would
+   * take ingestion down over a condition SQS itself recovers from by redelivering. The one exception is
+   * a systemic failure: if calls were throwing and not a single message could be deleted, that is a
+   * queue/credential/network problem rather than stale individual entries, and it is surfaced.
    */
   public void deleteProcessedMessages(SqsClient sqs, String queueUrl, List<MessageTracker> processedMessages) {
-    if (!processedMessages.isEmpty()) {
-      // create batch for deletion, SES DeleteMessageBatchRequest only accept max 10 entries
-      List<List<MessageTracker>> deleteBatches = createListPartitions(processedMessages, 10);
-      for (List<MessageTracker> deleteBatch : deleteBatches) {
-        deleteBatchOfMessages(sqs, queueUrl, deleteBatch);
+    if (processedMessages.isEmpty()) {
+      return;
+    }
+    long startMs = System.currentTimeMillis();
+    // create batch for deletion, DeleteMessageBatchRequest only accepts max SQS_BATCH_MAX_ENTRIES entries
+    List<List<MessageTracker>> deleteBatches = createListPartitions(processedMessages, SQS_BATCH_MAX_ENTRIES);
+    int totalBatches = deleteBatches.size();
+    int workers = Math.max(1, Math.min(processingParallelism, totalBatches));
+    AtomicLong busyNanos = new AtomicLong();
+    ExecutorService pool = newFixedThreadPool(DELETE_THREAD_PREFIX, workers);
+    // Failures SQS attributes to this caller (senderFault=true, e.g. ReceiptHandleIsInvalid once the
+    // visibility timeout has expired) cannot succeed on a retry, so they are set aside by the pass that
+    // reported them instead of consuming the retry budget - and are still reported at the end.
+    List<FailedDelete> permanentFailures = new ArrayList<>();
+    DeleteStats stats = new DeleteStats();
+    int retries = 0;
+    try {
+      DeletePass pass = deleteBatchesConcurrently(pool, sqs, queueUrl, deleteBatches, workers, busyNanos);
+      stats.add(pass);
+      List<FailedDelete> retryable = splitOffPermanentFailures(pass, permanentFailures);
+      while (!retryable.isEmpty() && retries < DELETE_MAX_RETRIES) {
+        retries++;
+        long backoffMs = sleepBeforeDeleteRetry(queueUrl, retryable.size(), retries);
+        List<MessageTracker> retryTrackers =
+            retryable.stream().map(failedDelete -> failedDelete.message).collect(Collectors.toList());
+        pass = deleteBatchesConcurrently(pool, sqs, queueUrl,
+            createListPartitions(retryTrackers, SQS_BATCH_MAX_ENTRIES), workers, busyNanos);
+        stats.add(pass);
+        retryable = splitOffPermanentFailures(pass, permanentFailures);
+        log.debug("Delete retry {} for queue {} (backoff {} ms) left {} messages still failing.",
+            retries, queueUrl, backoffMs, retryable.size());
+      }
+      List<FailedDelete> residual = new ArrayList<>(permanentFailures);
+      residual.addAll(retryable);
+      long wallMs = System.currentTimeMillis() - startMs;
+      int deleted = processedMessages.size() - residual.size();
+      log.info("Deleted {} of {} processed messages from queue {} across {} delete batches and {} SQS calls "
+              + "({} calls failed, {} retry passes) in {} ms ({} messages failed to delete).",
+          deleted, processedMessages.size(), queueUrl, totalBatches, stats.calls, stats.failedCalls,
+          retries, wallMs, residual.size());
+      if (stats.failedCalls > 0) {
+        // The residual WARN below groups by reason but carries no stack trace; log the first cause once
+        // here so the SDK-level reason (throttling, connection acquisition timeout, ...) is recoverable.
+        log.warn("{} of {} SQS DeleteMessageBatch calls failed for queue {}; their batches were retried and "
+                + "{} messages remain undeleted. Undeleted messages are redelivered after the visibility "
+                + "timeout, so ingestion may see them again rather than losing them.",
+            stats.failedCalls, stats.calls, queueUrl, residual.size(), stats.firstThrown);
+      }
+      if (stats.fatalThrown != null) {
+        // A non-retryable failure that struck only part of the phase (a session token expiring mid-run,
+        // say) leaves deleted > 0, so the systemic throw below stays silent by design. Without this it
+        // would be reported only as an indistinguishable residual-failure WARN, so name the condition
+        // explicitly: no retry can clear it, and it will recur on every commit until an operator acts.
+        log.error("Non-retryable SQS DeleteMessageBatch failure for queue {}; stopped dispatching further "
+                + "delete batches ({} batches skipped) and did not retry, since no retry can succeed. {} of {} "
+                + "messages remain undeleted and will be redelivered after the visibility timeout. Check the "
+                + "queue url, its region, and the credentials/permissions of this job.",
+            queueUrl, stats.skippedBatches, residual.size(), processedMessages.size(), stats.fatalThrown);
+      }
+      if (!residual.isEmpty()) {
+        logDeleteFailures(queueUrl, residual, retries);
+      }
+      logParallelPerf("delete", queueUrl, workers, stats.calls, wallMs, busyNanos.get());
+      // Nothing at all could be deleted and calls were throwing: systemic (bad credentials, queue gone,
+      // network down) rather than individual stale entries, and the caller is about to clear its tracked
+      // messages as if they had been handled, so surface it. A purely senderFault residue is deliberately
+      // not fatal - every receipt handle being stale is a real queue state that no retry or job failure
+      // can fix, and the messages are redelivered regardless.
+      //
+      // NOTE: this deliberately does not fire when every entry failed server-side on an HTTP 200
+      // (senderFault=false, e.g. InternalError) with no call ever throwing. That is an equally total
+      // failure to delete, but SQS reports genuinely broken plumbing - bad credentials, a deleted queue -
+      // by throwing, so firstThrown is the sharper signal, and escalating a persistent per-entry
+      // condition into a job shutdown would trade at-least-once redelivery for an ingestion outage.
+      // Making that case visible belongs to the residual-failure metric tracked as follow-up, not here.
+      // The extra answeredCalls() guard: a DeleteMessageBatch that returned HTTP 200 proves the queue is
+      // reachable and the credentials work, even if it reported every entry as failed. Without it, the
+      // deliberately-non-fatal all-senderFault case above (every receipt handle stale after a long commit)
+      // turns into a job shutdown as soon as one unrelated call is also throttled - and fanning out makes
+      // such a throttle more likely, not less.
+      if (deleted == 0 && stats.firstThrown != null && stats.answeredCalls() == 0) {
+        throw new HoodieException("Failed to delete any of the " + processedMessages.size()
+            + " processed messages from SQS queue " + queueUrl + " (" + stats.failedCalls + " of "
+            + stats.calls + " DeleteMessageBatch calls threw, " + residual.size()
+            + " messages still undeleted after " + retries + " retries)", stats.firstThrown);
+      }
+    } finally {
+      shutdownThreadPool(pool);
+    }
+  }
+
+  /**
+   * Deletes the given batches concurrently on {@code pool} and returns the outcome of the pass: every
+   * message that was not deleted, plus the call stats. Each batch's SQS call time is accumulated into
+   * {@code busyNanos} so the caller can log the serialized-equivalent time and prove the deletes
+   * actually overlapped.
+   *
+   * @param workers the pool's size, passed in rather than re-derived from {@code deleteBatches}. A retry
+   *     pass carries fewer batches than the first one, so deriving it here would produce a second,
+   *     smaller value under the same name as the caller's - and the caller's is the one that sized the
+   *     pool and is reported as {@code parallelism} on the perf line. Over-dispatch is not a concern:
+   *     {@code pending} is exhausted once every batch is submitted, whatever the slot count says.
+   */
+  private DeletePass deleteBatchesConcurrently(ExecutorService pool, SqsClient sqs, String queueUrl,
+                                               List<List<MessageTracker>> deleteBatches, int workers,
+                                               AtomicLong busyNanos) {
+    CompletionService<BatchOutcome> completionService = new ExecutorCompletionService<>(pool);
+    Iterator<List<MessageTracker>> pending = deleteBatches.iterator();
+    DeletePass pass = new DeletePass();
+    int outstanding = 0;
+    try {
+      // Dispatch incrementally rather than queueing every batch up front. The pool stays saturated either
+      // way, but holding the untried batches back is what makes fail-fast possible: on a non-retryable
+      // failure the remaining batches are simply never submitted. With a deleted queue or revoked
+      // credentials that is the difference between ceil(M/10) doomed calls and roughly one per worker.

Review Comment:
   🤖 nit: could you use an explicit `case TRANSIENT:` instead of `default:` here? With `default` a future `SqsFailureKind` value would silently be treated as transient with no compile-time signal that a new case was missed.
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub>



-- 
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@hudi.apache.org

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


Re: [PR] perf(ingest): parallelize SQS receive and delete in the S3 events source [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19396:
URL: https://github.com/apache/hudi/pull/19396#issuecomment-5136519149

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "aa531689bdcec179c432c6759a640c2faf49a7a9",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=15790",
       "triggerID" : "aa531689bdcec179c432c6759a640c2faf49a7a9",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dd59373400cac8b9d5248d2f81d20bc89b1c943d",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=15867",
       "triggerID" : "dd59373400cac8b9d5248d2f81d20bc89b1c943d",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * dd59373400cac8b9d5248d2f81d20bc89b1c943d Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=15867) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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@hudi.apache.org

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