From 98094f6caca6a5c0d2cff4c36f3bfdc7c1fcb7b6 Mon Sep 17 00:00:00 2001 From: Levi Tamasi Date: Fri, 24 May 2019 11:16:47 -0700 Subject: [PATCH] Add some comments for BlockContents Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/5354 Differential Revision: D15496645 Pulled By: ltamasi fbshipit-source-id: 1282b1ce11fbc412d3d87b2688fd0586e7bb6b85 --- table/format.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/table/format.h b/table/format.h index f585885055..84242303ec 100644 --- a/table/format.h +++ b/table/format.h @@ -194,6 +194,10 @@ inline CompressionType get_block_compression_type(const char* block_data, return static_cast(block_data[block_size]); } +// Represents the contents of a block read from an SST file. Depending on how +// it's created, it may or may not own the actual block bytes. As an example, +// BlockContents objects representing data read from mmapped files only point +// into the mmapped region. struct BlockContents { Slice data; // Actual contents of data CacheAllocationPtr allocation; @@ -206,16 +210,20 @@ struct BlockContents { BlockContents() {} + // Does not take ownership of the underlying data bytes. BlockContents(const Slice& _data) : data(_data) {} + // Takes ownership of the underlying data bytes. BlockContents(CacheAllocationPtr&& _data, size_t _size) : data(_data.get(), _size), allocation(std::move(_data)) {} + // Takes ownership of the underlying data bytes. BlockContents(std::unique_ptr&& _data, size_t _size) : data(_data.get(), _size) { allocation.reset(_data.release()); } + // Returns whether the object has ownership of the underlying data bytes. bool own_bytes() const { return allocation.get() != nullptr; } // It's the caller's responsibility to make sure that this is