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

Avoid extra mutex for getting blob file reader #311

Merged
merged 6 commits into from
Feb 18, 2024

Conversation

Connor1996
Copy link
Member

Should merge #309 first

Signed-off-by: Connor1996 <[email protected]>
Signed-off-by: Connor1996 <[email protected]>
Signed-off-by: Connor1996 <[email protected]>
std::to_string(index.file_number));
return file_cache_->Get(options, sfile->file_number(), sfile->file_size(),
index.blob_handle, record, value);
return file_cache_->Get(options, index.file_number, index.blob_handle, record,
Copy link
Contributor

Choose a reason for hiding this comment

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

It will reduce the cost of a lock, but will add a cost to get file size from handle, is it cheaper?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, can you give some numbers?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hard to tell, because it depends on how long the mutex is held by others. As the mutex is shared by multiple fields, it's better to use an operation not affected by the mutex.

At least, rocksdb does this way https://github.com/tikv/rocksdb/blob/6.29.tikv/db/blob/blob_file_reader.cc#L97

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. After reading the code again, I think the difference is that before this PR, the lock is accquired for every call.
While for this PR, the getting file size only happens when cache miss. So overall it should be better.

Signed-off-by: Connor1996 <[email protected]>
Copy link
Contributor

@v01dstar v01dstar left a comment

Choose a reason for hiding this comment

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

LGTM

@tonyxuqqi tonyxuqqi enabled auto-merge (squash) February 12, 2024 17:10
@tonyxuqqi tonyxuqqi merged commit 1144c7a into tikv:master Feb 18, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants