mirror of https://github.com/facebook/rocksdb.git
TableCache.FindTable() to avoid the mem copy of file number
Summary: I'm not sure what's the purpose of encoding file number to a new buffer for looking up the table cache. It seems to be unnecessary to me. With this patch, we point the lookup key to the address of the int64 of the file number. Test Plan: make all check Reviewers: dhruba, haobo, igor, kailiu Reviewed By: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D14811
This commit is contained in:
parent
18df47b79a
commit
a094f3b3b5
|
@ -29,6 +29,11 @@ static void UnrefEntry(void* arg1, void* arg2) {
|
||||||
cache->Release(h);
|
cache->Release(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Slice GetSliceForFileNumber(uint64_t file_number) {
|
||||||
|
return Slice(reinterpret_cast<const char*>(&file_number),
|
||||||
|
sizeof(file_number));
|
||||||
|
}
|
||||||
|
|
||||||
TableCache::TableCache(const std::string& dbname,
|
TableCache::TableCache(const std::string& dbname,
|
||||||
const Options* options,
|
const Options* options,
|
||||||
const EnvOptions& storage_options,
|
const EnvOptions& storage_options,
|
||||||
|
@ -50,9 +55,7 @@ Status TableCache::FindTable(const EnvOptions& toptions,
|
||||||
Cache::Handle** handle, bool* table_io,
|
Cache::Handle** handle, bool* table_io,
|
||||||
const bool no_io) {
|
const bool no_io) {
|
||||||
Status s;
|
Status s;
|
||||||
char buf[sizeof(file_number)];
|
Slice key = GetSliceForFileNumber(file_number);
|
||||||
EncodeFixed64(buf, file_number);
|
|
||||||
Slice key(buf, sizeof(buf));
|
|
||||||
*handle = cache_->Lookup(key);
|
*handle = cache_->Lookup(key);
|
||||||
if (*handle == nullptr) {
|
if (*handle == nullptr) {
|
||||||
if (no_io) { // Dont do IO and return a not-found status
|
if (no_io) { // Dont do IO and return a not-found status
|
||||||
|
@ -165,9 +168,7 @@ bool TableCache::PrefixMayMatch(const ReadOptions& options,
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableCache::Evict(uint64_t file_number) {
|
void TableCache::Evict(uint64_t file_number) {
|
||||||
char buf[sizeof(file_number)];
|
cache_->Erase(GetSliceForFileNumber(file_number));
|
||||||
EncodeFixed64(buf, file_number);
|
|
||||||
cache_->Erase(Slice(buf, sizeof(buf)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace rocksdb
|
} // namespace rocksdb
|
||||||
|
|
Loading…
Reference in New Issue