Skip to content

Commit

Permalink
Run make format on PR XRPLF#249
Browse files Browse the repository at this point in the history
  • Loading branch information
igorcanadi committed Sep 17, 2014
1 parent 27b22f1 commit 54cada9
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 52 deletions.
3 changes: 1 addition & 2 deletions table/block.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion table/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 3 additions & 5 deletions table/block_based_filter_block.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion table/block_based_table_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions table/block_based_table_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
35 changes: 22 additions & 13 deletions table/format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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");
Expand Down
31 changes: 15 additions & 16 deletions table/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,28 +163,27 @@ struct BlockContents {
CompressionType compression_type;
std::unique_ptr<char[]> allocation;

BlockContents()
: cachable(false),
compression_type(kNoCompression) {}

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() : cachable(false), compression_type(kNoCompression) {}

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)) {}
};

// 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
Expand Down
9 changes: 4 additions & 5 deletions table/full_filter_block.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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);
}

Expand Down
12 changes: 8 additions & 4 deletions table/meta_blocks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand All @@ -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));
Expand Down

0 comments on commit 54cada9

Please sign in to comment.