This is an automated email from the ASF dual-hosted git repository.
achennaka pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new 780f6d27c [cfile] minor clean-up
780f6d27c is described below
commit 780f6d27ce292473dda2b728a10b6296cb2a20df
Author: Alexey Serbin <[email protected]>
AuthorDate: Thu Aug 1 17:57:31 2024 -0700
[cfile] minor clean-up
I'm going to post more patches updating the code in src/kudu/cfile, so
I think it makes sense to update the code to be more style-compliant
and make other minor improvements in a separate patch.
This patch:
* unifies using CHECK/DCHECK assertions, changing CHECK to DCHECK
where appropriate
* adds PREDICT_TRUE/PREDICT_FALSE for paths with Status::Corruption()
* fixes signed/unsigned comparison
* updates the code to be compliant with the current coding style
* replaces include guard macros with '#pragma once'
Otherwise, there aren't any functional modifications in this patch.
Change-Id: Ied096e13b546f29db1ae202f2814b7c5f1529c41
Reviewed-on: http://gerrit.cloudera.org:8080/21632
Tested-by: Alexey Serbin <[email protected]>
Reviewed-by: Mahesh Reddy <[email protected]>
Reviewed-by: Abhishek Chennaka <[email protected]>
---
src/kudu/cfile/binary_dict_block.cc | 27 +++---
src/kudu/cfile/binary_dict_block.h | 4 +-
src/kudu/cfile/binary_plain_block.cc | 70 +++++++-------
src/kudu/cfile/binary_plain_block.h | 16 ++--
src/kudu/cfile/binary_prefix_block.cc | 175 +++++++++++++++++-----------------
src/kudu/cfile/binary_prefix_block.h | 36 +++----
src/kudu/cfile/block_cache-test.cc | 10 +-
src/kudu/cfile/block_cache.h | 2 -
src/kudu/cfile/block_compression.cc | 2 +-
src/kudu/cfile/block_compression.h | 4 +-
src/kudu/cfile/block_encodings.h | 21 ++--
src/kudu/cfile/block_handle.h | 5 +-
src/kudu/cfile/bloomfile-test-base.cc | 2 +-
src/kudu/cfile/bloomfile-test.cc | 6 +-
src/kudu/cfile/bloomfile.cc | 32 +++----
src/kudu/cfile/bloomfile.h | 6 +-
src/kudu/cfile/bshuf_block.h | 16 ++--
src/kudu/cfile/cfile-test-base.h | 10 +-
src/kudu/cfile/cfile-test.cc | 8 +-
src/kudu/cfile/cfile_reader.cc | 16 ++--
src/kudu/cfile/cfile_util.cc | 4 +-
src/kudu/cfile/cfile_writer.cc | 32 +++----
src/kudu/cfile/cfile_writer.h | 8 +-
src/kudu/cfile/encoding-test.cc | 24 ++---
src/kudu/cfile/index_btree.cc | 6 +-
src/kudu/cfile/plain_bitmap_block.h | 6 +-
src/kudu/cfile/plain_block.h | 29 +++---
src/kudu/cfile/rle_block.h | 20 ++--
src/kudu/cfile/type_encodings.h | 5 +-
29 files changed, 293 insertions(+), 309 deletions(-)
diff --git a/src/kudu/cfile/binary_dict_block.cc
b/src/kudu/cfile/binary_dict_block.cc
index 53cbfb40d..74ca863ae 100644
--- a/src/kudu/cfile/binary_dict_block.cc
+++ b/src/kudu/cfile/binary_dict_block.cc
@@ -48,6 +48,7 @@
#include "kudu/util/memory/arena.h"
using std::vector;
+using strings::Substitute;
namespace kudu {
namespace cfile {
@@ -171,7 +172,7 @@ size_t BinaryDictBlockBuilder::Count() const {
Status BinaryDictBlockBuilder::GetFirstKey(void* key_void) const {
if (mode_ == kCodeWordMode) {
- CHECK(finished_);
+ DCHECK(finished_);
Slice* slice = reinterpret_cast<Slice*>(key_void);
*slice = Slice(first_key_);
return Status::OK();
@@ -182,7 +183,7 @@ Status BinaryDictBlockBuilder::GetFirstKey(void* key_void)
const {
Status BinaryDictBlockBuilder::GetLastKey(void* key_void) const {
if (mode_ == kCodeWordMode) {
- CHECK(finished_);
+ DCHECK(finished_);
uint32_t last_codeword;
RETURN_NOT_OK(data_builder_->GetLastKey(reinterpret_cast<void*>(&last_codeword)));
return dict_block_.GetKeyAtIdx(key_void, last_codeword);
@@ -206,17 +207,17 @@
BinaryDictBlockDecoder::BinaryDictBlockDecoder(scoped_refptr<BlockHandle> block,
}
Status BinaryDictBlockDecoder::ParseHeader() {
- CHECK(!parsed_);
+ DCHECK(!parsed_);
- if (data_.size() < kMinHeaderSize) {
- return Status::Corruption(
- strings::Substitute("not enough bytes for header: dictionary block
header "
+ if (PREDICT_FALSE(data_.size() < kMinHeaderSize)) {
+ return Status::Corruption(Substitute(
+ "not enough bytes for header: dictionary block header "
"size ($0) less than minimum possible header length ($1)",
data_.size(), kMinHeaderSize));
}
- bool valid =
tight_enum_test_cast<DictEncodingMode>(DecodeFixed32(&data_[0]), &mode_);
- if (PREDICT_FALSE(!valid)) {
+ if (PREDICT_FALSE(!tight_enum_test_cast<DictEncodingMode>(
+ DecodeFixed32(&data_[0]), &mode_))) {
return Status::Corruption("header Mode information corrupted");
}
auto sub_block = block_->SubrangeBlock(4, data_.size() - 4);
@@ -224,7 +225,7 @@ Status BinaryDictBlockDecoder::ParseHeader() {
if (mode_ == kCodeWordMode) {
data_decoder_.reset(new BShufBlockDecoder<UINT32>(std::move(sub_block)));
} else {
- if (mode_ != kPlainBinaryMode) {
+ if (PREDICT_FALSE(mode_ != kPlainBinaryMode)) {
return Status::Corruption("Unrecognized Dictionary encoded data block
header");
}
data_decoder_.reset(new BinaryPlainBlockDecoder(std::move(sub_block)));
@@ -277,7 +278,7 @@ Status BinaryDictBlockDecoder::CopyNextAndEval(size_t* n,
// Predicates that have no matching words should return no data.
SelectionVector* codewords_matching_pred =
parent_cfile_iter_->GetCodeWordsMatchingPredicate();
- CHECK(codewords_matching_pred != nullptr);
+ DCHECK(codewords_matching_pred != nullptr);
if (!codewords_matching_pred->AnySelected()) {
// If nothing is selected, move the data_decoder_ pointer forward and clear
// the corresponding bits in the selection vector.
@@ -306,7 +307,7 @@ Status BinaryDictBlockDecoder::CopyNextAndEval(size_t* n,
if (!sel->TestBit(i)) {
continue;
}
- uint32_t codeword =
*reinterpret_cast<uint32_t*>(&codeword_buf_[i*sizeof(uint32_t)]);
+ uint32_t codeword = *reinterpret_cast<uint32_t*>(&codeword_buf_[i *
sizeof(uint32_t)]);
if (BitmapTest(codewords_matching_pred->bitmap(), codeword)) {
// Row is included in predicate: point the cell in the block
// to the entry in the dictionary.
@@ -325,7 +326,7 @@ Status BinaryDictBlockDecoder::CopyNextAndEval(size_t* n,
Status BinaryDictBlockDecoder::CopyNextDecodeStrings(size_t* n,
ColumnDataView* dst) {
DCHECK(parsed_);
- CHECK_EQ(dst->type_info()->physical_type(), BINARY);
+ DCHECK_EQ(dst->type_info()->physical_type(), BINARY);
DCHECK_LE(*n, dst->nrows());
DCHECK_EQ(dst->stride(), sizeof(Slice));
@@ -340,7 +341,7 @@ Status
BinaryDictBlockDecoder::CopyNextDecodeStrings(size_t* n, ColumnDataView*
// Now point the cells in the destination block to the string data in the
dictionary
// block.
for (int i = 0; i < *n; i++) {
- uint32_t codeword =
*reinterpret_cast<uint32_t*>(&codeword_buf_[i*sizeof(uint32_t)]);
+ uint32_t codeword = *reinterpret_cast<uint32_t*>(&codeword_buf_[i *
sizeof(uint32_t)]);
*out++ = dict_decoder_->string_at_index(codeword);
}
dst->memory()->RetainReference(dict_decoder_->block_handle());
diff --git a/src/kudu/cfile/binary_dict_block.h
b/src/kudu/cfile/binary_dict_block.h
index 80825ca3c..c653be1e8 100644
--- a/src/kudu/cfile/binary_dict_block.h
+++ b/src/kudu/cfile/binary_dict_block.h
@@ -117,7 +117,7 @@ class BinaryDictBlockBuilder final : public BlockBuilder {
// They should NOT be cleared in the Reset() method.
BinaryPlainBlockBuilder dict_block_;
- google::dense_hash_map<StringPiece, uint32_t, GoodFastHash<StringPiece> >
dictionary_;
+ google::dense_hash_map<StringPiece, uint32_t, GoodFastHash<StringPiece>>
dictionary_;
// Memory to hold the actual content for strings in the dictionary_.
//
// The size of it should be bigger than the size limit for dictionary block
@@ -163,7 +163,7 @@ class BinaryDictBlockDecoder final : public BlockDecoder {
return data_decoder_->GetFirstRowId();
}
- static const size_t kMinHeaderSize = sizeof(uint32_t) * 1;
+ static constexpr const size_t kMinHeaderSize = sizeof(uint32_t) * 1;
private:
Status CopyNextDecodeStrings(size_t* n, ColumnDataView* dst);
diff --git a/src/kudu/cfile/binary_plain_block.cc
b/src/kudu/cfile/binary_plain_block.cc
index bd1597d24..8d4f8d218 100644
--- a/src/kudu/cfile/binary_plain_block.cc
+++ b/src/kudu/cfile/binary_plain_block.cc
@@ -36,7 +36,6 @@
#include "kudu/common/schema.h"
#include "kudu/common/types.h"
#include "kudu/gutil/port.h"
-#include "kudu/gutil/stringprintf.h"
#include "kudu/gutil/strings/substitute.h"
#include "kudu/util/coding.h"
#include "kudu/util/coding-inl.h"
@@ -44,17 +43,17 @@
#include "kudu/util/hexdump.h"
using std::vector;
+using strings::Substitute;
namespace kudu {
namespace cfile {
-BinaryPlainBlockBuilder::BinaryPlainBlockBuilder(const WriterOptions *options)
- : options_(options),
- end_of_data_offset_(0),
- size_estimate_(0) {
+BinaryPlainBlockBuilder::BinaryPlainBlockBuilder(const WriterOptions* options)
+ : options_(options),
+ end_of_data_offset_(0),
+ size_estimate_(0) {
Reset();
}
-BinaryPlainBlockBuilder::~BinaryPlainBlockBuilder() = default;
void BinaryPlainBlockBuilder::Reset() {
offsets_.clear();
@@ -89,7 +88,7 @@ void BinaryPlainBlockBuilder::Finish(rowid_t ordinal_pos,
vector<Slice>* slices)
*slices = { Slice(buffer_) };
}
-int BinaryPlainBlockBuilder::Add(const uint8_t *vals, size_t count) {
+int BinaryPlainBlockBuilder::Add(const uint8_t* vals, size_t count) {
DCHECK(!finished_);
DCHECK_GT(count, 0);
size_t i = 0;
@@ -104,7 +103,7 @@ int BinaryPlainBlockBuilder::Add(const uint8_t *vals,
size_t count) {
size_estimate_++;
}
- const Slice *src = reinterpret_cast<const Slice *>(vals);
+ const Slice* src = reinterpret_cast<const Slice*>(vals);
size_t offset = buffer_.size();
offsets_.push_back(offset);
size_estimate_ += coding::CalcRequiredBytes32(offset);
@@ -126,10 +125,10 @@ size_t BinaryPlainBlockBuilder::Count() const {
return offsets_.size();
}
-Status BinaryPlainBlockBuilder::GetKeyAtIdx(void *key_void, int idx) const {
- Slice *slice = reinterpret_cast<Slice *>(key_void);
+Status BinaryPlainBlockBuilder::GetKeyAtIdx(void* key_void, uint32_t idx)
const {
+ Slice* slice = reinterpret_cast<Slice*>(key_void);
- if (idx >= offsets_.size()) {
+ if (PREDICT_FALSE(idx >= offsets_.size())) {
return Status::InvalidArgument("index too large");
}
@@ -138,25 +137,23 @@ Status BinaryPlainBlockBuilder::GetKeyAtIdx(void
*key_void, int idx) const {
}
if (PREDICT_FALSE(offsets_.size() == 1)) {
- *slice = Slice(&buffer_[kHeaderSize],
- end_of_data_offset_ - kHeaderSize);
+ *slice = Slice(&buffer_[kHeaderSize], end_of_data_offset_ - kHeaderSize);
} else if (idx + 1 == offsets_.size()) {
- *slice = Slice(&buffer_[offsets_[idx]],
- end_of_data_offset_ - offsets_[idx]);
+ *slice = Slice(&buffer_[offsets_[idx]], end_of_data_offset_ -
offsets_[idx]);
} else {
- *slice = Slice(&buffer_[offsets_[idx]],
- offsets_[idx + 1] - offsets_[idx]);
+ *slice = Slice(&buffer_[offsets_[idx]], offsets_[idx + 1] - offsets_[idx]);
}
return Status::OK();
}
-Status BinaryPlainBlockBuilder::GetFirstKey(void *key_void) const {
- CHECK(finished_);
+Status BinaryPlainBlockBuilder::GetFirstKey(void* key_void) const {
+ DCHECK(finished_);
return GetKeyAtIdx(key_void, 0);
}
-Status BinaryPlainBlockBuilder::GetLastKey(void *key_void) const {
- CHECK(finished_);
+Status BinaryPlainBlockBuilder::GetLastKey(void* key_void) const {
+ DCHECK(finished_);
+ DCHECK(!offsets_.empty());
return GetKeyAtIdx(key_void, offsets_.size() - 1);
}
@@ -172,14 +169,13 @@
BinaryPlainBlockDecoder::BinaryPlainBlockDecoder(scoped_refptr<BlockHandle> bloc
ordinal_pos_base_(0),
cur_idx_(0) {
}
-BinaryPlainBlockDecoder::~BinaryPlainBlockDecoder() = default;
Status BinaryPlainBlockDecoder::ParseHeader() {
- CHECK(!parsed_);
+ DCHECK(!parsed_);
- if (data_.size() < kMinHeaderSize) {
- return Status::Corruption(
- strings::Substitute("not enough bytes for header: string block header "
+ if (PREDICT_FALSE(data_.size() < kMinHeaderSize)) {
+ return Status::Corruption(Substitute(
+ "not enough bytes for header: string block header "
"size ($0) less than minimum possible header length ($1)",
data_.size(), kMinHeaderSize));
}
@@ -190,15 +186,15 @@ Status BinaryPlainBlockDecoder::ParseHeader() {
size_t offsets_pos = DecodeFixed32(&data_[8]);
// Sanity check.
- if (offsets_pos > data_.size()) {
- return Status::Corruption(
- StringPrintf("offsets_pos %ld > block size %ld in plain string block",
- offsets_pos, data_.size()));
+ if (PREDICT_FALSE(offsets_pos > data_.size())) {
+ return Status::Corruption(Substitute(
+ "offsets_pos $0 > block size $0 in plain string block",
+ offsets_pos, data_.size()));
}
// Decode the string offsets themselves
- const uint8_t *p = data_.data() + offsets_pos;
- const uint8_t *limit = data_.data() + data_.size();
+ const uint8_t* p = data_.data() + offsets_pos;
+ const uint8_t* limit = data_.data() + data_.size();
// Reserve one extra element, which we'll fill in at the end
// with an offset past the last element.
@@ -264,10 +260,10 @@ void BinaryPlainBlockDecoder::SeekToPositionInBlock(uint
pos) {
cur_idx_ = pos;
}
-Status BinaryPlainBlockDecoder::SeekAtOrAfterValue(const void *value_void,
bool *exact) {
+Status BinaryPlainBlockDecoder::SeekAtOrAfterValue(const void* value_void,
bool* exact) {
DCHECK(value_void != nullptr);
- const Slice &target = *reinterpret_cast<const Slice *>(value_void);
+ const Slice& target = *reinterpret_cast<const Slice*>(value_void);
// Binary search in restart array to find the first restart point
// with a key >= target
@@ -299,7 +295,7 @@ Status BinaryPlainBlockDecoder::SeekAtOrAfterValue(const
void *value_void, bool
template <typename CellHandler>
Status BinaryPlainBlockDecoder::HandleBatch(size_t* n, ColumnDataView* dst,
CellHandler c) {
DCHECK(parsed_);
- CHECK_EQ(dst->type_info()->physical_type(), BINARY);
+ DCHECK_EQ(dst->type_info()->physical_type(), BINARY);
DCHECK_LE(*n, dst->nrows());
DCHECK_EQ(dst->stride(), sizeof(Slice));
if (PREDICT_FALSE(*n == 0 || cur_idx_ >= num_elems_)) {
@@ -308,7 +304,7 @@ Status BinaryPlainBlockDecoder::HandleBatch(size_t* n,
ColumnDataView* dst, Cell
}
size_t max_fetch = std::min(*n, static_cast<size_t>(num_elems_ - cur_idx_));
- Slice *out = reinterpret_cast<Slice*>(dst->data());
+ Slice* out = reinterpret_cast<Slice*>(dst->data());
for (size_t i = 0; i < max_fetch; i++, out++, cur_idx_++) {
Slice elem(string_at_index(cur_idx_));
c(i, elem, out);
@@ -320,7 +316,7 @@ Status BinaryPlainBlockDecoder::HandleBatch(size_t* n,
ColumnDataView* dst, Cell
Status BinaryPlainBlockDecoder::CopyNextValues(size_t* n, ColumnDataView* dst)
{
dst->memory()->RetainReference(block_);
return HandleBatch(n, dst, [&](size_t /*i*/, Slice elem, Slice* out) {
- *out = elem;
+ *out = elem;
});
}
diff --git a/src/kudu/cfile/binary_plain_block.h
b/src/kudu/cfile/binary_plain_block.h
index a65abae70..8bea41a27 100644
--- a/src/kudu/cfile/binary_plain_block.h
+++ b/src/kudu/cfile/binary_plain_block.h
@@ -58,12 +58,11 @@ struct WriterOptions;
class BinaryPlainBlockBuilder final : public BlockBuilder {
public:
- explicit BinaryPlainBlockBuilder(const WriterOptions *options);
- ~BinaryPlainBlockBuilder() override;
+ explicit BinaryPlainBlockBuilder(const WriterOptions* options);
bool IsBlockFull() const override;
- int Add(const uint8_t *vals, size_t count) override;
+ int Add(const uint8_t* vals, size_t count) override;
void Finish(rowid_t ordinal_pos, std::vector<Slice>* slices) override;
@@ -73,7 +72,7 @@ class BinaryPlainBlockBuilder final : public BlockBuilder {
// Return the key at index idx.
// key should be a Slice*
- Status GetKeyAtIdx(void* key_void, int idx) const;
+ Status GetKeyAtIdx(void* key_void, uint32_t idx) const;
// Return the first added key.
// key should be a Slice*
@@ -106,7 +105,6 @@ class BinaryPlainBlockDecoder final : public BlockDecoder {
BinaryPlainBlockDecoder(BinaryPlainBlockDecoder&& other) noexcept {
*this = std::move(other);
}
- ~BinaryPlainBlockDecoder() override;
BinaryPlainBlockDecoder& operator=(BinaryPlainBlockDecoder&& other) noexcept
{
block_ = std::move(other.block_);
@@ -122,9 +120,9 @@ class BinaryPlainBlockDecoder final : public BlockDecoder {
Status ParseHeader() override;
void SeekToPositionInBlock(uint pos) override;
- Status SeekAtOrAfterValue(const void *value,
- bool *exact_match) override;
- Status CopyNextValues(size_t *n, ColumnDataView *dst) override;
+ Status SeekAtOrAfterValue(const void* value,
+ bool* exact_match) override;
+ Status CopyNextValues(size_t* n, ColumnDataView* dst) override;
Status CopyNextAndEval(size_t* n,
ColumnMaterializationContext* ctx,
SelectionVectorView* sel,
@@ -160,7 +158,7 @@ class BinaryPlainBlockDecoder final : public BlockDecoder {
}
// Minimum length of a header.
- static const size_t kMinHeaderSize = sizeof(uint32_t) * 3;
+ static constexpr const size_t kMinHeaderSize = sizeof(uint32_t) * 3;
private:
// Helper template for handling batches of rows. CellHandler is a lambda that
diff --git a/src/kudu/cfile/binary_prefix_block.cc
b/src/kudu/cfile/binary_prefix_block.cc
index 9f2f85bec..0b053448c 100644
--- a/src/kudu/cfile/binary_prefix_block.cc
+++ b/src/kudu/cfile/binary_prefix_block.cc
@@ -33,7 +33,6 @@
#include "kudu/common/schema.h"
#include "kudu/common/types.h"
#include "kudu/gutil/port.h"
-#include "kudu/gutil/stringprintf.h"
#include "kudu/gutil/strings/fastmem.h"
#include "kudu/gutil/strings/substitute.h"
#include "kudu/util/coding.h"
@@ -44,24 +43,28 @@
#include "kudu/util/memory/arena.h"
#include "kudu/util/slice.h"
-namespace kudu {
-namespace cfile {
-
using kudu::coding::AppendGroupVarInt32;
using std::string;
using std::vector;
using strings::Substitute;
+namespace kudu {
+namespace cfile {
+
////////////////////////////////////////////////////////////
// Utility code used by both encoding and decoding
////////////////////////////////////////////////////////////
-static const uint8_t *DecodeEntryLengths(
- const uint8_t *ptr, const uint8_t *limit,
- uint32_t *shared, uint32_t *non_shared) {
-
- if ((ptr = GetVarint32Ptr(ptr, limit, shared)) == nullptr) return nullptr;
- if ((ptr = GetVarint32Ptr(ptr, limit, non_shared)) == nullptr) return
nullptr;
+static const uint8_t* DecodeEntryLengths(const uint8_t* ptr,
+ const uint8_t* limit,
+ uint32_t* shared,
+ uint32_t* non_shared) {
+ if ((ptr = GetVarint32Ptr(ptr, limit, shared)) == nullptr) {
+ return nullptr;
+ }
+ if ((ptr = GetVarint32Ptr(ptr, limit, non_shared)) == nullptr) {
+ return nullptr;
+ }
if (limit - ptr < *non_shared) {
return nullptr;
}
@@ -73,11 +76,11 @@ static const uint8_t *DecodeEntryLengths(
// StringPrefixBlockBuilder encoding
////////////////////////////////////////////////////////////
-BinaryPrefixBlockBuilder::BinaryPrefixBlockBuilder(const WriterOptions
*options)
- : options_(options),
- val_count_(0),
- vals_since_restart_(0),
- finished_(false) {
+BinaryPrefixBlockBuilder::BinaryPrefixBlockBuilder(const WriterOptions*
options)
+ : options_(options),
+ val_count_(0),
+ vals_since_restart_(0),
+ finished_(false) {
Reset();
}
@@ -99,7 +102,7 @@ bool BinaryPrefixBlockBuilder::IsBlockFull() const {
}
void BinaryPrefixBlockBuilder::Finish(rowid_t ordinal_pos, vector<Slice>*
slices) {
- CHECK(!finished_) << "already finished";
+ DCHECK(!finished_) << "already finished";
header_buf_.clear();
AppendGroupVarInt32(&header_buf_, val_count_, ordinal_pos,
@@ -123,15 +126,15 @@ void BinaryPrefixBlockBuilder::Finish(rowid_t
ordinal_pos, vector<Slice>* slices
*slices = { Slice(header_buf_), Slice(buffer_) };
}
-int BinaryPrefixBlockBuilder::Add(const uint8_t *vals, size_t count) {
+int BinaryPrefixBlockBuilder::Add(const uint8_t* vals, size_t count) {
DCHECK_GT(count, 0);
DCHECK(!finished_);
DCHECK_LE(vals_since_restart_, options_->block_restart_interval);
- int added = 0;
+ size_t added = 0;
const Slice* slices = reinterpret_cast<const Slice*>(vals);
Slice prev_val(last_val_);
- while (!IsBlockFull() && added < count) {
+ while (added < count && !IsBlockFull()) {
const Slice val = slices[added];
int old_size = buffer_.size();
@@ -177,31 +180,33 @@ size_t BinaryPrefixBlockBuilder::Count() const {
}
-Status BinaryPrefixBlockBuilder::GetFirstKey(void *key) const {
+Status BinaryPrefixBlockBuilder::GetFirstKey(void* key) const {
if (val_count_ == 0) {
return Status::NotFound("no keys in data block");
}
- const uint8_t *p = &buffer_[0];
+ const uint8_t* p = &buffer_[0];
uint32_t shared;
uint32_t non_shared;
p = DecodeEntryLengths(p, &buffer_[buffer_.size()], &shared, &non_shared);
- if (p == nullptr) {
+ if (PREDICT_FALSE(p == nullptr)) {
return Status::Corruption("Could not decode first entry in string block");
}
- CHECK(shared == 0) << "first entry in string block had a non-zero 'shared': "
- << shared;
+ if (PREDICT_FALSE(shared != 0)) {
+ return Status::Corruption(Substitute(
+ "first entry in string block had a non-zero 'shared': $0", shared));
+ }
- *reinterpret_cast<Slice *>(key) = Slice(p, non_shared);
+ *reinterpret_cast<Slice*>(key) = Slice(p, non_shared);
return Status::OK();
}
-Status BinaryPrefixBlockBuilder::GetLastKey(void *key) const {
- if (val_count_ == 0) {
+Status BinaryPrefixBlockBuilder::GetLastKey(void* key) const {
+ if (PREDICT_FALSE(val_count_ == 0)) {
return Status::NotFound("no keys in data block");
}
- *reinterpret_cast<Slice *>(key) = Slice(last_val_);
+ *reinterpret_cast<Slice*>(key) = Slice(last_val_);
return Status::OK();
}
@@ -229,21 +234,21 @@ Status BinaryPrefixBlockDecoder::ParseHeader() {
// Make sure the Slice we are referring to is at least the size of the
// minimum possible header
if (PREDICT_FALSE(data_.size() < kMinHeaderSize)) {
- return Status::Corruption(
- strings::Substitute("not enough bytes for header: string block header "
+ return Status::Corruption(Substitute(
+ "not enough bytes for header: string block header "
"size ($0) less than minimum possible header length ($1)",
data_.size(), kMinHeaderSize));
- // TODO include hexdump
+ // TODO(dsw): include hexdump
}
// Make sure the actual size of the group varints in the Slice we are
// referring to is as big as it claims to be
size_t header_size = coding::DecodeGroupVarInt32_GetGroupSize(data_.data());
if (PREDICT_FALSE(data_.size() < header_size)) {
- return Status::Corruption(
- strings::Substitute("string block header size ($0) less than length "
+ return Status::Corruption(Substitute(
+ "string block header size ($0) less than length "
"from in header ($1)", data_.size(), header_size));
- // TODO include hexdump
+ // TODO(dsw): include hexdump
}
// We should have enough space in the Slice to decode the group varints
@@ -255,24 +260,24 @@ Status BinaryPrefixBlockDecoder::ParseHeader() {
&restart_interval_, &unused);
// Then the footer, which points us to the restarts array
- num_restarts_ = DecodeFixed32(
- data_.data() + data_.size() - sizeof(uint32_t));
+ num_restarts_ = DecodeFixed32(data_.data() + data_.size() -
sizeof(uint32_t));
// sanity check the restarts size
uint32_t restarts_size = num_restarts_ * sizeof(uint32_t);
- if (restarts_size > data_.size()) {
- return Status::Corruption(
- StringPrintf("restart count %d too big to fit in block size %d",
- num_restarts_, static_cast<int>(data_.size())));
+ if (PREDICT_FALSE(restarts_size > data_.size())) {
+ return Status::Corruption(Substitute(
+ "restart count $0 too big to fit in block size $1",
+ num_restarts_, static_cast<int>(data_.size())));
}
- // TODO: check relationship between num_elems, num_restarts_,
+ // TODO(todd): check relationship between num_elems, num_restarts_,
// and restart_interval_
- restarts_ = reinterpret_cast<const uint32_t *>(
- data_.data() + data_.size()
- - sizeof(uint32_t) // rewind before the restart length
- - restarts_size);
+ restarts_ = reinterpret_cast<const uint32_t*>(
+ data_.data() + data_.size() -
+ // rewind before the restart length
+ sizeof(uint32_t) -
+ restarts_size);
SeekToStart();
parsed_ = true;
@@ -313,7 +318,7 @@ void BinaryPrefixBlockDecoder::SeekToPositionInBlock(uint
pos) {
// the '0' restart point, since that is simply the beginning of
// the data and hence a waste of space. So, 'idx' may range from
// 0 (first record) through num_restarts_ (exclusive).
-const uint8_t * BinaryPrefixBlockDecoder::GetRestartPoint(uint32_t idx) const {
+const uint8_t* BinaryPrefixBlockDecoder::GetRestartPoint(uint32_t idx) const {
DCHECK_LE(idx, num_restarts_);
if (PREDICT_TRUE(idx > 0)) {
@@ -332,14 +337,14 @@ void
BinaryPrefixBlockDecoder::SeekToRestartPoint(uint32_t idx) {
next_ptr_ = GetRestartPoint(idx);
cur_idx_ = idx * restart_interval_;
- CHECK_OK(ParseNextValue()); // TODO: handle corrupted blocks
+ CHECK_OK(ParseNextValue()); // TODO(todd): handle corrupted blocks
}
-Status BinaryPrefixBlockDecoder::SeekAtOrAfterValue(const void *value_void,
- bool *exact_match) {
+Status BinaryPrefixBlockDecoder::SeekAtOrAfterValue(const void* value_void,
+ bool* exact_match) {
DCHECK(value_void != nullptr);
- const Slice &target = *reinterpret_cast<const Slice *>(value_void);
+ const Slice& target = *reinterpret_cast<const Slice*>(value_void);
// Binary search in restart array to find the first restart point
// with a key >= target
@@ -347,14 +352,14 @@ Status BinaryPrefixBlockDecoder::SeekAtOrAfterValue(const
void *value_void,
int32_t right = num_restarts_;
while (left < right) {
uint32_t mid = (left + right + 1) / 2;
- const uint8_t *entry = GetRestartPoint(mid);
- uint32_t shared, non_shared;
- const uint8_t *key_ptr = DecodeEntryLengths(entry, &shared, &non_shared);
- if (key_ptr == nullptr || (shared != 0)) {
- string err =
- StringPrintf("bad entry restart=%d shared=%d\n", mid, shared) +
- HexDump(Slice(entry, 16));
- return Status::Corruption(err);
+ const uint8_t* entry = GetRestartPoint(mid);
+ uint32_t shared;
+ uint32_t non_shared;
+ const uint8_t* key_ptr = DecodeEntryLengths(entry, &shared, &non_shared);
+ if (PREDICT_FALSE(key_ptr == nullptr || shared != 0)) {
+ return Status::Corruption(Substitute(
+ "bad entry restart=$0 shared=$1\n$2",
+ mid, shared, HexDump(Slice(entry, 16))));
}
const Slice mid_key(key_ptr, non_shared);
if (mid_key < target) {
@@ -388,15 +393,15 @@ Status BinaryPrefixBlockDecoder::SeekAtOrAfterValue(const
void *value_void,
}
}
-Status BinaryPrefixBlockDecoder::CopyNextValues(size_t *n, ColumnDataView
*dst) {
+Status BinaryPrefixBlockDecoder::CopyNextValues(size_t* n, ColumnDataView*
dst) {
DCHECK(parsed_);
- CHECK_EQ(dst->type_info()->physical_type(), BINARY);
+ DCHECK_EQ(dst->type_info()->physical_type(), BINARY);
DCHECK_EQ(dst->stride(), sizeof(Slice));
DCHECK_LE(*n, dst->nrows());
- Arena *out_arena = dst->arena();
- Slice *out = reinterpret_cast<Slice *>(dst->data());
+ Arena* out_arena = dst->arena();
+ Slice* out = reinterpret_cast<Slice*>(dst->data());
if (PREDICT_FALSE(*n == 0 || cur_idx_ >= num_elems_)) {
*n = 0;
@@ -407,11 +412,11 @@ Status BinaryPrefixBlockDecoder::CopyNextValues(size_t
*n, ColumnDataView *dst)
size_t max_fetch = std::min(*n, static_cast<size_t>(num_elems_ - cur_idx_));
// Grab the first row, which we've cached from the last call or seek.
- const uint8_t *out_data = out_arena->AddSlice(cur_val_);
+ const uint8_t* out_data = out_arena->AddSlice(cur_val_);
if (PREDICT_FALSE(out_data == nullptr)) {
return Status::IOError(
- "Out of memory",
- StringPrintf("Failed to allocate %d bytes in output arena",
+ "out of memory",
+ Substitute("failed to allocate $0 bytes in output arena",
static_cast<int>(cur_val_.size())));
}
@@ -454,11 +459,11 @@ Status BinaryPrefixBlockDecoder::CopyNextValues(size_t
*n, ColumnDataView *dst)
// Returns a pointer to where the value itself starts.
// Returns NULL if the varints themselves, or the value that
// they prefix extend past the end of the block data.
-const uint8_t *BinaryPrefixBlockDecoder::DecodeEntryLengths(
- const uint8_t *ptr, uint32_t *shared, uint32_t *non_shared) const {
+const uint8_t* BinaryPrefixBlockDecoder::DecodeEntryLengths(
+ const uint8_t* ptr, uint32_t* shared, uint32_t* non_shared) const {
// data ends where the restart info begins
- const uint8_t *limit = reinterpret_cast<const uint8_t *>(restarts_);
+ const uint8_t* limit = reinterpret_cast<const uint8_t*>(restarts_);
return kudu::cfile::DecodeEntryLengths(ptr, limit, shared, non_shared);
}
@@ -486,7 +491,7 @@ Status BinaryPrefixBlockDecoder::SkipForward(int n) {
Status BinaryPrefixBlockDecoder::CheckNextPtr() {
DCHECK(next_ptr_ != nullptr);
- if (PREDICT_FALSE(next_ptr_ == reinterpret_cast<const uint8_t
*>(restarts_))) {
+ if (PREDICT_FALSE(next_ptr_ == reinterpret_cast<const uint8_t*>(restarts_)))
{
DCHECK_EQ(cur_idx_, num_elems_ - 1);
return Status::NotFound("Trying to parse past end of array");
}
@@ -494,21 +499,21 @@ Status BinaryPrefixBlockDecoder::CheckNextPtr() {
}
inline Status BinaryPrefixBlockDecoder::ParseNextIntoArena(Slice prev_val,
- Arena *dst,
- Slice *copied) {
+ Arena* dst,
+ Slice* copied) {
RETURN_NOT_OK(CheckNextPtr());
- uint32_t shared, non_shared;
- const uint8_t *val_delta = DecodeEntryLengths(next_ptr_, &shared,
&non_shared);
- if (val_delta == nullptr) {
- return Status::Corruption(
- StringPrintf("Could not decode value length data at idx %d",
- cur_idx_));
+ uint32_t shared;
+ uint32_t non_shared;
+ const uint8_t* val_delta = DecodeEntryLengths(next_ptr_, &shared,
&non_shared);
+ if (PREDICT_FALSE(val_delta == nullptr)) {
+ return Status::Corruption(Substitute(
+ "could not decode value length data at idx $0", cur_idx_));
}
DCHECK_LE(shared, prev_val.size())
- << "Spcified longer shared amount than previous key length";
+ << "Specified longer shared amount than previous key length";
- uint8_t *buf = reinterpret_cast<uint8_t *>(dst->AllocateBytes(non_shared +
shared));
+ uint8_t* buf = reinterpret_cast<uint8_t*>(dst->AllocateBytes(non_shared +
shared));
strings::memcpy_inlined(buf, prev_val.data(), shared);
strings::memcpy_inlined(buf + shared, val_delta, non_shared);
@@ -523,12 +528,12 @@ inline Status
BinaryPrefixBlockDecoder::ParseNextIntoArena(Slice prev_val,
inline Status BinaryPrefixBlockDecoder::ParseNextValue() {
RETURN_NOT_OK(CheckNextPtr());
- uint32_t shared, non_shared;
- const uint8_t *val_delta = DecodeEntryLengths(next_ptr_, &shared,
&non_shared);
- if (val_delta == nullptr) {
- return Status::Corruption(
- StringPrintf("Could not decode value length data at idx %d",
- cur_idx_));
+ uint32_t shared;
+ uint32_t non_shared;
+ const uint8_t* val_delta = DecodeEntryLengths(next_ptr_, &shared,
&non_shared);
+ if (PREDICT_FALSE(val_delta == nullptr)) {
+ return Status::Corruption(Substitute(
+ "could not decode value length data at idx $0", cur_idx_));
}
// Chop the current key to the length that is shared with the next
diff --git a/src/kudu/cfile/binary_prefix_block.h
b/src/kudu/cfile/binary_prefix_block.h
index ea47fde7a..afffcd107 100644
--- a/src/kudu/cfile/binary_prefix_block.h
+++ b/src/kudu/cfile/binary_prefix_block.h
@@ -45,11 +45,11 @@ struct WriterOptions;
// This encodes in a manner similar to LevelDB (prefix coding).
class BinaryPrefixBlockBuilder final : public BlockBuilder {
public:
- explicit BinaryPrefixBlockBuilder(const WriterOptions *options);
+ explicit BinaryPrefixBlockBuilder(const WriterOptions* options);
bool IsBlockFull() const override;
- int Add(const uint8_t *vals, size_t count) override;
+ int Add(const uint8_t* vals, size_t count) override;
void Finish(rowid_t ordinal_pos, std::vector<Slice>* slices) override;
@@ -58,12 +58,12 @@ class BinaryPrefixBlockBuilder final : public BlockBuilder {
size_t Count() const override;
// Return the first added key.
- // key should be a Slice *
- Status GetFirstKey(void *key) const override;
+ // key should be a Slice*
+ Status GetFirstKey(void* key) const override;
// Return the last added key.
- // key should be a Slice *
- Status GetLastKey(void *key) const override;
+ // key should be a Slice*
+ Status GetLastKey(void* key) const override;
private:
const WriterOptions* const options_;
@@ -87,9 +87,9 @@ class BinaryPrefixBlockDecoder final : public BlockDecoder {
Status ParseHeader() override;
void SeekToPositionInBlock(uint pos) override;
- Status SeekAtOrAfterValue(const void *value,
- bool *exact_match) override;
- Status CopyNextValues(size_t *n, ColumnDataView *dst) override;
+ Status SeekAtOrAfterValue(const void* value,
+ bool* exact_match) override;
+ Status CopyNextValues(size_t* n, ColumnDataView* dst) override;
bool HasNext() const override {
DCHECK(parsed_);
@@ -113,19 +113,19 @@ class BinaryPrefixBlockDecoder final : public
BlockDecoder {
// Minimum length of a header.
// Currently one group of varints for an empty block, so minimum is 5 bytes.
- static const size_t kMinHeaderSize = 5;
+ static constexpr const size_t kMinHeaderSize = 5;
private:
Status SkipForward(int n);
Status CheckNextPtr();
Status ParseNextValue();
- Status ParseNextIntoArena(Slice prev_val, Arena *dst, Slice *copied);
+ Status ParseNextIntoArena(Slice prev_val, Arena* dst, Slice* copied);
- const uint8_t *DecodeEntryLengths(const uint8_t *ptr,
- uint32_t *shared,
- uint32_t *non_shared) const;
+ const uint8_t* DecodeEntryLengths(const uint8_t* ptr,
+ uint32_t* shared,
+ uint32_t* non_shared) const;
- const uint8_t *GetRestartPoint(uint32_t idx) const;
+ const uint8_t* GetRestartPoint(uint32_t idx) const;
void SeekToRestartPoint(uint32_t idx);
void SeekToStart();
@@ -139,10 +139,10 @@ class BinaryPrefixBlockDecoder final : public
BlockDecoder {
rowid_t ordinal_pos_base_;
uint32_t num_restarts_;
- const uint32_t *restarts_;
+ const uint32_t* restarts_;
uint32_t restart_interval_;
- const uint8_t *data_start_;
+ const uint8_t* data_start_;
// Index of the next row to be returned by CopyNextValues, relative to
// the block's base offset.
@@ -155,7 +155,7 @@ class BinaryPrefixBlockDecoder final : public BlockDecoder {
// The ptr pointing to the next element to parse. This is for the entry
// following cur_val_
// This is advanced by ParseNextValue()
- const uint8_t *next_ptr_;
+ const uint8_t* next_ptr_;
};
} // namespace cfile
diff --git a/src/kudu/cfile/block_cache-test.cc
b/src/kudu/cfile/block_cache-test.cc
index 3430180f3..bf87339e4 100644
--- a/src/kudu/cfile/block_cache-test.cc
+++ b/src/kudu/cfile/block_cache-test.cc
@@ -20,6 +20,8 @@
#include <cstring>
#include <memory>
#include <ostream>
+#include <string>
+#include <type_traits>
#include <gflags/gflags_declare.h>
#include <glog/logging.h>
@@ -34,14 +36,14 @@ DECLARE_double(cache_memtracker_approximation_ratio);
namespace kudu {
namespace cfile {
-static const char *DATA_TO_CACHE = "hello world";
+static const char* const kDataToCache = "hello world";
TEST(TestBlockCache, TestBasics) {
// Disable approximate tracking of cache memory since we make specific
// assertions on the MemTracker in this test.
FLAGS_cache_memtracker_approximation_ratio = 0;
- size_t data_size = strlen(DATA_TO_CACHE) + 1;
+ size_t data_size = strlen(kDataToCache) + 1;
BlockCache cache(512 * 1024 * 1024);
BlockCache::FileId id(1234);
BlockCache::CacheKey key(id, 1);
@@ -59,7 +61,7 @@ TEST(TestBlockCache, TestBasics) {
}
BlockCache::PendingEntry data = cache.Allocate(key, data_size);
- memcpy(data.val_ptr(), DATA_TO_CACHE, data_size);
+ memcpy(data.val_ptr(), kDataToCache, data_size);
// Insert and re-lookup
BlockCacheHandle inserted_handle;
@@ -77,7 +79,7 @@ TEST(TestBlockCache, TestBasics) {
ASSERT_TRUE(cache.Lookup(key, Cache::EXPECT_IN_CACHE, &retrieved_handle));
ASSERT_TRUE(retrieved_handle.valid());
- ASSERT_EQ(0, memcmp(retrieved_handle.data().data(), DATA_TO_CACHE,
data_size));
+ ASSERT_EQ(0, memcmp(retrieved_handle.data().data(), kDataToCache,
data_size));
// Ensure that a lookup for a different offset doesn't
// return this data.
diff --git a/src/kudu/cfile/block_cache.h b/src/kudu/cfile/block_cache.h
index a288fa55f..2deb716b6 100644
--- a/src/kudu/cfile/block_cache.h
+++ b/src/kudu/cfile/block_cache.h
@@ -184,8 +184,6 @@ class BlockCacheHandle {
return *this;
}
- ~BlockCacheHandle() = default;
-
// Swap this handle with another handle.
// This can be useful to transfer ownership of a handle by swapping
// with an empty BlockCacheHandle.
diff --git a/src/kudu/cfile/block_compression.cc
b/src/kudu/cfile/block_compression.cc
index e3f8a064c..68375dc82 100644
--- a/src/kudu/cfile/block_compression.cc
+++ b/src/kudu/cfile/block_compression.cc
@@ -139,7 +139,7 @@ Status CompressedBlockDecoder::Init() {
p += 4;
// Check that the on-disk data size matches with the buffer.
- if (data_.size() != header_length() + compressed_size) {
+ if (PREDICT_FALSE(data_.size() != header_length() + compressed_size)) {
return Status::Corruption(
Substitute("compressed size $0 does not match remaining length in
buffer $1, buffer: $2",
compressed_size, data_.size() - header_length(),
diff --git a/src/kudu/cfile/block_compression.h
b/src/kudu/cfile/block_compression.h
index cd426c7c9..0680e14d9 100644
--- a/src/kudu/cfile/block_compression.h
+++ b/src/kudu/cfile/block_compression.h
@@ -14,8 +14,7 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-#ifndef KUDU_CFILE_BLOCK_COMPRESSION_H
-#define KUDU_CFILE_BLOCK_COMPRESSION_H
+#pragma once
#include <cstddef>
#include <cstdint>
@@ -133,4 +132,3 @@ class CompressedBlockDecoder {
} // namespace cfile
} // namespace kudu
-#endif
diff --git a/src/kudu/cfile/block_encodings.h b/src/kudu/cfile/block_encodings.h
index 4728fcf86..62e7fba8c 100644
--- a/src/kudu/cfile/block_encodings.h
+++ b/src/kudu/cfile/block_encodings.h
@@ -14,9 +14,7 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-
-#ifndef KUDU_CFILE_BLOCK_ENCODINGS_H
-#define KUDU_CFILE_BLOCK_ENCODINGS_H
+#pragma once
#include <algorithm>
#include <cstdint>
@@ -46,7 +44,8 @@ class BlockBuilder {
// Append extra information to the end of the current cfile, for example:
// append the dictionary block for under dictionary encoding mode.
- virtual Status AppendExtraInfo(CFileWriter *c_writer, CFileFooterPB* footer)
{
+ virtual Status AppendExtraInfo(CFileWriter* /*c_writer*/,
+ CFileFooterPB* /*footer*/) {
return Status::OK();
}
@@ -59,7 +58,7 @@ class BlockBuilder {
// Add a sequence of values to the block.
// Returns the number of values actually added, which may be less
// than requested if the block is full.
- virtual int Add(const uint8_t *vals, size_t count) = 0;
+ virtual int Add(const uint8_t* vals, size_t count) = 0;
// Return one or more Slices which represents the encoded data.
// The multiple slices will be concatenated when appended to the file.
@@ -86,14 +85,14 @@ class BlockBuilder {
// data is only valid until the next call to Reset().
//
// If no keys have been added, returns Status::NotFound
- virtual Status GetFirstKey(void *key) const = 0;
+ virtual Status GetFirstKey(void* key) const = 0;
// Return the key of the last entry in this index block.
// For pointer-based types (such as strings), the pointed-to
// data is only valid until the next call to Reset().
//
// If no keys have been added, returns Status::NotFound
- virtual Status GetLastKey(void *key) const = 0;
+ virtual Status GetLastKey(void* key) const = 0;
private:
DISALLOW_COPY_AND_ASSIGN(BlockBuilder);
@@ -133,8 +132,8 @@ class BlockDecoder {
//
// This will only return valid results when the data block
// consists of values in sorted order.
- virtual Status SeekAtOrAfterValue(const void *value,
- bool *exact_match) = 0;
+ virtual Status SeekAtOrAfterValue(const void* value,
+ bool* exact_match) = 0;
// Seek the decoder forward by a given number of rows, or to the end
// of the block. This is primarily used to skip over data.
@@ -156,7 +155,7 @@ class BlockDecoder {
// In the case that the values are themselves references
// to other memory (eg Slices), the referred-to memory is
// allocated in the dst block's arena.
- virtual Status CopyNextValues(size_t *n, ColumnDataView *dst) = 0;
+ virtual Status CopyNextValues(size_t* n, ColumnDataView* dst) = 0;
// Fetch the next values from the block and evaluate whether they satisfy
// the predicate. Mark the row in the view into the selection vector. This
@@ -199,5 +198,3 @@ class BlockDecoder {
} // namespace cfile
} // namespace kudu
-
-#endif
diff --git a/src/kudu/cfile/block_handle.h b/src/kudu/cfile/block_handle.h
index b88d844c4..bcdaf543e 100644
--- a/src/kudu/cfile/block_handle.h
+++ b/src/kudu/cfile/block_handle.h
@@ -14,9 +14,7 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-
-#ifndef KUDU_CFILE_BLOCK_HANDLE_H
-#define KUDU_CFILE_BLOCK_HANDLE_H
+#pragma once
#include <memory>
@@ -102,4 +100,3 @@ class BlockHandle final : public
RefCountedThreadSafe<BlockHandle> {
} // namespace cfile
} // namespace kudu
-#endif
diff --git a/src/kudu/cfile/bloomfile-test-base.cc
b/src/kudu/cfile/bloomfile-test-base.cc
index de603e50d..955fa59cc 100644
--- a/src/kudu/cfile/bloomfile-test-base.cc
+++ b/src/kudu/cfile/bloomfile-test-base.cc
@@ -113,7 +113,7 @@ uint64_t BloomFileTestBase::ReadBenchmark() {
key = BigEndian::FromHost64(key);
- Slice s(reinterpret_cast<uint8_t *>(&key), sizeof(key));
+ Slice s(reinterpret_cast<uint8_t*>(&key), sizeof(key));
bool present;
CHECK_OK(bfr_->CheckKeyPresent(BloomKeyProbe(s), nullptr, &present));
if (present) count_present++;
diff --git a/src/kudu/cfile/bloomfile-test.cc b/src/kudu/cfile/bloomfile-test.cc
index 6c63aaaa6..206d045ca 100644
--- a/src/kudu/cfile/bloomfile-test.cc
+++ b/src/kudu/cfile/bloomfile-test.cc
@@ -21,6 +21,8 @@
#include <cstdlib>
#include <memory>
#include <ostream>
+#include <string>
+#include <type_traits>
#include <utility>
#include <gflags/gflags_declare.h>
@@ -60,7 +62,7 @@ class BloomFileTest : public BloomFileTestBase {
// Verify all the keys that we inserted probe as present.
for (uint64_t i = 0; i < FLAGS_n_keys; i++) {
uint64_t i_byteswapped = BigEndian::FromHost64(i << kKeyShift);
- Slice s(reinterpret_cast<char *>(&i_byteswapped), sizeof(i));
+ Slice s(reinterpret_cast<char*>(&i_byteswapped), sizeof(i));
bool present = false;
ASSERT_OK_FAST(bfr()->CheckKeyPresent(BloomKeyProbe(s), nullptr,
&present));
@@ -71,7 +73,7 @@ class BloomFileTest : public BloomFileTestBase {
// Check that the FP rate for keys we didn't insert is what we expect.
for (uint64_t i = 0; i < FLAGS_n_keys; i++) {
uint64_t key = random();
- Slice s(reinterpret_cast<char *>(&key), sizeof(key));
+ Slice s(reinterpret_cast<char*>(&key), sizeof(key));
bool present = false;
ASSERT_OK_FAST(bfr()->CheckKeyPresent(BloomKeyProbe(s), nullptr,
&present));
diff --git a/src/kudu/cfile/bloomfile.cc b/src/kudu/cfile/bloomfile.cc
index 42bd3dec4..8bdba97d0 100644
--- a/src/kudu/cfile/bloomfile.cc
+++ b/src/kudu/cfile/bloomfile.cc
@@ -134,9 +134,7 @@ size_t BloomFileWriter::written_size() const {
return writer_.written_size();
}
-Status BloomFileWriter::AppendKeys(
- const Slice *keys, size_t n_keys) {
-
+Status BloomFileWriter::AppendKeys(const Slice* keys, size_t n_keys) {
// If this is the call on a new bloom, copy the first key.
if (bloom_builder_.count() == 0 && n_keys > 0) {
first_key_.assign_copy(keys[0].data(), keys[0].size());
@@ -198,7 +196,7 @@ Status BloomFileWriter::FinishCurrentBloomBlock() {
Status BloomFileReader::Open(unique_ptr<ReadableBlock> block,
ReaderOptions options,
- unique_ptr<BloomFileReader> *reader) {
+ unique_ptr<BloomFileReader>* reader) {
unique_ptr<BloomFileReader> bf_reader;
const IOContext* io_context = options.io_context;
RETURN_NOT_OK(OpenNoInit(std::move(block),
@@ -211,10 +209,9 @@ Status BloomFileReader::Open(unique_ptr<ReadableBlock>
block,
Status BloomFileReader::OpenNoInit(unique_ptr<ReadableBlock> block,
ReaderOptions options,
- unique_ptr<BloomFileReader> *reader) {
+ unique_ptr<BloomFileReader>* reader) {
unique_ptr<CFileReader> cf_reader;
- RETURN_NOT_OK(CFileReader::OpenNoInit(std::move(block),
- options, &cf_reader));
+ RETURN_NOT_OK(CFileReader::OpenNoInit(std::move(block), options,
&cf_reader));
const IOContext* io_context = options.io_context;
unique_ptr<BloomFileReader> bf_reader(new BloomFileReader(
std::move(cf_reader), std::move(options)));
@@ -245,13 +242,14 @@ Status BloomFileReader::InitOnce(const IOContext*
io_context) {
// If it's already initialized, this is a no-op.
RETURN_NOT_OK(reader_->Init(io_context));
- if (reader_->is_compressed()) {
- return Status::NotSupported("bloom file is compressed (compression not
supported)",
- reader_->ToString());
+ if (PREDICT_FALSE(reader_->is_compressed())) {
+ return Status::NotSupported(
+ "bloom file is compressed (compression not supported)",
+ reader_->ToString());
}
- if (!reader_->has_validx()) {
- return Status::NotSupported("bloom file missing value index",
- reader_->ToString());
+ if (PREDICT_FALSE(!reader_->has_validx())) {
+ return Status::NotSupported(
+ "bloom file missing value index", reader_->ToString());
}
return Status::OK();
}
@@ -267,13 +265,13 @@ Status BloomFileReader::ParseBlockHeader(const Slice&
block,
uint32_t header_len = DecodeFixed32(data.data());
data.remove_prefix(sizeof(header_len));
- if (header_len > data.size()) {
+ if (PREDICT_FALSE(header_len > data.size())) {
return Status::Corruption(
StringPrintf("Header length %d doesn't fit in buffer of size %ld",
header_len, data.size()));
}
- if (!hdr->ParseFromArray(data.data(), header_len)) {
+ if (PREDICT_FALSE(!hdr->ParseFromArray(data.data(), header_len))) {
return Status::Corruption(
string("Invalid bloom block header: ") +
hdr->InitializationErrorString() +
@@ -285,9 +283,9 @@ Status BloomFileReader::ParseBlockHeader(const Slice& block,
return Status::OK();
}
-Status BloomFileReader::CheckKeyPresent(const BloomKeyProbe &probe,
+Status BloomFileReader::CheckKeyPresent(const BloomKeyProbe& probe,
const IOContext* io_context,
- bool *maybe_present) {
+ bool* maybe_present) {
DCHECK(init_once_.init_succeeded());
// Since we frequently will access the same BloomFile many times in a row
diff --git a/src/kudu/cfile/bloomfile.h b/src/kudu/cfile/bloomfile.h
index 366a9f6e9..1c1720db4 100644
--- a/src/kudu/cfile/bloomfile.h
+++ b/src/kudu/cfile/bloomfile.h
@@ -48,10 +48,10 @@ struct ReaderOptions;
class BloomFileWriter {
public:
BloomFileWriter(std::unique_ptr<fs::WritableBlock> block,
- const BloomFilterSizing &sizing);
+ const BloomFilterSizing& sizing);
Status Start();
- Status AppendKeys(const Slice *keys, size_t n_keys);
+ Status AppendKeys(const Slice* keys, size_t n_keys);
// Close the bloom's CFile, closing the underlying writable block.
Status Finish();
@@ -132,7 +132,7 @@ class BloomFileReader {
// Returns the parsed header inside *hdr, and returns
// a Slice to the true bloom filter data inside
// *bloom_data.
- Status ParseBlockHeader(const Slice &block,
+ Status ParseBlockHeader(const Slice& block,
BloomBlockHeaderPB* hdr,
Slice* bloom_data) const;
diff --git a/src/kudu/cfile/bshuf_block.h b/src/kudu/cfile/bshuf_block.h
index d8c4c6eeb..8036fca64 100644
--- a/src/kudu/cfile/bshuf_block.h
+++ b/src/kudu/cfile/bshuf_block.h
@@ -20,8 +20,7 @@
// UINT32, INT32, FLOAT, DOUBLE.
// Reference:
// https://github.com/kiyo-masui/bitshuffle.git
-#ifndef KUDU_CFILE_BSHUF_BLOCK_H
-#define KUDU_CFILE_BSHUF_BLOCK_H
+#pragma once
#include <sys/types.h>
@@ -245,8 +244,8 @@ class BShufBlockDecoder final : public BlockDecoder {
}
Status ParseHeader() override {
- CHECK(!parsed_);
- if (data_.size() < kHeaderSize) {
+ DCHECK(!parsed_);
+ if (PREDICT_FALSE(data_.size() < kHeaderSize)) {
return Status::Corruption(
strings::Substitute("not enough bytes for header: bitshuffle block
header "
"size ($0) less than expected header length ($1)",
@@ -256,11 +255,12 @@ class BShufBlockDecoder final : public BlockDecoder {
ordinal_pos_base_ = DecodeFixed32(&data_[0]);
num_elems_ = DecodeFixed32(&data_[4]);
compressed_size_ = DecodeFixed32(&data_[8]);
- if (compressed_size_ != data_.size()) {
+ if (PREDICT_FALSE(compressed_size_ != data_.size())) {
return Status::Corruption("Size Information unmatched");
}
num_elems_after_padding_ = DecodeFixed32(&data_[12]);
- if (num_elems_after_padding_ != KUDU_ALIGN_UP(num_elems_, 8)) {
+ if (PREDICT_FALSE(num_elems_after_padding_ !=
+ KUDU_ALIGN_UP(num_elems_, 8))) {
return Status::Corruption("num of element information corrupted");
}
size_of_elem_ = DecodeFixed32(&data_[16]);
@@ -292,7 +292,7 @@ class BShufBlockDecoder final : public BlockDecoder {
}
void SeekToPositionInBlock(uint pos) override {
- CHECK(parsed_) << "Must call ParseHeader()";
+ DCHECK(parsed_) << "Must call ParseHeader()";
if (PREDICT_FALSE(num_elems_ == 0)) {
DCHECK_EQ(0, pos);
return;
@@ -426,7 +426,5 @@ Status BShufBlockDecoder<UINT32>::SeekAtOrAfterValue(const
void* value_void, boo
template<>
Status BShufBlockDecoder<UINT32>::CopyNextValuesToArray(size_t* n, uint8_t*
array);
-
} // namespace cfile
} // namespace kudu
-#endif
diff --git a/src/kudu/cfile/cfile-test-base.h b/src/kudu/cfile/cfile-test-base.h
index 1e8a07544..20f981bbf 100644
--- a/src/kudu/cfile/cfile-test-base.h
+++ b/src/kudu/cfile/cfile-test-base.h
@@ -139,8 +139,8 @@ class DataGenerator {
size_t block_entries() const { return block_entries_; }
size_t total_entries() const { return total_entries_; }
- const cpp_type *values() const { return values_.get(); }
- const uint8_t *non_null_bitmap() const { return non_null_bitmap_.get(); }
+ const cpp_type* values() const { return values_.get(); }
+ const uint8_t* non_null_bitmap() const { return non_null_bitmap_.get(); }
const cpp_type& operator[](size_t index) const {
return values_[index];
@@ -302,7 +302,7 @@ class DuplicateStringDataGenerator : public
DataGenerator<STRING, HAS_NULLS> {
Slice BuildTestValue(size_t block_index, size_t value) override {
// random number from 0 ~ num_-1
value = random() % num_;
- char *buf = data_buffer_[block_index].data;
+ char* buf = data_buffer_[block_index].data;
int len = snprintf(buf, kItemBufferSize - 1, format_, value);
DCHECK_LT(len, kItemBufferSize);
return Slice(buf, len);
@@ -419,7 +419,7 @@ class CFileTestBase : public KuduTest {
// constant stride.
template<class Indexable, typename SumType>
ATTRIBUTE_NO_SANITIZE_INTEGER
-SumType FastSum(const Indexable &data, size_t n) {
+SumType FastSum(const Indexable& data, size_t n) {
SumType sums[4] = {0, 0, 0, 0};
size_t rem = n;
int i = 0;
@@ -476,7 +476,7 @@ void ReadBinaryFile(CFileIterator* iter, int* count) {
LOG(INFO) << "Count: " << *count;
}
-void TimeReadFile(FsManager* fs_manager, const BlockId& block_id, size_t
*count_ret) {
+void TimeReadFile(FsManager* fs_manager, const BlockId& block_id, size_t*
count_ret) {
Status s;
std::unique_ptr<fs::ReadableBlock> source;
diff --git a/src/kudu/cfile/cfile-test.cc b/src/kudu/cfile/cfile-test.cc
index 7098c84ac..42ca249f4 100644
--- a/src/kudu/cfile/cfile-test.cc
+++ b/src/kudu/cfile/cfile-test.cc
@@ -278,7 +278,7 @@ class TestCFile : public CFileTestBase {
slices.emplace_back("Head");
slices.emplace_back("Body");
slices.emplace_back("Tail");
- slices.emplace_back(reinterpret_cast<uint8_t *>(&i), 4);
+ slices.emplace_back(reinterpret_cast<uint8_t*>(&i), 4);
ASSERT_OK(w.AppendRawBlock(std::move(slices), i, nullptr, Slice(),
"raw-data"));
}
ASSERT_OK(w.Finish());
@@ -826,7 +826,7 @@ TEST_P(TestCFileBothCacheMemoryTypes,
TestDefaultColumnIter) {
ColumnMaterializationContext int_ctx = CreateNonDecoderEvalContext(&int_col,
&sel);
ASSERT_OK(iter.Scan(&int_ctx));
for (size_t i = 0; i < int_col.nrows(); ++i) {
- ASSERT_EQ(int_value, *reinterpret_cast<const uint32_t
*>(int_col.cell_ptr(i)));
+ ASSERT_EQ(int_value, *reinterpret_cast<const
uint32_t*>(int_col.cell_ptr(i)));
}
// Test Int Nullable Default Value
@@ -837,7 +837,7 @@ TEST_P(TestCFileBothCacheMemoryTypes,
TestDefaultColumnIter) {
ASSERT_OK(nullable_iter.Scan(&nullable_ctx));
for (size_t i = 0; i < nullable_col.nrows(); ++i) {
ASSERT_FALSE(nullable_col.is_null(i));
- ASSERT_EQ(int_value, *reinterpret_cast<const uint32_t
*>(nullable_col.cell_ptr(i)));
+ ASSERT_EQ(int_value, *reinterpret_cast<const
uint32_t*>(nullable_col.cell_ptr(i)));
}
// Test NULL Default Value
@@ -858,7 +858,7 @@ TEST_P(TestCFileBothCacheMemoryTypes,
TestDefaultColumnIter) {
ColumnMaterializationContext str_ctx = CreateNonDecoderEvalContext(&str_col,
&sel);
ASSERT_OK(str_iter.Scan(&str_ctx));
for (size_t i = 0; i < str_col.nrows(); ++i) {
- ASSERT_EQ(str_value, *reinterpret_cast<const Slice
*>(str_col.cell_ptr(i)));
+ ASSERT_EQ(str_value, *reinterpret_cast<const Slice*>(str_col.cell_ptr(i)));
}
}
diff --git a/src/kudu/cfile/cfile_reader.cc b/src/kudu/cfile/cfile_reader.cc
index 5f1968da5..b2b8e1eef 100644
--- a/src/kudu/cfile/cfile_reader.cc
+++ b/src/kudu/cfile/cfile_reader.cc
@@ -767,7 +767,7 @@ Status CFileIterator::SeekToOrdinal(rowid_t ord_idx) {
last_prepare_count_ = 0;
seeked_ = posidx_iter_.get();
- CHECK_EQ(ord_idx, GetCurrentOrdinal());
+ DCHECK_EQ(ord_idx, GetCurrentOrdinal());
return Status::OK();
}
@@ -928,7 +928,7 @@ Status CFileIterator::PrepareForNewSeek() {
}
rowid_t CFileIterator::GetCurrentOrdinal() const {
- CHECK(seeked_) << "not seeked";
+ DCHECK(seeked_) << "not seeked";
return last_prepare_idx_;
}
@@ -1015,15 +1015,15 @@ Status CFileIterator::QueueCurrentDataBlock(const
IndexTreeIterator& idx_iter) {
}
bool CFileIterator::HasNext() const {
- CHECK(seeked_) << "not seeked";
- CHECK(!prepared_) << "Cannot call HasNext() mid-batch";
+ DCHECK(seeked_) << "not seeked";
+ DCHECK(!prepared_) << "Cannot call HasNext() mid-batch";
return !prepared_blocks_.empty() || seeked_->HasNext();
}
Status CFileIterator::PrepareBatch(size_t* n) {
- CHECK(!prepared_) << "Should call FinishBatch() first";
- CHECK(seeked_ != nullptr) << "must be seeked";
+ DCHECK(!prepared_) << "Should call FinishBatch() first";
+ DCHECK(seeked_ != nullptr) << "must be seeked";
CHECK(!prepared_blocks_.empty());
@@ -1073,7 +1073,7 @@ Status CFileIterator::PrepareBatch(size_t* n) {
}
Status CFileIterator::FinishBatch() {
- CHECK(prepared_) << "no batch prepared";
+ DCHECK(prepared_) << "no batch prepared";
prepared_ = false;
DVLOG(1) << "Finishing batch " << last_prepare_idx_ << "-"
@@ -1115,7 +1115,7 @@ Status CFileIterator::FinishBatch() {
}
Status CFileIterator::Scan(ColumnMaterializationContext* ctx) {
- CHECK(seeked_) << "not seeked";
+ DCHECK(seeked_) << "not seeked";
// Use views to advance the block and selection vector as we read into them.
ColumnDataView remaining_dst(ctx->block());
diff --git a/src/kudu/cfile/cfile_util.cc b/src/kudu/cfile/cfile_util.cc
index 78ee67c25..95e131133 100644
--- a/src/kudu/cfile/cfile_util.cc
+++ b/src/kudu/cfile/cfile_util.cc
@@ -122,7 +122,7 @@ Status DumpIterator(const CFileReader& reader,
int indent) {
RowBlockMemory mem(8192);
uint8_t buf[kBufSize];
- const TypeInfo *type = reader.type_info();
+ const TypeInfo* type = reader.type_info();
size_t max_rows = kBufSize/type->size();
uint8_t nulls[BitmapSize(max_rows)];
ColumnBlock cb(type, reader.is_nullable() ? nulls : nullptr, buf, max_rows,
&mem);
@@ -139,7 +139,7 @@ Status DumpIterator(const CFileReader& reader,
if (reader.is_nullable()) {
for (size_t i = 0; i < n; i++) {
strbuf.append(indent, ' ');
- const void *ptr = cb.nullable_cell_ptr(i);
+ const void* ptr = cb.nullable_cell_ptr(i);
if (ptr != nullptr) {
type->AppendDebugStringForValue(ptr, &strbuf);
} else {
diff --git a/src/kudu/cfile/cfile_writer.cc b/src/kudu/cfile/cfile_writer.cc
index 03c8d7b06..af1e3b198 100644
--- a/src/kudu/cfile/cfile_writer.cc
+++ b/src/kudu/cfile/cfile_writer.cc
@@ -145,8 +145,7 @@ CFileWriter::~CFileWriter() {
Status CFileWriter::Start() {
TRACE_EVENT0("cfile", "CFileWriter::Start");
- CHECK(state_ == kWriterInitialized) <<
- "bad state for Start(): " << state_;
+ DCHECK(state_ == kWriterInitialized) << "bad state for Start(): " << state_;
if (compression_ != NO_COMPRESSION) {
const CompressionCodec* codec;
@@ -201,8 +200,7 @@ Status CFileWriter::Finish() {
Status CFileWriter::FinishAndReleaseBlock(BlockCreationTransaction*
transaction) {
TRACE_EVENT0("cfile", "CFileWriter::FinishAndReleaseBlock");
- CHECK(state_ == kWriterWriting) <<
- "Bad state for Finish(): " << state_;
+ DCHECK(state_ == kWriterWriting) << "Bad state for Finish(): " << state_;
// Write out any pending values as the last data block.
RETURN_NOT_OK(FinishCurDataBlock());
@@ -268,8 +266,8 @@ Status
CFileWriter::FinishAndReleaseBlock(BlockCreationTransaction* transaction)
return Status::OK();
}
-void CFileWriter::AddMetadataPair(const Slice &key, const Slice &value) {
- CHECK_NE(state_, kWriterFinished);
+void CFileWriter::AddMetadataPair(const Slice& key, const Slice& value) {
+ DCHECK_NE(state_, kWriterFinished);
unflushed_metadata_.emplace_back(key.ToString(), value.ToString());
}
@@ -284,22 +282,22 @@ string CFileWriter::GetMetaValueOrDie(Slice key) const {
LOG(FATAL) << "Missing metadata entry: " << KUDU_REDACT(key.ToDebugString());
}
-void CFileWriter::FlushMetadataToPB(RepeatedPtrField<FileMetadataPairPB>
*field) {
+void CFileWriter::FlushMetadataToPB(RepeatedPtrField<FileMetadataPairPB>*
field) {
typedef pair<string, string> ss_pair;
- for (const ss_pair &entry : unflushed_metadata_) {
- FileMetadataPairPB *pb = field->Add();
+ for (const ss_pair& entry : unflushed_metadata_) {
+ FileMetadataPairPB* pb = field->Add();
pb->set_key(entry.first);
pb->set_value(entry.second);
}
unflushed_metadata_.clear();
}
-Status CFileWriter::AppendEntries(const void *entries, size_t count) {
+Status CFileWriter::AppendEntries(const void* entries, size_t count) {
DCHECK(!is_nullable_);
int rem = count;
- const uint8_t *ptr = reinterpret_cast<const uint8_t *>(entries);
+ const uint8_t* ptr = reinterpret_cast<const uint8_t*>(entries);
while (rem > 0) {
int n = data_block_->Add(ptr, rem);
@@ -318,12 +316,12 @@ Status CFileWriter::AppendEntries(const void *entries,
size_t count) {
return Status::OK();
}
-Status CFileWriter::AppendNullableEntries(const uint8_t *bitmap,
- const void *entries,
+Status CFileWriter::AppendNullableEntries(const uint8_t* bitmap,
+ const void* entries,
size_t count) {
DCHECK(is_nullable_ && bitmap != nullptr);
- const uint8_t *ptr = reinterpret_cast<const uint8_t *>(entries);
+ const uint8_t* ptr = reinterpret_cast<const uint8_t*>(entries);
size_t nitems;
bool is_non_null = false;
@@ -398,7 +396,7 @@ Status CFileWriter::FinishCurDataBlock() {
}
std::move(data_slices.begin(), data_slices.end(), std::back_inserter(v));
s = AppendRawBlock(std::move(v), first_elem_ord,
- reinterpret_cast<const void *>(key_tmp_space),
+ reinterpret_cast<const void*>(key_tmp_space),
Slice(last_key_),
"data block");
}
@@ -421,7 +419,7 @@ Status CFileWriter::AppendRawBlock(vector<Slice>
data_slices,
const void* validx_curr,
const Slice& validx_prev,
const char* name_for_log) {
- CHECK_EQ(state_, kWriterWriting);
+ DCHECK_EQ(state_, kWriterWriting);
BlockPointer ptr;
Status s = AddBlock(std::move(data_slices), &ptr, name_for_log);
@@ -438,7 +436,7 @@ Status CFileWriter::AppendRawBlock(vector<Slice>
data_slices,
}
if (validx_builder_ != nullptr) {
- CHECK(validx_curr != nullptr) <<
+ DCHECK(validx_curr != nullptr) <<
"must pass a key for raw block if validx is configured";
(*options_.validx_key_encoder)(validx_curr, &tmp_buf_);
diff --git a/src/kudu/cfile/cfile_writer.h b/src/kudu/cfile/cfile_writer.h
index f9391a297..b5d6b61fa 100644
--- a/src/kudu/cfile/cfile_writer.h
+++ b/src/kudu/cfile/cfile_writer.h
@@ -117,7 +117,7 @@ class CFileWriter {
//
// If this is called prior to Start(), then the metadata pairs will be added
in
// the header. Otherwise, the pairs will be added in the footer during
Finish().
- void AddMetadataPair(const Slice &key, const Slice &value);
+ void AddMetadataPair(const Slice& key, const Slice& value);
// Return the metadata value associated with the given key.
//
@@ -125,12 +125,12 @@ class CFileWriter {
std::string GetMetaValueOrDie(Slice key) const;
// Append a set of values to the file.
- Status AppendEntries(const void *entries, size_t count);
+ Status AppendEntries(const void* entries, size_t count);
// Append a set of values to the file with the relative null bitmap.
// "entries" is not "compact" - ie if you're appending 10 rows, and 9 are
NULL,
// 'entries' still will have 10 elements in it
- Status AppendNullableEntries(const uint8_t *bitmap, const void *entries,
size_t count);
+ Status AppendNullableEntries(const uint8_t* bitmap, const void* entries,
size_t count);
// Append a raw block to the file, adding it to the various indexes.
//
@@ -191,7 +191,7 @@ class CFileWriter {
// Flush the current unflushed_metadata_ entries into the given protobuf
// field, clearing the buffer.
- void
FlushMetadataToPB(google::protobuf::RepeatedPtrField<FileMetadataPairPB>
*field);
+ void
FlushMetadataToPB(google::protobuf::RepeatedPtrField<FileMetadataPairPB>*
field);
WriterOptions options_;
diff --git a/src/kudu/cfile/encoding-test.cc b/src/kudu/cfile/encoding-test.cc
index e50fead52..63df32c09 100644
--- a/src/kudu/cfile/encoding-test.cc
+++ b/src/kudu/cfile/encoding-test.cc
@@ -86,8 +86,8 @@ class TestEncoding : public KuduTest {
}
template<DataType type>
- void CopyOne(BlockDecoder *decoder,
- typename TypeTraits<type>::cpp_type *ret) {
+ void CopyOne(BlockDecoder* decoder,
+ typename TypeTraits<type>::cpp_type* ret) {
ColumnBlock cb(GetTypeInfo(type), nullptr, ret, 1, &memory_);
ColumnDataView cdv(&cb);
size_t n = 1;
@@ -128,9 +128,9 @@ class TestEncoding : public KuduTest {
}
int rem = slices.size();
- Slice *ptr = &slices[0];
+ Slice* ptr = &slices[0];
while (rem > 0) {
- int added = sbb->Add(reinterpret_cast<const uint8_t *>(ptr),
+ int added = sbb->Add(reinterpret_cast<const uint8_t*>(ptr),
rem);
CHECK(added > 0);
rem -= added;
@@ -384,7 +384,7 @@ class TestEncoding : public KuduTest {
const CppType max_seek_target = data[num_ints - 1] + 1;
auto ibb = CreateBlockBuilderOrDie(IntType, encoding);
- CHECK_EQ(num_ints, ibb->Add(reinterpret_cast<uint8_t *>(&data[0]),
+ CHECK_EQ(num_ints, ibb->Add(reinterpret_cast<uint8_t*>(&data[0]),
num_ints));
scoped_refptr<BlockHandle> block = FinishAndMakeContiguous(ibb.get(), 0);
LOG(INFO) << "Created " << TypeTraits<IntType>::name() << " block with "
<< num_ints
@@ -450,7 +450,7 @@ class TestEncoding : public KuduTest {
const uint32_t kOrdinalPosBase = 12345;
auto bb = CreateBlockBuilderOrDie(Type, encoding);
- bb->Add(reinterpret_cast<const uint8_t *>(src), size);
+ bb->Add(reinterpret_cast<const uint8_t*>(src), size);
scoped_refptr<BlockHandle> block = FinishAndMakeContiguous(bb.get(),
kOrdinalPosBase);
LOG(INFO) << "Encoded size for " << size << " elems: " <<
block->data().size();
@@ -561,7 +561,7 @@ class TestEncoding : public KuduTest {
}
}
auto ibb = CreateBlockBuilderOrDie(IntType, encoding);
- ibb->Add(reinterpret_cast<const uint8_t *>(&to_insert[0]),
+ ibb->Add(reinterpret_cast<const uint8_t*>(&to_insert[0]),
to_insert.size());
scoped_refptr<BlockHandle> block = FinishAndMakeContiguous(ibb.get(),
kOrdinalPosBase);
@@ -591,7 +591,7 @@ class TestEncoding : public KuduTest {
static_cast<size_t>((random() % 30) + 1));
size_t n = to_decode;
ColumnDataView dst_data(&dst_block, dec_count);
- DCHECK_EQ((unsigned char *)(&decoded[dec_count]), dst_data.data());
+ DCHECK_EQ((unsigned char*)(&decoded[dec_count]), dst_data.data());
ASSERT_OK_FAST(ibd->CopyNextValues(&n, &dst_data));
ASSERT_GE(to_decode, n);
dec_count += n;
@@ -651,7 +651,7 @@ class TestEncoding : public KuduTest {
}
auto bb = CreateBlockBuilderOrDie(BOOL, encoding);
- bb->Add(reinterpret_cast<const uint8_t *>(&to_insert[0]),
+ bb->Add(reinterpret_cast<const uint8_t*>(&to_insert[0]),
to_insert.size());
scoped_refptr<BlockHandle> block = FinishAndMakeContiguous(bb.get(),
kOrdinalPosBase);
@@ -675,7 +675,7 @@ class TestEncoding : public KuduTest {
static_cast<size_t>((random() % 30) + 1));
size_t n = to_decode;
ColumnDataView dst_data(&dst_block, dec_count);
- DCHECK_EQ((unsigned char *)(&decoded[dec_count]), dst_data.data());
+ DCHECK_EQ((unsigned char*)(&decoded[dec_count]), dst_data.data());
ASSERT_OK_FAST(bd->CopyNextValues(&n, &dst_data));
ASSERT_GE(to_decode, n);
dec_count += n;
@@ -788,7 +788,7 @@ TEST_F(TestEncoding, TestRleIntBlockEncoder) {
Random rand(SeedRandom());
auto ints = CreateRandomIntegersInRange<uint32_t>(10000, 0,
std::numeric_limits<uint32_t>::max(),
&rand);
- ibb->Add(reinterpret_cast<const uint8_t *>(ints.data()), 10000);
+ ibb->Add(reinterpret_cast<const uint8_t*>(ints.data()), 10000);
scoped_refptr<BlockHandle> block = FinishAndMakeContiguous(ibb.get(), 12345);
LOG(INFO) << "RLE Encoded size for 10k ints: " << block->data().size();
@@ -798,7 +798,7 @@ TEST_F(TestEncoding, TestRleIntBlockEncoder) {
for (int i = 0; i < 100; i++) {
ints[i] = 0;
}
- ibb->Add(reinterpret_cast<const uint8_t *>(ints.data()), 100);
+ ibb->Add(reinterpret_cast<const uint8_t*>(ints.data()), 100);
block = FinishAndMakeContiguous(ibb.get(), 12345);
ASSERT_EQ(14UL, block->data().size());
}
diff --git a/src/kudu/cfile/index_btree.cc b/src/kudu/cfile/index_btree.cc
index 942ff389c..563c1b420 100644
--- a/src/kudu/cfile/index_btree.cc
+++ b/src/kudu/cfile/index_btree.cc
@@ -169,9 +169,9 @@ Status IndexTreeBuilder::FinishAndWriteBlock(size_t level,
BlockPointer* written
struct IndexTreeIterator::SeekedIndex {
- SeekedIndex() :
- iter(&reader)
- {}
+ SeekedIndex()
+ : iter(&reader) {
+ }
// Hold a copy of the underlying block data, which would
// otherwise go out of scope. The reader and iter
diff --git a/src/kudu/cfile/plain_bitmap_block.h
b/src/kudu/cfile/plain_bitmap_block.h
index e272769db..6701b105f 100644
--- a/src/kudu/cfile/plain_bitmap_block.h
+++ b/src/kudu/cfile/plain_bitmap_block.h
@@ -118,7 +118,7 @@ class PlainBitMapBlockDecoder final : public BlockDecoder {
}
Status ParseHeader() override {
- CHECK(!parsed_);
+ DCHECK(!parsed_);
if (data_.size() < kHeaderSize) {
return Status::Corruption(
@@ -147,7 +147,7 @@ class PlainBitMapBlockDecoder final : public BlockDecoder {
}
void SeekToPositionInBlock(uint pos) override {
- CHECK(parsed_) << "Must call ParseHeader()";
+ DCHECK(parsed_) << "Must call ParseHeader()";
if (PREDICT_FALSE(num_elems_ == 0)) {
DCHECK_EQ(0, pos);
@@ -167,7 +167,7 @@ class PlainBitMapBlockDecoder final : public BlockDecoder {
return Status::NotSupported("BOOL keys are not supported!");
}
- Status CopyNextValues(size_t *n, ColumnDataView *dst) override {
+ Status CopyNextValues(size_t* n, ColumnDataView* dst) override {
DCHECK(parsed_);
DCHECK_LE(*n, dst->nrows());
DCHECK_EQ(dst->stride(), sizeof(bool));
diff --git a/src/kudu/cfile/plain_block.h b/src/kudu/cfile/plain_block.h
index 3b2d2b2aa..41b2979a8 100644
--- a/src/kudu/cfile/plain_block.h
+++ b/src/kudu/cfile/plain_block.h
@@ -33,13 +33,13 @@ namespace kudu {
namespace cfile {
template<typename Type>
-inline Type Decode(const uint8_t *ptr) {
+inline Type Decode(const uint8_t* ptr) {
Type result;
memcpy(&result, ptr, sizeof(result));
return result;
}
-static const size_t kPlainBlockHeaderSize = sizeof(uint32_t) * 2;
+static constexpr const size_t kPlainBlockHeaderSize = sizeof(uint32_t) * 2;
//
// A plain encoder for generic fixed size data types.
@@ -47,7 +47,7 @@ static const size_t kPlainBlockHeaderSize = sizeof(uint32_t)
* 2;
template<DataType Type>
class PlainBlockBuilder final : public BlockBuilder {
public:
- explicit PlainBlockBuilder(const WriterOptions *options)
+ explicit PlainBlockBuilder(const WriterOptions* options)
: options_(options) {
// Reserve enough space for the block, plus a bit of slop since
// we often overrun the block by a few values.
@@ -55,7 +55,7 @@ class PlainBlockBuilder final : public BlockBuilder {
Reset();
}
- int Add(const uint8_t *vals_void, size_t count) override {
+ int Add(const uint8_t* vals_void, size_t count) override {
int old_size = buffer_.size();
buffer_.resize(old_size + count * kCppTypeSize);
memcpy(&buffer_[old_size], vals_void, count * kCppTypeSize);
@@ -83,13 +83,13 @@ class PlainBlockBuilder final : public BlockBuilder {
return count_;
}
- Status GetFirstKey(void *key) const override {
+ Status GetFirstKey(void* key) const override {
DCHECK_GT(count_, 0);
UnalignedStore(key, Decode<CppType>(&buffer_[kPlainBlockHeaderSize]));
return Status::OK();
}
- Status GetLastKey(void *key) const override {
+ Status GetLastKey(void* key) const override {
DCHECK_GT(count_, 0);
size_t idx = kPlainBlockHeaderSize + (count_ - 1) * kCppTypeSize;
UnalignedStore(key, Decode<CppType>(&buffer_[idx]));
@@ -123,9 +123,9 @@ class PlainBlockDecoder final : public BlockDecoder {
}
Status ParseHeader() override {
- CHECK(!parsed_);
+ DCHECK(!parsed_);
- if (data_.size() < kPlainBlockHeaderSize) {
+ if (PREDICT_FALSE(data_.size() < kPlainBlockHeaderSize)) {
return Status::Corruption(
"not enough bytes for header in PlainBlockDecoder");
}
@@ -133,11 +133,11 @@ class PlainBlockDecoder final : public BlockDecoder {
num_elems_ = DecodeFixed32(&data_[0]);
ordinal_pos_base_ = DecodeFixed32(&data_[4]);
- if (data_.size() != kPlainBlockHeaderSize + num_elems_ * size_of_type) {
+ if (PREDICT_FALSE(data_.size() !=
+ kPlainBlockHeaderSize + num_elems_ * size_of_type)) {
return Status::Corruption(
std::string("unexpected data size. ") + "\nFirst 100 bytes: "
- + HexDump(
- Slice(data_.data(),
+ + HexDump(Slice(data_.data(),
(data_.size() < 100 ? data_.size() : 100))));
}
@@ -149,7 +149,7 @@ class PlainBlockDecoder final : public BlockDecoder {
}
void SeekToPositionInBlock(uint pos) override {
- CHECK(parsed_) << "Must call ParseHeader()";
+ DCHECK(parsed_) << "Must call ParseHeader()";
if (PREDICT_FALSE(num_elems_ == 0)) {
DCHECK_EQ(0, pos);
@@ -160,7 +160,7 @@ class PlainBlockDecoder final : public BlockDecoder {
cur_idx_ = pos;
}
- Status SeekAtOrAfterValue(const void *value, bool *exact_match) override {
+ Status SeekAtOrAfterValue(const void* value, bool* exact_match) override {
DCHECK(value != nullptr);
CppType target = UnalignedLoad<CppType>(value);
@@ -192,7 +192,7 @@ class PlainBlockDecoder final : public BlockDecoder {
return Status::OK();
}
- Status CopyNextValues(size_t *n, ColumnDataView *dst) override {
+ Status CopyNextValues(size_t* n, ColumnDataView* dst) override {
DCHECK(parsed_);
DCHECK_LE(*n, dst->nrows());
DCHECK_EQ(dst->stride(), sizeof(CppType));
@@ -238,7 +238,6 @@ class PlainBlockDecoder final : public BlockDecoder {
enum {
size_of_type = TypeTraits<Type>::size
};
-
};
} // namespace cfile
diff --git a/src/kudu/cfile/rle_block.h b/src/kudu/cfile/rle_block.h
index a33d9d621..0f6ea702c 100644
--- a/src/kudu/cfile/rle_block.h
+++ b/src/kudu/cfile/rle_block.h
@@ -119,9 +119,9 @@ class RleBitMapBlockDecoder final : public BlockDecoder {
}
Status ParseHeader() override {
- CHECK(!parsed_);
+ DCHECK(!parsed_);
- if (data_.size() < kRleBitmapBlockHeaderSize) {
+ if (PREDICT_FALSE(data_.size() < kRleBitmapBlockHeaderSize)) {
return Status::Corruption(
"not enough bytes for header in RleBitMapBlockDecoder");
}
@@ -140,7 +140,7 @@ class RleBitMapBlockDecoder final : public BlockDecoder {
}
void SeekToPositionInBlock(uint pos) override {
- CHECK(parsed_) << "Must call ParseHeader()";
+ DCHECK(parsed_) << "Must call ParseHeader()";
DCHECK_LE(pos, num_elems_)
<< "Tried to seek to " << pos << " which is > number of elements ("
<< num_elems_ << ") in the block!";
@@ -165,7 +165,7 @@ class RleBitMapBlockDecoder final : public BlockDecoder {
cur_idx_ = pos;
}
- Status CopyNextValues(size_t *n, ColumnDataView* dst) override {
+ Status CopyNextValues(size_t* n, ColumnDataView* dst) override {
DCHECK(parsed_);
DCHECK_LE(*n, dst->nrows());
@@ -319,9 +319,9 @@ class RleIntBlockDecoder final : public BlockDecoder {
}
Status ParseHeader() override {
- CHECK(!parsed_);
+ DCHECK(!parsed_);
- if (data_.size() < kRleBitmapBlockHeaderSize) {
+ if (PREDICT_FALSE(data_.size() < kRleBitmapBlockHeaderSize)) {
return Status::Corruption(
"not enough bytes for header in RleIntBlockDecoder");
}
@@ -341,7 +341,7 @@ class RleIntBlockDecoder final : public BlockDecoder {
}
void SeekToPositionInBlock(uint pos) override {
- CHECK(parsed_) << "Must call ParseHeader()";
+ DCHECK(parsed_) << "Must call ParseHeader()";
DCHECK_LE(pos, num_elems_)
<< "Tried to seek to " << pos << " which is > number of elements ("
<< num_elems_ << ") in the block!";
@@ -365,7 +365,7 @@ class RleIntBlockDecoder final : public BlockDecoder {
cur_idx_ = pos;
}
- Status SeekAtOrAfterValue(const void *value_void, bool *exact_match)
override {
+ Status SeekAtOrAfterValue(const void* value_void, bool* exact_match)
override {
// Currently using linear search as we do not check whether a
// mid-point of a buffer will fall on a literal or not.
//
@@ -399,7 +399,7 @@ class RleIntBlockDecoder final : public BlockDecoder {
return Status::NotFound("not in block");
}
- Status CopyNextValues(size_t *n, ColumnDataView *dst) override {
+ Status CopyNextValues(size_t* n, ColumnDataView* dst) override {
DCHECK(parsed_);
DCHECK_LE(*n, dst->nrows());
@@ -457,7 +457,7 @@ class RleIntBlockDecoder final : public BlockDecoder {
if (!sel->TestBit(row_idx)) {
continue;
}
- *(reinterpret_cast<CppType *>(data_ptr)) = val;
+ *(reinterpret_cast<CppType*>(data_ptr)) = val;
}
} else {
// Mark that the rows will not be returned.
diff --git a/src/kudu/cfile/type_encodings.h b/src/kudu/cfile/type_encodings.h
index da75eefd5..71e5934a8 100644
--- a/src/kudu/cfile/type_encodings.h
+++ b/src/kudu/cfile/type_encodings.h
@@ -14,8 +14,7 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-#ifndef KUDU_CFILE_TYPE_ENCODINGS_H_
-#define KUDU_CFILE_TYPE_ENCODINGS_H_
+#pragma once
#include <memory>
@@ -78,5 +77,3 @@ class TypeEncodingInfo {
} // namespace cfile
} // namespace kudu
-
-#endif /* KUDU_CFILE_TYPE_ENCODINGS_H_ */