-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
improve mutex locking when writing index in boltdb-shipper #5830
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,15 +226,18 @@ func (lt *Table) MultiQueries(ctx context.Context, queries []chunk.IndexQuery, c | |
} | ||
|
||
func (lt *Table) getOrAddDB(name string) (*bbolt.DB, error) { | ||
lt.dbsMtx.RLock() | ||
db, ok := lt.dbs[name] | ||
lt.dbsMtx.RUnlock() | ||
|
||
if ok { | ||
return db, nil | ||
} | ||
|
||
lt.dbsMtx.Lock() | ||
defer lt.dbsMtx.Unlock() | ||
|
||
var ( | ||
db *bbolt.DB | ||
err error | ||
ok bool | ||
) | ||
|
||
var err error | ||
db, ok = lt.dbs[name] | ||
if !ok { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might invert this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I merged the PR already. Will open a follow-up PR. |
||
db, err = shipper_util.SafeOpenBoltdbFile(filepath.Join(lt.path, name)) | ||
|
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 could be moved inside the scope where it is used.