Run make format on PR #249

main
Igor Canadi 10 years ago
parent 27b22f13a3
commit 54cada92b1
  1. 3
      table/block.cc
  2. 4
      table/block.h
  3. 8
      table/block_based_filter_block.cc
  4. 2
      table/block_based_table_builder.cc
  5. 10
      table/block_based_table_reader.cc
  6. 35
      table/format.cc
  7. 31
      table/format.h
  8. 9
      table/full_filter_block.cc
  9. 12
      table/meta_blocks.cc

@ -298,8 +298,7 @@ uint32_t Block::NumRestarts() const {
} }
Block::Block(const BlockContents& contents) Block::Block(const BlockContents& contents)
: data_(contents.data.data()), : data_(contents.data.data()), size_(contents.data.size()) {
size_(contents.data.size()) {
if (size_ < sizeof(uint32_t)) { if (size_ < sizeof(uint32_t)) {
size_ = 0; // Error marker size_ = 0; // Error marker
} else { } else {

@ -39,7 +39,9 @@ class Block {
const char* data() const { return data_; } const char* data() const { return data_; }
bool cachable() const { return contents_.cachable; } bool cachable() const { return contents_.cachable; }
uint32_t NumRestarts() const; 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 // If hash index lookup is enabled and `use_hash_index` is true. This block
// will do hash lookup for the key prefix. // will do hash lookup for the key prefix.

@ -137,8 +137,7 @@ void BlockBasedFilterBlockBuilder::GenerateFilter() {
BlockBasedFilterBlockReader::BlockBasedFilterBlockReader( BlockBasedFilterBlockReader::BlockBasedFilterBlockReader(
const SliceTransform* prefix_extractor, const SliceTransform* prefix_extractor,
const BlockBasedTableOptions& table_opt, const BlockBasedTableOptions& table_opt, const Slice& contents)
const Slice& contents)
: policy_(table_opt.filter_policy.get()), : policy_(table_opt.filter_policy.get()),
prefix_extractor_(prefix_extractor), prefix_extractor_(prefix_extractor),
whole_key_filtering_(table_opt.whole_key_filtering), whole_key_filtering_(table_opt.whole_key_filtering),
@ -159,9 +158,8 @@ BlockBasedFilterBlockReader::BlockBasedFilterBlockReader(
BlockBasedFilterBlockReader::BlockBasedFilterBlockReader( BlockBasedFilterBlockReader::BlockBasedFilterBlockReader(
const SliceTransform* prefix_extractor, const SliceTransform* prefix_extractor,
const BlockBasedTableOptions& table_opt, const BlockBasedTableOptions& table_opt, BlockContents&& contents)
BlockContents &&contents) : BlockBasedFilterBlockReader(prefix_extractor, table_opt, contents.data) {
: BlockBasedFilterBlockReader (prefix_extractor, table_opt, contents.data) {
contents_ = std::move(contents); contents_ = std::move(contents);
} }

@ -635,7 +635,7 @@ Status BlockBasedTableBuilder::InsertBlockInCache(const Slice& block_contents,
Cache::Handle* cache_handle = nullptr; Cache::Handle* cache_handle = nullptr;
size_t size = block_contents.size(); 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); memcpy(ubuf.get(), block_contents.data(), size);
ubuf[size] = type; ubuf[size] = type;

@ -298,8 +298,7 @@ class HashIndexReader : public IndexReader {
private: private:
HashIndexReader(const Comparator* comparator, Block* index_block) HashIndexReader(const Comparator* comparator, Block* index_block)
: IndexReader(comparator), : IndexReader(comparator), index_block_(index_block) {
index_block_(index_block) {
assert(index_block_ != nullptr); assert(index_block_ != nullptr);
} }
@ -746,15 +745,16 @@ FilterBlockReader* BlockBasedTable::ReadFilter(
assert(rep->filter_policy); assert(rep->filter_policy);
if (kFilterBlockPrefix == filter_block_prefix) { if (kFilterBlockPrefix == filter_block_prefix) {
return new BlockBasedFilterBlockReader(rep->ioptions.prefix_extractor, return new BlockBasedFilterBlockReader(
rep->table_options, std::move(block)); rep->ioptions.prefix_extractor, rep->table_options, std::move(block));
} else if (kFullFilterBlockPrefix == filter_block_prefix) { } else if (kFullFilterBlockPrefix == filter_block_prefix) {
auto filter_bits_reader = rep->filter_policy-> auto filter_bits_reader = rep->filter_policy->
GetFilterBitsReader(block.data); GetFilterBitsReader(block.data);
if (filter_bits_reader != nullptr) { if (filter_bits_reader != nullptr) {
return new FullFilterBlockReader(rep->ioptions.prefix_extractor, 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; return nullptr;

@ -257,19 +257,20 @@ Status ReadBlock(RandomAccessFile* file, const Footer& footer,
Status ReadBlockContents(RandomAccessFile* file, const Footer& footer, Status ReadBlockContents(RandomAccessFile* file, const Footer& footer,
const ReadOptions& options, const BlockHandle& handle, const ReadOptions& options, const BlockHandle& handle,
BlockContents *contents, Env* env, BlockContents* contents, Env* env,
bool decompression_requested) { bool decompression_requested) {
Status status; Status status;
Slice slice; Slice slice;
size_t n = static_cast<size_t>(handle.size()); size_t n = static_cast<size_t>(handle.size());
std::unique_ptr<char[]> heap_buf; std::unique_ptr<char[]> heap_buf;
char stack_buf[DefaultStackBufferSize]; char stack_buf[DefaultStackBufferSize];
char *used_buf = nullptr; char* used_buf = nullptr;
rocksdb::CompressionType compression_type; rocksdb::CompressionType compression_type;
if (decompression_requested && n + kBlockTrailerSize < DefaultStackBufferSize) { if (decompression_requested &&
//If we've got a small enough hunk of data, read it in to the n + kBlockTrailerSize < DefaultStackBufferSize) {
//trivially allocated stack buffer instead of needing a full malloc() // 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]; used_buf = &stack_buf[0];
} else { } else {
heap_buf = std::unique_ptr<char[]>(new char[n + kBlockTrailerSize]); heap_buf = std::unique_ptr<char[]>(new char[n + kBlockTrailerSize]);
@ -331,40 +332,48 @@ Status UncompressBlockContents(const char* data, size_t n,
break; break;
} }
case kZlibCompression: 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[] = static char zlib_corrupt_msg[] =
"Zlib not supported or corrupted Zlib compressed block contents"; "Zlib not supported or corrupted Zlib compressed block contents";
if (!ubuf) { if (!ubuf) {
return Status::Corruption(zlib_corrupt_msg); 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; break;
case kBZip2Compression: 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[] = static char bzip2_corrupt_msg[] =
"Bzip2 not supported or corrupted Bzip2 compressed block contents"; "Bzip2 not supported or corrupted Bzip2 compressed block contents";
if (!ubuf) { if (!ubuf) {
return Status::Corruption(bzip2_corrupt_msg); 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; break;
case kLZ4Compression: 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[] = static char lz4_corrupt_msg[] =
"LZ4 not supported or corrupted LZ4 compressed block contents"; "LZ4 not supported or corrupted LZ4 compressed block contents";
if (!ubuf) { if (!ubuf) {
return Status::Corruption(lz4_corrupt_msg); 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; break;
case kLZ4HCCompression: 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[] = static char lz4hc_corrupt_msg[] =
"LZ4HC not supported or corrupted LZ4HC compressed block contents"; "LZ4HC not supported or corrupted LZ4HC compressed block contents";
if (!ubuf) { if (!ubuf) {
return Status::Corruption(lz4hc_corrupt_msg); 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; break;
default: default:
return Status::Corruption("bad block type"); return Status::Corruption("bad block type");

@ -163,28 +163,27 @@ struct BlockContents {
CompressionType compression_type; CompressionType compression_type;
std::unique_ptr<char[]> allocation; std::unique_ptr<char[]> allocation;
BlockContents() BlockContents() : cachable(false), compression_type(kNoCompression) {}
: cachable(false),
compression_type(kNoCompression) {} BlockContents(const Slice& _data, bool _cachable,
CompressionType _compression_type)
BlockContents(const Slice &_data, bool _cachable, CompressionType _compression_type) : data(_data), cachable(_cachable), compression_type(_compression_type) {}
: data(_data),
cachable(_cachable), BlockContents(std::unique_ptr<char[]>&& _data, size_t _size, bool _cachable,
compression_type(_compression_type) {} CompressionType _compression_type)
: data(_data.get(), _size),
BlockContents(std::unique_ptr<char[]> &&_data, size_t _size, bool _cachable, CompressionType _compression_type) cachable(_cachable),
: data(_data.get(), _size), compression_type(_compression_type),
cachable(_cachable), allocation(std::move(_data)) {}
compression_type(_compression_type),
allocation(std::move(_data)) {}
}; };
// Read the block identified by "handle" from "file". On failure // Read the block identified by "handle" from "file". On failure
// return non-OK. On success fill *result and return OK. // return non-OK. On success fill *result and return OK.
extern Status ReadBlockContents(RandomAccessFile* file, const Footer& footer, extern Status ReadBlockContents(RandomAccessFile* file, const Footer& footer,
const ReadOptions& options, const ReadOptions& options,
const BlockHandle& handle, BlockContents* contents, const BlockHandle& handle,
Env* env, bool do_uncompress); BlockContents* contents, Env* env,
bool do_uncompress);
// The 'data' points to the raw block contents read in from file. // The 'data' points to the raw block contents read in from file.
// This method allocates a new heap buffer and the raw block // This method allocates a new heap buffer and the raw block

@ -54,8 +54,7 @@ Slice FullFilterBlockBuilder::Finish() {
FullFilterBlockReader::FullFilterBlockReader( FullFilterBlockReader::FullFilterBlockReader(
const SliceTransform* prefix_extractor, const SliceTransform* prefix_extractor,
const BlockBasedTableOptions& table_opt, const BlockBasedTableOptions& table_opt, const Slice& contents,
const Slice& contents,
FilterBitsReader* filter_bits_reader) FilterBitsReader* filter_bits_reader)
: prefix_extractor_(prefix_extractor), : prefix_extractor_(prefix_extractor),
whole_key_filtering_(table_opt.whole_key_filtering), whole_key_filtering_(table_opt.whole_key_filtering),
@ -66,10 +65,10 @@ FullFilterBlockReader::FullFilterBlockReader(
FullFilterBlockReader::FullFilterBlockReader( FullFilterBlockReader::FullFilterBlockReader(
const SliceTransform* prefix_extractor, const SliceTransform* prefix_extractor,
const BlockBasedTableOptions& table_opt, const BlockBasedTableOptions& table_opt, BlockContents&& contents,
BlockContents&& contents,
FilterBitsReader* filter_bits_reader) 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); block_contents_ = std::move(contents);
} }

@ -229,8 +229,8 @@ Status ReadTableProperties(RandomAccessFile* file, uint64_t file_size,
BlockContents metaindex_contents; BlockContents metaindex_contents;
ReadOptions read_options; ReadOptions read_options;
read_options.verify_checksums = false; read_options.verify_checksums = false;
s = ReadBlockContents(file, footer, read_options, metaindex_handle, &metaindex_contents, s = ReadBlockContents(file, footer, read_options, metaindex_handle,
env, false); &metaindex_contents, env, false);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
@ -303,7 +303,9 @@ Status ReadMetaBlock(RandomAccessFile* file, uint64_t file_size,
Status status; Status status;
Footer footer(table_magic_number); Footer footer(table_magic_number);
status = ReadFooterFromFile(file, file_size, &footer); status = ReadFooterFromFile(file, file_size, &footer);
if (!status.ok()) return status; if (!status.ok()) {
return status;
}
// Reading metaindex block // Reading metaindex block
auto metaindex_handle = footer.metaindex_handle(); auto metaindex_handle = footer.metaindex_handle();
@ -312,7 +314,9 @@ Status ReadMetaBlock(RandomAccessFile* file, uint64_t file_size,
read_options.verify_checksums = false; read_options.verify_checksums = false;
status = ReadBlockContents(file, footer, read_options, metaindex_handle, status = ReadBlockContents(file, footer, read_options, metaindex_handle,
&metaindex_contents, env, false); &metaindex_contents, env, false);
if (!status.ok()) return status; if (!status.ok()) {
return status;
}
// Finding metablock // Finding metablock
Block metaindex_block(std::move(metaindex_contents)); Block metaindex_block(std::move(metaindex_contents));

Loading…
Cancel
Save