Skip to content
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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions pkg/storage/stores/shipper/uploads/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

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.

db, ok = lt.dbs[name]
if !ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might invert this if so that the read-lock and write-lock cases look the same. Also this would outdent the remainder of the function which is more idiomatic Go.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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))
Expand Down