mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-25 22:44:05 +00:00
Run make format on PR #249
This commit is contained in:
parent
27b22f13a3
commit
54cada92b1
|
@ -298,8 +298,7 @@ uint32_t Block::NumRestarts() const {
|
|||
}
|
||||
|
||||
Block::Block(const BlockContents& contents)
|
||||
: data_(contents.data.data()),
|
||||
size_(contents.data.size()) {
|
||||
: data_(contents.data.data()), size_(contents.data.size()) {
|
||||
if (size_ < sizeof(uint32_t)) {
|
||||
size_ = 0; // Error marker
|
||||
} else {
|
||||
|
|
|
@ -39,7 +39,9 @@ class Block {
|
|||
const char* data() const { return data_; }
|
||||
bool cachable() const { return contents_.cachable; }
|
||||
uint32_t NumRestarts() const;
|
||||
CompressionType compression_type() const { return contents_.compression_type; }
|
||||
CompressionType compression_type() const {
|
||||
return contents_.compression_type;
|
||||
}
|
||||
|
||||
// If hash index lookup is enabled and `use_hash_index` is true. This block
|
||||
// will do hash lookup for the key prefix.
|
||||
|
|
|
@ -137,8 +137,7 @@ void BlockBasedFilterBlockBuilder::GenerateFilter() {
|
|||
|
||||
BlockBasedFilterBlockReader::BlockBasedFilterBlockReader(
|
||||
const SliceTransform* prefix_extractor,
|
||||
const BlockBasedTableOptions& table_opt,
|
||||
const Slice& contents)
|
||||
const BlockBasedTableOptions& table_opt, const Slice& contents)
|
||||
: policy_(table_opt.filter_policy.get()),
|
||||
prefix_extractor_(prefix_extractor),
|
||||
whole_key_filtering_(table_opt.whole_key_filtering),
|
||||
|
@ -159,9 +158,8 @@ BlockBasedFilterBlockReader::BlockBasedFilterBlockReader(
|
|||
|
||||
BlockBasedFilterBlockReader::BlockBasedFilterBlockReader(
|
||||
const SliceTransform* prefix_extractor,
|
||||
const BlockBasedTableOptions& table_opt,
|
||||
BlockContents &&contents)
|
||||
: BlockBasedFilterBlockReader (prefix_extractor, table_opt, contents.data) {
|
||||
const BlockBasedTableOptions& table_opt, BlockContents&& contents)
|
||||
: BlockBasedFilterBlockReader(prefix_extractor, table_opt, contents.data) {
|
||||
contents_ = std::move(contents);
|
||||
}
|
||||
|
||||
|
|
|
@ -635,7 +635,7 @@ Status BlockBasedTableBuilder::InsertBlockInCache(const Slice& block_contents,
|
|||
Cache::Handle* cache_handle = nullptr;
|
||||
size_t size = block_contents.size();
|
||||
|
||||
std::unique_ptr<char[]> ubuf(new char[size+1]);
|
||||
std::unique_ptr<char[]> ubuf(new char[size + 1]);
|
||||
memcpy(ubuf.get(), block_contents.data(), size);
|
||||
ubuf[size] = type;
|
||||
|
||||
|
|
|
@ -298,8 +298,7 @@ class HashIndexReader : public IndexReader {
|
|||
|
||||
private:
|
||||
HashIndexReader(const Comparator* comparator, Block* index_block)
|
||||
: IndexReader(comparator),
|
||||
index_block_(index_block) {
|
||||
: IndexReader(comparator), index_block_(index_block) {
|
||||
assert(index_block_ != nullptr);
|
||||
}
|
||||
|
||||
|
@ -746,15 +745,16 @@ FilterBlockReader* BlockBasedTable::ReadFilter(
|
|||
|
||||
assert(rep->filter_policy);
|
||||
if (kFilterBlockPrefix == filter_block_prefix) {
|
||||
return new BlockBasedFilterBlockReader(rep->ioptions.prefix_extractor,
|
||||
rep->table_options, std::move(block));
|
||||
return new BlockBasedFilterBlockReader(
|
||||
rep->ioptions.prefix_extractor, rep->table_options, std::move(block));
|
||||
} else if (kFullFilterBlockPrefix == filter_block_prefix) {
|
||||
auto filter_bits_reader = rep->filter_policy->
|
||||
GetFilterBitsReader(block.data);
|
||||
|
||||
if (filter_bits_reader != nullptr) {
|
||||
return new FullFilterBlockReader(rep->ioptions.prefix_extractor,
|
||||
rep->table_options, std::move(block), filter_bits_reader);
|
||||
rep->table_options, std::move(block),
|
||||
filter_bits_reader);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
|
|
@ -257,19 +257,20 @@ Status ReadBlock(RandomAccessFile* file, const Footer& footer,
|
|||
|
||||
Status ReadBlockContents(RandomAccessFile* file, const Footer& footer,
|
||||
const ReadOptions& options, const BlockHandle& handle,
|
||||
BlockContents *contents, Env* env,
|
||||
BlockContents* contents, Env* env,
|
||||
bool decompression_requested) {
|
||||
Status status;
|
||||
Slice slice;
|
||||
size_t n = static_cast<size_t>(handle.size());
|
||||
std::unique_ptr<char[]> heap_buf;
|
||||
char stack_buf[DefaultStackBufferSize];
|
||||
char *used_buf = nullptr;
|
||||
char* used_buf = nullptr;
|
||||
rocksdb::CompressionType compression_type;
|
||||
|
||||
if (decompression_requested && n + kBlockTrailerSize < DefaultStackBufferSize) {
|
||||
//If we've got a small enough hunk of data, read it in to the
|
||||
//trivially allocated stack buffer instead of needing a full malloc()
|
||||
if (decompression_requested &&
|
||||
n + kBlockTrailerSize < DefaultStackBufferSize) {
|
||||
// If we've got a small enough hunk of data, read it in to the
|
||||
// trivially allocated stack buffer instead of needing a full malloc()
|
||||
used_buf = &stack_buf[0];
|
||||
} else {
|
||||
heap_buf = std::unique_ptr<char[]>(new char[n + kBlockTrailerSize]);
|
||||
|
@ -331,40 +332,48 @@ Status UncompressBlockContents(const char* data, size_t n,
|
|||
break;
|
||||
}
|
||||
case kZlibCompression:
|
||||
ubuf = std::unique_ptr<char[]>(port::Zlib_Uncompress(data, n, &decompress_size));
|
||||
ubuf = std::unique_ptr<char[]>(
|
||||
port::Zlib_Uncompress(data, n, &decompress_size));
|
||||
static char zlib_corrupt_msg[] =
|
||||
"Zlib not supported or corrupted Zlib compressed block contents";
|
||||
if (!ubuf) {
|
||||
return Status::Corruption(zlib_corrupt_msg);
|
||||
}
|
||||
*contents = BlockContents(std::move(ubuf), decompress_size, true, kNoCompression);
|
||||
*contents =
|
||||
BlockContents(std::move(ubuf), decompress_size, true, kNoCompression);
|
||||
break;
|
||||
case kBZip2Compression:
|
||||
ubuf = std::unique_ptr<char[]>(port::BZip2_Uncompress(data, n, &decompress_size));
|
||||
ubuf = std::unique_ptr<char[]>(
|
||||
port::BZip2_Uncompress(data, n, &decompress_size));
|
||||
static char bzip2_corrupt_msg[] =
|
||||
"Bzip2 not supported or corrupted Bzip2 compressed block contents";
|
||||
if (!ubuf) {
|
||||
return Status::Corruption(bzip2_corrupt_msg);
|
||||
}
|
||||
*contents = BlockContents(std::move(ubuf), decompress_size, true, kNoCompression);
|
||||
*contents =
|
||||
BlockContents(std::move(ubuf), decompress_size, true, kNoCompression);
|
||||
break;
|
||||
case kLZ4Compression:
|
||||
ubuf = std::unique_ptr<char[]>(port::LZ4_Uncompress(data, n, &decompress_size));
|
||||
ubuf = std::unique_ptr<char[]>(
|
||||
port::LZ4_Uncompress(data, n, &decompress_size));
|
||||
static char lz4_corrupt_msg[] =
|
||||
"LZ4 not supported or corrupted LZ4 compressed block contents";
|
||||
if (!ubuf) {
|
||||
return Status::Corruption(lz4_corrupt_msg);
|
||||
}
|
||||
*contents = BlockContents(std::move(ubuf), decompress_size, true, kNoCompression);
|
||||
*contents =
|
||||
BlockContents(std::move(ubuf), decompress_size, true, kNoCompression);
|
||||
break;
|
||||
case kLZ4HCCompression:
|
||||
ubuf = std::unique_ptr<char[]>(port::LZ4_Uncompress(data, n, &decompress_size));
|
||||
ubuf = std::unique_ptr<char[]>(
|
||||
port::LZ4_Uncompress(data, n, &decompress_size));
|
||||
static char lz4hc_corrupt_msg[] =
|
||||
"LZ4HC not supported or corrupted LZ4HC compressed block contents";
|
||||
if (!ubuf) {
|
||||
return Status::Corruption(lz4hc_corrupt_msg);
|
||||
}
|
||||
*contents = BlockContents(std::move(ubuf), decompress_size, true, kNoCompression);
|
||||
*contents =
|
||||
BlockContents(std::move(ubuf), decompress_size, true, kNoCompression);
|
||||
break;
|
||||
default:
|
||||
return Status::Corruption("bad block type");
|
||||
|
|
|
@ -163,28 +163,27 @@ struct BlockContents {
|
|||
CompressionType compression_type;
|
||||
std::unique_ptr<char[]> allocation;
|
||||
|
||||
BlockContents()
|
||||
: cachable(false),
|
||||
compression_type(kNoCompression) {}
|
||||
BlockContents() : cachable(false), compression_type(kNoCompression) {}
|
||||
|
||||
BlockContents(const Slice &_data, bool _cachable, CompressionType _compression_type)
|
||||
: data(_data),
|
||||
cachable(_cachable),
|
||||
compression_type(_compression_type) {}
|
||||
BlockContents(const Slice& _data, bool _cachable,
|
||||
CompressionType _compression_type)
|
||||
: data(_data), cachable(_cachable), compression_type(_compression_type) {}
|
||||
|
||||
BlockContents(std::unique_ptr<char[]> &&_data, size_t _size, bool _cachable, CompressionType _compression_type)
|
||||
: data(_data.get(), _size),
|
||||
cachable(_cachable),
|
||||
compression_type(_compression_type),
|
||||
allocation(std::move(_data)) {}
|
||||
BlockContents(std::unique_ptr<char[]>&& _data, size_t _size, bool _cachable,
|
||||
CompressionType _compression_type)
|
||||
: data(_data.get(), _size),
|
||||
cachable(_cachable),
|
||||
compression_type(_compression_type),
|
||||
allocation(std::move(_data)) {}
|
||||
};
|
||||
|
||||
// Read the block identified by "handle" from "file". On failure
|
||||
// return non-OK. On success fill *result and return OK.
|
||||
extern Status ReadBlockContents(RandomAccessFile* file, const Footer& footer,
|
||||
const ReadOptions& options,
|
||||
const BlockHandle& handle, BlockContents* contents,
|
||||
Env* env, bool do_uncompress);
|
||||
const BlockHandle& handle,
|
||||
BlockContents* contents, Env* env,
|
||||
bool do_uncompress);
|
||||
|
||||
// The 'data' points to the raw block contents read in from file.
|
||||
// This method allocates a new heap buffer and the raw block
|
||||
|
|
|
@ -54,8 +54,7 @@ Slice FullFilterBlockBuilder::Finish() {
|
|||
|
||||
FullFilterBlockReader::FullFilterBlockReader(
|
||||
const SliceTransform* prefix_extractor,
|
||||
const BlockBasedTableOptions& table_opt,
|
||||
const Slice& contents,
|
||||
const BlockBasedTableOptions& table_opt, const Slice& contents,
|
||||
FilterBitsReader* filter_bits_reader)
|
||||
: prefix_extractor_(prefix_extractor),
|
||||
whole_key_filtering_(table_opt.whole_key_filtering),
|
||||
|
@ -66,10 +65,10 @@ FullFilterBlockReader::FullFilterBlockReader(
|
|||
|
||||
FullFilterBlockReader::FullFilterBlockReader(
|
||||
const SliceTransform* prefix_extractor,
|
||||
const BlockBasedTableOptions& table_opt,
|
||||
BlockContents&& contents,
|
||||
const BlockBasedTableOptions& table_opt, BlockContents&& contents,
|
||||
FilterBitsReader* filter_bits_reader)
|
||||
: FullFilterBlockReader(prefix_extractor, table_opt, contents.data, filter_bits_reader) {
|
||||
: FullFilterBlockReader(prefix_extractor, table_opt, contents.data,
|
||||
filter_bits_reader) {
|
||||
block_contents_ = std::move(contents);
|
||||
}
|
||||
|
||||
|
|
|
@ -229,8 +229,8 @@ Status ReadTableProperties(RandomAccessFile* file, uint64_t file_size,
|
|||
BlockContents metaindex_contents;
|
||||
ReadOptions read_options;
|
||||
read_options.verify_checksums = false;
|
||||
s = ReadBlockContents(file, footer, read_options, metaindex_handle, &metaindex_contents,
|
||||
env, false);
|
||||
s = ReadBlockContents(file, footer, read_options, metaindex_handle,
|
||||
&metaindex_contents, env, false);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
@ -303,7 +303,9 @@ Status ReadMetaBlock(RandomAccessFile* file, uint64_t file_size,
|
|||
Status status;
|
||||
Footer footer(table_magic_number);
|
||||
status = ReadFooterFromFile(file, file_size, &footer);
|
||||
if (!status.ok()) return status;
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
// Reading metaindex block
|
||||
auto metaindex_handle = footer.metaindex_handle();
|
||||
|
@ -312,7 +314,9 @@ Status ReadMetaBlock(RandomAccessFile* file, uint64_t file_size,
|
|||
read_options.verify_checksums = false;
|
||||
status = ReadBlockContents(file, footer, read_options, metaindex_handle,
|
||||
&metaindex_contents, env, false);
|
||||
if (!status.ok()) return status;
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
// Finding metablock
|
||||
Block metaindex_block(std::move(metaindex_contents));
|
||||
|
|
Loading…
Reference in a new issue