Fixed dead rows accumulating in software host counts tables#40288
Fixed dead rows accumulating in software host counts tables#40288
Conversation
|
@coderabbitai full review |
There was a problem hiding this comment.
Pull request overview
This PR addresses accumulation of “dead” hosts_count = 0 rows in the host-count aggregation tables by switching the sync logic to an atomic swap-table approach and enforcing positive counts at the schema level.
Changes:
- Reworked
SyncHostsSoftwareandSyncHostsSoftwareTitlesto populate swap tables and atomically rename them into place (instead of resetting counts to 0 and updating in-place). - Updated listing/filtering SQL to no longer rely on
hosts_count > 0predicates, consistent with eliminating zero-count rows. - Added a migration + schema constraints to delete existing zero-count rows and prevent future inserts of non-positive counts; adjusted unit test expectations accordingly.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
server/datastore/mysql/software.go |
Uses swap-table + rename for software_host_counts; removes reliance on hosts_count > 0 filtering in several queries. |
server/datastore/mysql/software_titles.go |
Uses swap-table + rename for software_titles_host_counts; adjusts title queries to check row existence instead of hosts_count > 0. |
server/datastore/mysql/migrations/tables/20260223000000_CleanupSoftwareHostCountsZeroRows.go |
Cleans up accumulated zero rows and adds CHECK constraints to enforce hosts_count > 0. |
server/datastore/mysql/schema.sql |
Reflects new constraints and migration status in the canonical schema. |
server/datastore/mysql/software_test.go |
Updates expected row counts in software_host_counts due to removal of zero-count rows. |
changes/35805-zero-host-counts |
Adds changelog entry for the bugfix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #40288 +/- ##
==========================================
- Coverage 66.26% 65.54% -0.73%
==========================================
Files 2460 2274 -186
Lines 197220 180111 -17109
Branches 8716 8593 -123
==========================================
- Hits 130682 118046 -12636
+ Misses 54713 50865 -3848
+ Partials 11825 11200 -625
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
WalkthroughThis PR fixes dead rows accumulating in software host counts tables by implementing an atomic table swap strategy during synchronization instead of in-place updates. A new migration cleans up existing zero-count rows and adds CHECK constraints (hosts_count > 0) to both Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
LGTM, but looks like there are some conflicts @getvictor |
…t-counts # Conflicts: # server/datastore/mysql/schema.sql # server/datastore/mysql/software_titles.go # server/datastore/mysql/testdata/select_software_titles_sql_fixture.gz
Related issue: Resolves #35805
Fixed to make sure software host counts tables never have host counts of 0.
Planning to loadtest this fix along with the follow up fix for #35799
Checklist for submitter
changes/,orbit/changes/oree/fleetd-chrome/changes.Testing
Summary by CodeRabbit