diff --git a/db/dbformat.cc b/db/dbformat.cc index 9357c3278..7b565abc5 100644 --- a/db/dbformat.cc +++ b/db/dbformat.cc @@ -106,45 +106,6 @@ const char* InternalKeyComparator::Name() const { return name_.c_str(); } -int InternalKeyComparator::Compare(const Slice& akey, const Slice& bkey) const { - // Order by: - // increasing user key (according to user-supplied comparator) - // decreasing sequence number - // decreasing type (though sequence# should be enough to disambiguate) - int r = user_comparator_->Compare(ExtractUserKey(akey), ExtractUserKey(bkey)); - PERF_COUNTER_ADD(user_key_comparison_count, 1); - if (r == 0) { - const uint64_t anum = DecodeFixed64(akey.data() + akey.size() - 8); - const uint64_t bnum = DecodeFixed64(bkey.data() + bkey.size() - 8); - if (anum > bnum) { - r = -1; - } else if (anum < bnum) { - r = +1; - } - } - return r; -} - -int InternalKeyComparator::CompareKeySeq(const Slice& akey, - const Slice& bkey) const { - // Order by: - // increasing user key (according to user-supplied comparator) - // decreasing sequence number - int r = user_comparator_->Compare(ExtractUserKey(akey), ExtractUserKey(bkey)); - PERF_COUNTER_ADD(user_key_comparison_count, 1); - if (r == 0) { - // Shift the number to exclude the last byte which contains the value type - const uint64_t anum = DecodeFixed64(akey.data() + akey.size() - 8) >> 8; - const uint64_t bnum = DecodeFixed64(bkey.data() + bkey.size() - 8) >> 8; - if (anum > bnum) { - r = -1; - } else if (anum < bnum) { - r = +1; - } - } - return r; -} - int InternalKeyComparator::Compare(const ParsedInternalKey& a, const ParsedInternalKey& b) const { // Order by: diff --git a/db/dbformat.h b/db/dbformat.h index 52e668d1d..7262bb24b 100644 --- a/db/dbformat.h +++ b/db/dbformat.h @@ -11,6 +11,7 @@ #include #include #include +#include "monitoring/perf_context_imp.h" #include "rocksdb/comparator.h" #include "rocksdb/db.h" #include "rocksdb/filter_policy.h" @@ -607,4 +608,46 @@ struct RangeTombstone { } }; +inline +int InternalKeyComparator::Compare(const Slice& akey, const Slice& bkey) const { + // Order by: + // increasing user key (according to user-supplied comparator) + // decreasing sequence number + // decreasing type (though sequence# should be enough to disambiguate) + int r = user_comparator_->Compare(ExtractUserKey(akey), ExtractUserKey(bkey)); + PERF_COUNTER_ADD(user_key_comparison_count, 1); + if (r == 0) { + const uint64_t anum = DecodeFixed64(akey.data() + akey.size() - 8); + const uint64_t bnum = DecodeFixed64(bkey.data() + bkey.size() - 8); + if (anum > bnum) { + r = -1; + } else if (anum < bnum) { + r = +1; + } + } + return r; +} + +inline +int InternalKeyComparator::CompareKeySeq(const Slice& akey, + const Slice& bkey) const { + // Order by: + // increasing user key (according to user-supplied comparator) + // decreasing sequence number + int r = user_comparator_->Compare(ExtractUserKey(akey), ExtractUserKey(bkey)); + PERF_COUNTER_ADD(user_key_comparison_count, 1); + if (r == 0) { + // Shift the number to exclude the last byte which contains the value type + const uint64_t anum = DecodeFixed64(akey.data() + akey.size() - 8) >> 8; + const uint64_t bnum = DecodeFixed64(bkey.data() + bkey.size() - 8) >> 8; + if (anum > bnum) { + r = -1; + } else if (anum < bnum) { + r = +1; + } + } + return r; +} + + } // namespace rocksdb diff --git a/table/block_fetcher.cc b/table/block_fetcher.cc index 09d930fdc..fd01ac1c6 100644 --- a/table/block_fetcher.cc +++ b/table/block_fetcher.cc @@ -30,6 +30,7 @@ namespace rocksdb { +inline void BlockFetcher::CheckBlockChecksum() { // Check the crc of the type and the block contents if (read_options_.verify_checksums) { @@ -62,6 +63,7 @@ void BlockFetcher::CheckBlockChecksum() { } } +inline bool BlockFetcher::TryGetUncompressBlockFromPersistentCache() { if (cache_options_.persistent_cache && !cache_options_.persistent_cache->IsCompressed()) { @@ -83,6 +85,7 @@ bool BlockFetcher::TryGetUncompressBlockFromPersistentCache() { return false; } +inline bool BlockFetcher::TryGetFromPrefetchBuffer() { if (prefetch_buffer_ != nullptr && prefetch_buffer_->TryReadFromCache( @@ -99,6 +102,7 @@ bool BlockFetcher::TryGetFromPrefetchBuffer() { return got_from_prefetch_buffer_; } +inline bool BlockFetcher::TryGetCompressedBlockFromPersistentCache() { if (cache_options_.persistent_cache && cache_options_.persistent_cache->IsCompressed()) { @@ -119,6 +123,7 @@ bool BlockFetcher::TryGetCompressedBlockFromPersistentCache() { return false; } +inline void BlockFetcher::PrepareBufferForBlockFromFile() { // cache miss read from device if (do_uncompress_ && @@ -127,12 +132,12 @@ void BlockFetcher::PrepareBufferForBlockFromFile() { // trivially allocated stack buffer instead of needing a full malloc() used_buf_ = &stack_buf_[0]; } else { - heap_buf_ = - std::unique_ptr(new char[block_size_ + kBlockTrailerSize]); + heap_buf_.reset(new char[block_size_ + kBlockTrailerSize]); used_buf_ = heap_buf_.get(); } } +inline void BlockFetcher::InsertCompressedBlockToPersistentCacheIfNeeded() { if (status_.ok() && read_options_.fill_cache && cache_options_.persistent_cache && @@ -143,6 +148,7 @@ void BlockFetcher::InsertCompressedBlockToPersistentCacheIfNeeded() { } } +inline void BlockFetcher::InsertUncompressedBlockToPersistentCacheIfNeeded() { if (status_.ok() && !got_from_prefetch_buffer_ && read_options_.fill_cache && cache_options_.persistent_cache && @@ -153,6 +159,7 @@ void BlockFetcher::InsertUncompressedBlockToPersistentCacheIfNeeded() { } } +inline void BlockFetcher::GetBlockContents() { if (slice_.data() != used_buf_) { // the slice content is not the buffer provided @@ -161,7 +168,7 @@ void BlockFetcher::GetBlockContents() { } else { // page is uncompressed, the buffer either stack or heap provided if (got_from_prefetch_buffer_ || used_buf_ == &stack_buf_[0]) { - heap_buf_ = std::unique_ptr(new char[block_size_]); + heap_buf_.reset(new char[block_size_]); memcpy(heap_buf_.get(), used_buf_, block_size_); } *contents_ = BlockContents(std::move(heap_buf_), block_size_, true,