Skip to content

Commit

Permalink
Add some comments for BlockContents
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: facebook#5354

Differential Revision: D15496645

Pulled By: ltamasi

fbshipit-source-id: 1282b1ce11fbc412d3d87b2688fd0586e7bb6b85
  • Loading branch information
ltamasi authored and facebook-github-bot committed May 24, 2019
1 parent 88ff807 commit 98094f6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions table/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ inline CompressionType get_block_compression_type(const char* block_data,
return static_cast<CompressionType>(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;
Expand All @@ -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<char[]>&& _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
Expand Down

0 comments on commit 98094f6

Please sign in to comment.