You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "PDGGK (via GitHub)" <gi...@apache.org> on 2026/08/26 14:18:51 UTC

[PR] Truncate timestamps towards the past when comparing them for consistency [shardingsphere]

PDGGK opened a new pull request, #39610:
URL: https://github.com/apache/shardingsphere/pull/39610

   Changes proposed in this pull request:
   
     - Truncate timestamps to the second with `Math.floorDiv`, so pre-epoch values land in the second they belong to.
   
   `isMatched` compares `Timestamp` columns at second granularity, deliberately, to avoid precision differences between heterogeneous databases:
   
   ```java
   return ((Timestamp) thisColumnValue).getTime() / 1000L * 1000L
       == ((Timestamp) thatColumnValue).getTime() / 1000L * 1000L;
   ```
   
   Integer division truncates towards zero rather than downwards, so for a negative epoch value it rounds *up* — `-1500` becomes `-1000`, putting a timestamp in the second above the one it is in. Above the epoch the two agree; below it they do not, and the comparison goes wrong in both directions:
   
   | the two values (ms) | apart | current | with `floorDiv` |
   |---|---|---|---|
   | `-1500`, `-1000` | 500 ms, different seconds | **matched** | differ |
   | `-500`, `400` | 900 ms, straddles the epoch | **matched** | differ |
   | `-1`, `1` | 2 ms, different seconds | **matched** | differ |
   | `-1000`, `-999` | 1 ms, same second | **differ** | matched |
   
   The first three are the ones that matter: a data consistency check reports two rows as equal while they hold different timestamps, which is the one answer the check exists to rule out. The last is the mirror image — two values inside the same second reported as a mismatch, so the check fails on data that is in fact consistent.
   
   Any table with timestamps before 1970-01-01 is affected — dates of birth, historical records, backfilled series.
   
   ### Tests
   
   `assertTimestampEqualsBeforeEpoch` covers all four rows of that table. On `master` the first assertion already fails:
   
   ```
   DataConsistencyCheckUtilsTest.assertTimestampEqualsBeforeEpoch:66
   expected: <false> but was: <true>
   ```
   
   The existing `assertTimestampEquals` is untouched and still passes, so the above-epoch behaviour and the sub-second tolerance are unchanged.
   
   `mvn test -pl kernel/data-pipeline/core` — 322 tests, all passing.
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [x] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [x] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the pull request.
   - [x] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [x] I have added corresponding unit tests for my changes.
   - [ ] I have updated the Release Notes of the current development version. For more details, see [Update Release Note](https://shardingsphere.apache.org/community/en/involved/contribute/contributor/)
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


Re: [PR] Truncate timestamps towards the past when comparing them for consistency [shardingsphere]

Posted by "PDGGK (via GitHub)" <gi...@apache.org>.
PDGGK commented on PR #39610:
URL: https://github.com/apache/shardingsphere/pull/39610#issuecomment-5491383182

   Fixed in `cb595fe5`. `assertTrue` and `assertFalse` are back and the `Matchers.is` import is gone; the scenarios are now two parameterized tests, `assertTimestampMatchedBeforeEpoch` and `assertTimestampNotMatchedBeforeEpoch`, each execution still invoking `isMatched` once.
   
   One thing worth stating rather than leaving implicit: of the four pre-epoch scenarios, three fail on `master` and one does not. `sub second tolerance before epoch` (-1999, -1001) is already true under integer division, so it guards the tolerance rather than covering the fix. The three that discriminate are:
   
   ```
   assertTimestampMatchedBeforeEpoch    "same second before epoch"        expected: <true>  but was: <false>
   assertTimestampNotMatchedBeforeEpoch "different seconds before epoch"  expected: <false> but was: <true>
   assertTimestampNotMatchedBeforeEpoch "different seconds across epoch"  expected: <false> but was: <true>
   ```
   
   The branch is also rebased onto `81da8493`, since the Spotless failure the PR was showing came from master rather than from this change.
   
   `mvn test -pl :shardingsphere-data-pipeline-core` — 325 tests passing, `spotless:check -Pcheck` and `checkstyle:check -Pcheck` clean.
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


Re: [PR] Truncate timestamps towards the past when comparing them for consistency [shardingsphere]

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


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


Re: [PR] Truncate timestamps towards the past when comparing them for consistency [shardingsphere]

Posted by "PDGGK (via GitHub)" <gi...@apache.org>.
PDGGK commented on PR #39610:
URL: https://github.com/apache/shardingsphere/pull/39610#issuecomment-5460427317

   Both fixed in 8593b85d.
   
   On the comments: CODE_OF_CONDUCT.md permits only Javadoc, TODO and FIXME, and you are right that Spotless passing says nothing about that rule. The two line comments are gone; the helper carries the intent in its name instead - toSeconds is now toFlooredSeconds.
   
   On the test: it is now a @ParameterizedTest(name = "{0}") with four cases, each naming its scenario and calling isMatched once - different seconds before epoch, different seconds across epoch, same second before epoch, sub second tolerance before epoch. Reverting the fix now fails three of them by name rather than pointing at one line.
   
   mvn test -pl kernel/data-pipeline/core - 325 tests, all passing. Checkstyle clean.
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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