|
|
@ -30,6 +30,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
namespace rocksdb { |
|
|
|
namespace rocksdb { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline |
|
|
|
void BlockFetcher::CheckBlockChecksum() { |
|
|
|
void BlockFetcher::CheckBlockChecksum() { |
|
|
|
// Check the crc of the type and the block contents
|
|
|
|
// Check the crc of the type and the block contents
|
|
|
|
if (read_options_.verify_checksums) { |
|
|
|
if (read_options_.verify_checksums) { |
|
|
@ -62,6 +63,7 @@ void BlockFetcher::CheckBlockChecksum() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline |
|
|
|
bool BlockFetcher::TryGetUncompressBlockFromPersistentCache() { |
|
|
|
bool BlockFetcher::TryGetUncompressBlockFromPersistentCache() { |
|
|
|
if (cache_options_.persistent_cache && |
|
|
|
if (cache_options_.persistent_cache && |
|
|
|
!cache_options_.persistent_cache->IsCompressed()) { |
|
|
|
!cache_options_.persistent_cache->IsCompressed()) { |
|
|
@ -83,6 +85,7 @@ bool BlockFetcher::TryGetUncompressBlockFromPersistentCache() { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline |
|
|
|
bool BlockFetcher::TryGetFromPrefetchBuffer() { |
|
|
|
bool BlockFetcher::TryGetFromPrefetchBuffer() { |
|
|
|
if (prefetch_buffer_ != nullptr && |
|
|
|
if (prefetch_buffer_ != nullptr && |
|
|
|
prefetch_buffer_->TryReadFromCache( |
|
|
|
prefetch_buffer_->TryReadFromCache( |
|
|
@ -99,6 +102,7 @@ bool BlockFetcher::TryGetFromPrefetchBuffer() { |
|
|
|
return got_from_prefetch_buffer_; |
|
|
|
return got_from_prefetch_buffer_; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline |
|
|
|
bool BlockFetcher::TryGetCompressedBlockFromPersistentCache() { |
|
|
|
bool BlockFetcher::TryGetCompressedBlockFromPersistentCache() { |
|
|
|
if (cache_options_.persistent_cache && |
|
|
|
if (cache_options_.persistent_cache && |
|
|
|
cache_options_.persistent_cache->IsCompressed()) { |
|
|
|
cache_options_.persistent_cache->IsCompressed()) { |
|
|
@ -119,6 +123,7 @@ bool BlockFetcher::TryGetCompressedBlockFromPersistentCache() { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline |
|
|
|
void BlockFetcher::PrepareBufferForBlockFromFile() { |
|
|
|
void BlockFetcher::PrepareBufferForBlockFromFile() { |
|
|
|
// cache miss read from device
|
|
|
|
// cache miss read from device
|
|
|
|
if (do_uncompress_ && |
|
|
|
if (do_uncompress_ && |
|
|
@ -127,12 +132,12 @@ void BlockFetcher::PrepareBufferForBlockFromFile() { |
|
|
|
// trivially allocated stack buffer instead of needing a full malloc()
|
|
|
|
// trivially allocated stack buffer instead of needing a full malloc()
|
|
|
|
used_buf_ = &stack_buf_[0]; |
|
|
|
used_buf_ = &stack_buf_[0]; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
heap_buf_ = |
|
|
|
heap_buf_.reset(new char[block_size_ + kBlockTrailerSize]); |
|
|
|
std::unique_ptr<char[]>(new char[block_size_ + kBlockTrailerSize]); |
|
|
|
|
|
|
|
used_buf_ = heap_buf_.get(); |
|
|
|
used_buf_ = heap_buf_.get(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline |
|
|
|
void BlockFetcher::InsertCompressedBlockToPersistentCacheIfNeeded() { |
|
|
|
void BlockFetcher::InsertCompressedBlockToPersistentCacheIfNeeded() { |
|
|
|
if (status_.ok() && read_options_.fill_cache && |
|
|
|
if (status_.ok() && read_options_.fill_cache && |
|
|
|
cache_options_.persistent_cache && |
|
|
|
cache_options_.persistent_cache && |
|
|
@ -143,6 +148,7 @@ void BlockFetcher::InsertCompressedBlockToPersistentCacheIfNeeded() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline |
|
|
|
void BlockFetcher::InsertUncompressedBlockToPersistentCacheIfNeeded() { |
|
|
|
void BlockFetcher::InsertUncompressedBlockToPersistentCacheIfNeeded() { |
|
|
|
if (status_.ok() && !got_from_prefetch_buffer_ && read_options_.fill_cache && |
|
|
|
if (status_.ok() && !got_from_prefetch_buffer_ && read_options_.fill_cache && |
|
|
|
cache_options_.persistent_cache && |
|
|
|
cache_options_.persistent_cache && |
|
|
@ -153,6 +159,7 @@ void BlockFetcher::InsertUncompressedBlockToPersistentCacheIfNeeded() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline |
|
|
|
void BlockFetcher::GetBlockContents() { |
|
|
|
void BlockFetcher::GetBlockContents() { |
|
|
|
if (slice_.data() != used_buf_) { |
|
|
|
if (slice_.data() != used_buf_) { |
|
|
|
// the slice content is not the buffer provided
|
|
|
|
// the slice content is not the buffer provided
|
|
|
@ -161,7 +168,7 @@ void BlockFetcher::GetBlockContents() { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// page is uncompressed, the buffer either stack or heap provided
|
|
|
|
// page is uncompressed, the buffer either stack or heap provided
|
|
|
|
if (got_from_prefetch_buffer_ || used_buf_ == &stack_buf_[0]) { |
|
|
|
if (got_from_prefetch_buffer_ || used_buf_ == &stack_buf_[0]) { |
|
|
|
heap_buf_ = std::unique_ptr<char[]>(new char[block_size_]); |
|
|
|
heap_buf_.reset(new char[block_size_]); |
|
|
|
memcpy(heap_buf_.get(), used_buf_, block_size_); |
|
|
|
memcpy(heap_buf_.get(), used_buf_, block_size_); |
|
|
|
} |
|
|
|
} |
|
|
|
*contents_ = BlockContents(std::move(heap_buf_), block_size_, true, |
|
|
|
*contents_ = BlockContents(std::move(heap_buf_), block_size_, true, |
|
|
|