-
Notifications
You must be signed in to change notification settings - Fork 387
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
satellite/overlay: avoid large statement for piece counts #3001
Conversation
Benchmark old ns/op new ns/op delta BenchmarkDB_PieceCounts/Sqlite/Update-32 2403696100 136937262 -94.30% BenchmarkDB_PieceCounts/Sqlite/All-32 16454915 17416226 +5.84% BenchmarkDB_PieceCounts/Postgres/Update-32 562646350 149697062 -73.39% BenchmarkDB_PieceCounts/Postgres/All-32 13657257 14630751 +7.13%
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.
I am also not sure why this is written directly into the nodes table, rather than being cached and put into the table together with the other metrics
satellite/overlay/piececount_test.go
Outdated
initialCounts, err := overlaydb.AllPieceCounts(ctx) | ||
require.NoError(t, err) | ||
require.Empty(t, initialCounts) | ||
// TODO: make it actually return everything |
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.
Is it fine to leave the TODO here and remove the code below?
Or better fix it directly? 👍
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.
I didn't want to fix it directly at this moment, otherwise the PR would grow too large. But I certainly can remove it.
for _, count := range counts { | ||
_, err := tx.Tx.ExecContext(ctx, query, count.Count, count.ID) | ||
if err != nil { | ||
return Error.Wrap(err) |
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.
Wouldnt this mean that if a single update fails, we return out of the entire function and discard the other inserts.
And the piece count for some nodes could be updated by then, as i dont see that we rollback in an error case?
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.
I am not entirely up to speed how critical this number is..
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.
Wouldnt this mean that if a single update fails, we return out of the entire function and discard the other inserts.
Yes, but this would also mean that there's something critically wrong already. Either we ended up creating piece count updates for storage nodes that aren't in our table. Or somebody deleted the node from the table... either would be problematic.
There of course could be an issue with database.
Of course, we don't care that much here, since it's for sqlite, which is mainly for testing.
And the piece count for some nodes could be updated by then, as i dont see that we rollback in an error case?
When WithTx
returns an error, it will rollback the transaction.
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.
Thanks, that should be ok then 👍
@stefanbenten this is not for metrics, this number is used for calculating garbage collection bloom filter sizes. |
_, err = cache.db.DB.ExecContext(ctx, cache.db.Rebind(sqlQuery), args...) | ||
return err | ||
} | ||
sort.Slice(counts, func(i, k int) bool { |
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.
Just curious why not use .SliceStable
here?
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.
Because the node ids are guaranteed to be unique, so there wouldn’t be a difference in the result.
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.
LGTM
What: Use array arguments instead of constructing a large single query.
Why: Concatenated SQL statements are harder to audit and often can end up slower.
PS: Each commit is separately reviewable.
Please describe the tests:
Please describe the performance impact:
Code Review Checklist (to be filled out by reviewer)