-
Notifications
You must be signed in to change notification settings - Fork 170
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
Conversation
Signed-off-by: Connor1996 <[email protected]>
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, |
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.
It will reduce the cost of a lock, but will add a cost to get file size from handle, is it cheaper?
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.
Agree, can you give some numbers?
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.
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
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.
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]>
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
Should merge #309 first