-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix deadlock: reduce number rows deleted at per iter, add retry #27027
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #27027 +/- ##
==========================================
- Coverage 63.99% 63.98% -0.01%
==========================================
Files 1704 1705 +1
Lines 162237 162796 +559
Branches 4327 4327
==========================================
+ Hits 103822 104164 +342
- Misses 50346 50518 +172
- Partials 8069 8114 +45
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:
|
@@ -587,13 +589,13 @@ func (ds *Datastore) CleanupActivitiesAndAssociatedData(ctx context.Context, max | |||
var rowsAffected int64 | |||
|
|||
// Start a new transaction for each batch of deletions. | |||
err := ds.withTx(ctx, func(tx sqlx.ExtContext) error { | |||
err := ds.withRetryTxx(ctx, func(tx sqlx.ExtContext) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On environments with heavy/constant use of live queries this might increase the latency of the live queries (retries might impact transactions for live queries). Which can impact Zero Trust flows that use live queries to determine device health.
Another approach we can use to reduce chance of deadlock is to not use a transaction that modifies three tables and instead use DB reader and writer, something like this:
- Use DB reader to know which queries are expired (get ids).
- Use DB writer to delete queries (ids from 1).
- Use DB reader to determine which distributed_query_campaigns to delete (get ids).
- Use DB writer to delete distributed_query_campaigns (ids from 3).
- Use DB reader to determine which distributed_query_campaign_targets to delete (get ids).
- Use DB writer to delete distributed_query_campaign_targets (ids from 5).
AFAICS we can delete the queries separately from the (not in a transaction) because these are non-accessible non-saved expired queries and there's no foreign key association.
Am all ears.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a comment to discuss a different approach.
#27002
changes/
,orbit/changes/
oree/fleetd-chrome/changes
.See Changes files for more information.