Skip to content

GH-3442: Fix MySQL/MariaDB message ordering in JdbcChatMemoryRepository#4739

Closed
sobychacko wants to merge 1 commit intospring-projects:mainfrom
sobychacko:fix-jdbc-chat-memory-timestamp-ordering
Closed

GH-3442: Fix MySQL/MariaDB message ordering in JdbcChatMemoryRepository#4739
sobychacko wants to merge 1 commit intospring-projects:mainfrom
sobychacko:fix-jdbc-chat-memory-timestamp-ordering

Conversation

@sobychacko
Copy link
Contributor

Fixes #3442

Change timestamp generation to use second-level granularity instead of milliseconds to ensure compatibility with MySQL/MariaDB default TIMESTAMP precision (0 decimal places). The old code used millisecond timestamps that were truncated to seconds on storage, causing messages saved within the same second to have identical timestamps and random ordering.

The timestamp field functions as a sequence ID for message ordering rather than a precise temporal record. Using second-level granularity with proper incrementing ensures correct ordering across all database timestamp precisions without requiring schema changes.

Also adds testMessageOrderWithLargeBatch() that saves 50 messages to validate ordering is preserved. The original test with only 4 messages was passing by chance despite the underlying bug.

Thank you for taking time to contribute this pull request!
You might have already read the contributor guide, but as a reminder, please make sure to:

  • Add a Signed-off-by line to each commit (git commit -s) per the DCO
  • Rebase your changes on the latest main branch and squash your commits
  • Add/Update unit tests as needed
  • Run a build and make sure all tests pass prior to submission

For more details, please check the contributor guide.
Thank you upfront!

…tMemoryRepository

Fixes spring-projects#3442

Change timestamp generation to use second-level granularity instead of
milliseconds to ensure compatibility with MySQL/MariaDB default TIMESTAMP
precision (0 decimal places). The old code used millisecond timestamps that
were truncated to seconds on storage, causing messages saved within the same
second to have identical timestamps and random ordering.

The timestamp field functions as a sequence ID for message ordering rather
than a precise temporal record. Using second-level granularity with proper
incrementing ensures correct ordering across all database timestamp precisions
without requiring schema changes.

Also adds testMessageOrderWithLargeBatch() that saves 50 messages to validate
ordering is preserved. The original test with only 4 messages was passing by
chance despite the underlying bug.

Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
@ilayaperumalg ilayaperumalg self-assigned this Oct 28, 2025
@ilayaperumalg
Copy link
Member

Rebased and merged as d2492a6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working for: backport-to-1.0.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MySQL/MariaDB schema TIMESTAMP precision causes message ordering issues in JdbcChatMemoryRepository

3 participants