SEPURI-SAI-KRISHNA opened a new pull request, #12290:
URL: https://github.com/apache/seatunnel/pull/12290

   ### Purpose of this pull request
   
   Close #11976
   
   #11721 fixed the negative queue index in `MultiTableSinkWriter` by clearing 
the sign bit inline. That was deliberate rather than preferred: 
`HashUtils.bucketIndex` did not exist at that branch point. It landed on `dev` 
through #11987 on 2026-09-01, a week after #11721's last `dev` merge, so 
adopting it there would have meant a fresh merge and a re-review of an already 
approved diff. #11976 was opened to track the migration and held open until 
#11721 merged, which it did on 2026-09-10.
   
   This is that migration:
   
   ```java
   - index = (object.hashCode() & Integer.MAX_VALUE) % blockingQueues.size();
   + index = HashUtils.bucketIndex(object.hashCode(), blockingQueues.size());
   ```
   
   The two are the same function for every input. `HashUtils.bucketIndex(int, 
int)` is exactly `(hash & Integer.MAX_VALUE) % bucketCount`, so routing is 
unchanged for every key, including `Integer.MIN_VALUE`. This removes the last 
remaining copy of the idiom and moves the reasoning into one documented place 
rather than a comment at the call site. The same migration was done for the 
AzureCosmosDB enumerator in #12049 and for the other call sites in #11937 and 
#11987.
   
   The javadoc on `write(SeaTunnelRow)` is updated to point at the helper 
instead of restating the expression.
   
   One deliberate behavioral difference: `bucketIndex` rejects a non-positive 
`bucketCount` with `IllegalArgumentException`, where the inline form would have 
thrown `ArithmeticException` on division by zero. That path is unreachable 
here, since an empty queue list would already fail earlier in the 
random-routing branch on `Random.nextInt(0)`, and the explicit message is the 
better outcome if it ever became reachable.
   
   Note also that `object.hashCode()` is an `int`, so this binds to the `int` 
overload. `HashUtils` documents that the `int` and `long` overloads are 
distinct mappings rather than a widening, and a call site must not be switched 
between them. This one is not.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. Same routing for every input, no config or API surface touched.
   
   ### How was this patch tested?
   
   The existing routing tests in `MultiTableSinkWriterTest` are unchanged and 
still pass, including the one that pins the exact target queue for a primary 
key whose `hashCode()` is `Integer.MIN_VALUE`. That test is what makes this a 
safe swap: it asserts the concrete index, not merely that the index is 
non-negative, so a change in mapping would fail it.
   
   ```
   ./mvnw -pl seatunnel-api -Dskip.spotless=true test
   Tests run: 398, Failures: 0, Errors: 0, Skipped: 0
   ```
   
   `./mvnw -pl seatunnel-api spotless:check` passes.
   


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