Repository navigation
Conversation
Since the move to setTimestamp()/setTime() in GenericDaoBase, Connector/J sends the milliseconds and MySQL rounds them into DATETIME(0) columns instead of dropping them. A value such as 10:59:59.999 is now stored as 11:00:00. The usage job computes period end as periodEnd - 1ms, so every usage record and usage_job end_date lands on the next period boundary and the last day of a listUsageRecords query is missed. Any other DATETIME written through the DAO can also be up to 0.5s in the future. Cut the sub-second part before binding Date and Calendar values as timestamps or times, which restores the previous stored values.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 4.20 #14929 +/- ##
============================================
+ Coverage 16.44% 16.46% +0.01%
- Complexity 13687 13715 +28
============================================
Files 5669 5671 +2
Lines 501651 501780 +129
Branches 60944 60965 +21
============================================
+ Hits 82491 82606 +115
- Misses 409920 409924 +4
- Partials 9240 9250 +10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
An active documentation gap remains because the smoke integration-suite is still in progress and its completed results, including relevant job outcomes, have not been added to the PR description.
1 open issue
What changed in this PR
This pull request fixes date-boundary regressions caused by MySQL rounding millisecond values when GenericDaoBase binds temporal values to whole-second database columns. Temporal bindings are truncated to whole seconds before persistence.
Changes:
- Added floor-based epoch-millisecond truncation and whole-second timestamp conversion.
- Applied truncation to timestamp and time bindings for dates, calendars, and date element collections.
- Added tests covering millisecond removal, negative epoch values, and timestamp precision.
| File | Description |
|---|---|
| framework/db/src/test/java/com/cloud/utils/db/GenericDaoBaseTest.java | Adds tests for whole-second truncation, negative epoch values, and timestamp precision behavior. |
| framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java | Truncates DAO-bound timestamp and time values to whole seconds before JDBC binding. |
Review effort: Lite
| * seconds, and the MySQL driver sends them to the server, which rounds rather than truncates | ||
| * (e.g. 10:59:59.999 is stored as 11:00:00), so values are cut to whole seconds before binding. | ||
| */ | ||
| protected static long truncateToSeconds(long millis) { |
|
@blueorangutan package |
|
@sudo87 a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Tested this on a two-host lab running a build of
So the fix restores the stored values, and the control rules out the build itself. In the unpatched run, types 21 to 24 still ended on One thing: the three new tests in |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 20260 |
framework-db excludes com/cloud/utils/db/*Test* from surefire, so the tests added for the truncation helpers in GenericDaoBaseTest never ran. Put the helpers in com.cloud.utils.db.datetime, which is not excluded, and test them there.
|
Thank you @Alpha162 for testing out the patch. Good catch on the tests, I moved the helpers and tests into new class so that those are run in CI. |

Description
Fixes #14928
GenericDaoBase now binds dates with setTimestamp()/setTime(), so the MySQL driver sends milliseconds and the server rounds them into DATETIME columns 10:59:59.999 is stored as 11:00:00.
The usage job uses periodEnd - 1ms as the end date, so usage records now get the next period's boundary as end_date and the last day of a listUsageRecords query is missed. Other DAO-written dates can also end up up to 0.5s in the future.
Truncate to whole seconds before binding, which restores the old stored values.
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
How did you try to break this feature and the system with this change?