-
Notifications
You must be signed in to change notification settings - Fork 128
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
remove custom trylock in favor of stock sync.Mutex #1886
base: master
Are you sure you want to change the base?
Conversation
2eadf2c
to
7db6f74
Compare
Go 1.18 supplements Mutex with a TryLock method. Use this directly instead of our dumb homebrew trylock mutex when Go 1.18 is in use.
7db6f74
to
db9fd08
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.
Looks straight-forward.
@@ -24,7 +24,7 @@ jobs: | |||
working-directory: ./cmd/dcrdata | |||
|
|||
- name: Install Linters | |||
run: "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.48.0" | |||
run: "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.50.1" |
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.
current version master is v1.55.2, consider updating to v1.58.0
@@ -1,6 +1,9 @@ | |||
// Copyright (c) 2021, The Decred developers | |||
// Copyright (c) 2021-2022, The Decred developers |
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.
Can update this the next time you commit.
@@ -0,0 +1,13 @@ | |||
// Copyright (c) 2022, The Decred developers |
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 too.
Go 1.18 supplements
Mutex
with aTryLock
method. For the on-demand concurrent client accesses to the cache-guarded DB, use this directly instead of our dumb homebrew trylock mutex when Go 1.18 is in use.IMPORTANT NOTES:
if !TryLock() { if haveCachedData { /* return stale data */ } else { Lock() /* wait */ } }
solves this quite handily. This has been functioning well in production for quite some time.The use case in pseudo code:
An alternative approach that does not involve locking to wait on the data, but rather a channel to receive from, used elsewhere in the project:
dcrdata/db/cache/addresscache.go
Lines 56 to 65 in 429ab90
Also update CI to use go 1.18-beta1.