-
Notifications
You must be signed in to change notification settings - Fork 244
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
Postgres optimized revision caching #555
Conversation
updateGroup singleflight.Group | ||
} | ||
|
||
type validRevision struct { |
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.
👍 this is a small change but I like it
@@ -23,7 +24,8 @@ const ( | |||
SELECT COALESCE( | |||
(SELECT MIN(%[1]s) FROM %[2]s WHERE %[3]s >= TO_TIMESTAMP(FLOOR(EXTRACT(EPOCH FROM NOW() AT TIME ZONE 'utc') * 1000000000 / %[4]d) * %[4]d / 1000000000)), | |||
(SELECT MAX(%[1]s) FROM %[2]s) | |||
);` | |||
), | |||
%[4]d - CAST(EXTRACT(EPOCH FROM NOW() AT TIME ZONE 'utc') * 1000000000 as bigint) %% %[4]d;` |
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.
update the comment to note that it's also returning validForNanos now?
10185ed
to
0c7dc2e
Compare
Updated |
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
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.
unlgtm, the e2e failure looks potentially real
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
0c7dc2e
to
59b5901
Compare
// it will remain valid. | ||
type OptimizedRevisionFunction func(context.Context) (rev datastore.Revision, validFor time.Duration, err error) | ||
|
||
// NewRemoteClockRevisions returns a RemoteClockRevisions for the given configuration |
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.
Fix comment
lastQuantizedRevision, err, _ := cor.updateGroup.Do("", func() (interface{}, error) { | ||
log.Debug().Time("now", localNow).Time("valid", lastRevision.validThrough).Msg("computing new revision") | ||
|
||
optimized, validFor, err := cor.optimizedFunc(ctx) |
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.
Add a panic here if it is not set? its slightly nicer than just an NPE
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.
At the cost of requiring an extra conditional every time.
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.
Yes, but I tend to think having panics when its an expected state makes sense; it would mean they forgot to call the assignment method, and that's certainly an expected bug
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 wish we had debug-only checks
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've seen this done with build tags in https://github.com/dlsniper/debugger and in some etcd fault injection library that I can't find now. I assume the compiler removes no-op functions but I haven't checked.
|
||
rvt := localNow. | ||
Add(validFor). | ||
Add(cor.maxRevisionStaleness) |
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.
Won't adding these push it above the max staleness?
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.
My definition for staleness
is "time after which the new revision would have been selected". So in this case we allow for it to be used slightly longer than it's strictly valid for, but which gives us a minimum valid lifetime for any revision we ask the database to compute. E.g you can't get back a revision that's only good for 1 nanosecond.
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.
But why not just do max(validFor, maxRevisionStaleness)
then?
} | ||
|
||
// CachedOptimizedRevisions does caching and deduplication for requests for optimized revisions. | ||
type CachedOptimizedRevisions struct { |
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.
Move above the function defs for this type?
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 don't know. All of the fields are private, it's probably less important than the API to interact with it.
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.
True, but it was highly unexpected when I landed on the file
244d25c
to
6116688
Compare
6116688
to
3fb483c
Compare
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
No description provided.