Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions cpp/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# clang-tidy configuration for Apache TsFile C++.
# Scope is tsfile's own sources (cpp/src); third_party is excluded by the
# header filter below and by the run script's file regex.
#
# Enabled: clang-analyzer (real bug hunting), bugprone, performance.
# Disabled noisy groups:
# -bugprone-assignment-in-if-condition RET_FAIL/IS_SUCC macro idiom (717 hits)
# -bugprone-branch-clone switch tables share bodies (127 hits)
# -bugprone-macro-parentheses project macro style (59 hits)
# -bugprone-multi-level-implicit-pointer-conversion cwrapper void* pattern (11 hits)
# -performance-enum-size enum base types are on-disk ABI
# NOTE: no comment lines inside the folded scalar below; they would be
# parsed as part of the checks list.
Checks: >
-*,
clang-analyzer-*,
bugprone-*,
performance-*,
-bugprone-easily-swappable-parameters,
-bugprone-narrowing-conversions,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-reserved-identifier,
-bugprone-unhandled-self-assignment,
-performance-inefficient-string-concatenation,
-bugprone-assignment-in-if-condition,
-bugprone-branch-clone,
-bugprone-macro-parentheses,
-bugprone-multi-level-implicit-pointer-conversion,
-performance-enum-size
WarningsAsErrors: ''
HeaderFilterRegex: '^.*/cpp/(src|test)/.*\.h$'
FormatStyle: none
2 changes: 1 addition & 1 deletion cpp/src/common/allocator/byte_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ class ByteStream {
uint32_t write_len = 0;
while (write_len < len) {
if (RET_FAIL(prepare_space())) {
std::cout << "write_buf error " << ret << std::endl;
std::cout << "write_buf error " << ret << '\n';
return ret;
}
uint32_t remainder = page_size_ - (total_size_.load() & page_mask_);
Expand Down
9 changes: 4 additions & 5 deletions cpp/src/common/allocator/mem_alloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,16 @@ void ModStat::print_stat() {
}
}

std::cout << "=== Memory Statistics ===" << std::endl;
std::cout << "=== Memory Statistics ===" << '\n';
for (int i = 0; i < count; i++) {
std::cout << " " << entries[i].name << ": " << entries[i].val
<< " bytes" << std::endl;
<< " bytes" << '\n';
}
double kb = total / 1024.0;
double mb = kb / 1024.0;
std::cout << " TOTAL: " << total << " bytes / " << std::fixed
<< std::setprecision(2) << kb << " KB / " << mb << " MB"
<< std::endl;
std::cout << "=========================" << std::endl;
<< std::setprecision(2) << kb << " KB / " << mb << " MB" << '\n';
std::cout << "=========================" << '\n';
}

BaseAllocator g_base_allocator;
Expand Down
11 changes: 8 additions & 3 deletions cpp/src/common/allocator/page_arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,14 @@ class PageArena {
}
INLINE char* alloc(uint32_t size,
size_t alignment = alignof(std::max_align_t)) {
auto current = reinterpret_cast<uintptr_t>(cur_alloc_);
uintptr_t aligned = (current + alignment - 1) & ~(alignment - 1);
char* ret = reinterpret_cast<char*>(aligned);
// Compute the padding in address space and advance the pointer
// instead of casting an integer back to a pointer (which
// pessimizes aliasing analysis).
const uintptr_t misalignment =
reinterpret_cast<uintptr_t>(cur_alloc_) & (alignment - 1);
const uintptr_t padding =
(alignment - misalignment) & (alignment - 1);
char* ret = cur_alloc_ + padding;
if (ret + size > page_end_) {
return nullptr;
}
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/common/device_id.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ std::vector<std::string> StringArrayDeviceID::split_device_id_string(
if (segment_cnt == 1) {
// "root" -> {"root"}
final_segments.push_back(splits[0]);
} else if (segment_cnt <
static_cast<size_t>(storage::DEFAULT_SEGMENT_NUM_FOR_TABLE_NAME +
1)) {
} else if (segment_cnt < static_cast<size_t>(
storage::DEFAULT_SEGMENT_NUM_FOR_TABLE_NAME) +
1) {
// "root.a" -> {"root", "a"}
// "root.a.b" -> {"root.a", "b"}
std::string table_name = std::accumulate(
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/common/row_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct Field {
}
default: {
assert(false);
std::cout << "unknown data type" << std::endl;
std::cout << "unknown data type" << '\n';
}
}
}
Expand All @@ -114,7 +114,7 @@ struct Field {
case common::TSDataType::DOUBLE:
return value_.dval_;
default:
std::cout << "unknown data type" << std::endl;
std::cout << "unknown data type" << '\n';
break;
}
return -1; // when data type is unknown
Expand Down
1 change: 1 addition & 0 deletions cpp/src/common/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ class TableSchema {

std::vector<common::TSDataType> get_data_types() const {
std::vector<common::TSDataType> ret;
ret.reserve(column_schemas_.size());
for (const auto& measurement_schema : column_schemas_) {
ret.emplace_back(measurement_schema->data_type_);
}
Expand Down
6 changes: 4 additions & 2 deletions cpp/src/common/tablet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,10 @@ int Tablet::add_value(uint32_t row_index, const std::string& measurement_name,
}

template <>
int Tablet::add_value(uint32_t row_index, const std::string& measurement_name,
std::string val) {
int Tablet::add_value(
uint32_t row_index, const std::string& measurement_name,
// Signature must match the primary template (T val).
std::string val) { // NOLINT(performance-unnecessary-value-param)
return add_value(row_index, measurement_name, String(val));
}

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/common/tablet.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ class Tablet {
int max_rows = DEFAULT_MAX_ROWS)
: max_row_num_(max_rows),
insert_target_name_(device_id),
schema_vec_(schema_vec),
schema_vec_(std::move(schema_vec)),
timestamps_(nullptr),
value_matrix_(nullptr),
bitmaps_(nullptr) {
ASSERT(device_id.size() >= 1);
ASSERT(schema_vec != NULL);
ASSERT(schema_vec_ != NULL);
ASSERT(max_rows > 0 && max_rows < (1 << 30));
if (max_rows < 0) {
ASSERT(false);
Expand Down
5 changes: 4 additions & 1 deletion cpp/src/common/tsfile_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ int TSMIterator::get_next(std::shared_ptr<IDeviceID>& ret_device_id,
ret_ts_index.finish();
}
if (UNLIKELY(ret_device_id == nullptr)) {
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
ret = E_TSFILE_WRITER_META_ERR;
// log_err("null device name from chunk_group_meta_iter, ret=%d", ret);
ASSERT(false);
Expand Down Expand Up @@ -383,14 +384,16 @@ int TsFileMeta::deserialize_from(common::ByteStream& in) {

/* ================ MetaIndexNode ================ */
int MetaIndexNode::binary_search_children(
// NOLINTNEXTLINE(performance-unnecessary-value-param) // public ABI
std::shared_ptr<IComparable> key, bool exact_search,
std::shared_ptr<IMetaIndexEntry>& ret_index_entry,
int64_t& ret_end_offset) {
return binary_search_children(key, exact_search, ret_index_entry,
return binary_search_children(std::move(key), exact_search, ret_index_entry,
ret_end_offset, *pa_);
}

int MetaIndexNode::binary_search_children(
// NOLINTNEXTLINE(performance-unnecessary-value-param) // public ABI
std::shared_ptr<IComparable> key, bool exact_search,
std::shared_ptr<IMetaIndexEntry>& ret_index_entry, int64_t& ret_end_offset,
common::PageArena& result_pa) {
Expand Down
14 changes: 8 additions & 6 deletions cpp/src/common/tsfile_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ struct ChunkHeader {
#ifndef NDEBUG
friend std::ostream& operator<<(std::ostream& os, const ChunkHeader& h) {
os << "{measurement_name=" << h.measurement_name_
<< ", data_size=" << h.data_size_ << ", data_type=" << h.data_type_
<< ", compression_type=" << h.compression_type_
<< ", encoding_type=" << h.encoding_type_
<< ", data_size=" << h.data_size_
<< ", data_type=" << static_cast<unsigned int>(h.data_type_)
<< ", compression_type="
<< static_cast<unsigned int>(h.compression_type_)
<< ", encoding_type=" << static_cast<unsigned int>(h.encoding_type_)
<< ", num_of_pages=" << h.num_of_pages_
<< ", serialized_size=" << h.serialized_size_
<< ", chunk_type=" << (int)h.chunk_type_ << "}";
Expand Down Expand Up @@ -282,7 +284,7 @@ struct ChunkMeta {
#ifndef NDEBUG
friend std::ostream& operator<<(std::ostream& os, const ChunkMeta& cm) {
os << "{measurement_name=" << cm.measurement_name_
<< ", data_type=" << cm.data_type_
<< ", data_type=" << static_cast<unsigned int>(cm.data_type_)
<< ", offset_of_chunk_header=" << cm.offset_of_chunk_header_
<< ", mask=" << ((int)cm.mask_);
if (cm.statistic_ == nullptr) {
Expand All @@ -303,7 +305,7 @@ struct ChunkGroupMeta {
: chunk_meta_list_(pa_ptr) {}

FORCE_INLINE int init(std::shared_ptr<IDeviceID> device_id) {
device_id_ = device_id;
device_id_ = std::move(device_id);
return 0;
}
FORCE_INLINE int push(ChunkMeta* cm) {
Expand Down Expand Up @@ -1158,7 +1160,7 @@ struct MetaIndexNode {

FORCE_INLINE bool is_empty() const { return children_.size() == 0; }

FORCE_INLINE int push_entry(std::shared_ptr<IMetaIndexEntry> entry) {
FORCE_INLINE int push_entry(const std::shared_ptr<IMetaIndexEntry>& entry) {
#if DEBUG_SE
std::cout << "MetaIndexNode.push_entry(" << *entry << ")" << std::endl;
#endif
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/compress/lz4_compressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class LZ4Compressor : public Compressor {
: compressed_buf_(nullptr),
uncompressed_buf_(nullptr),
uncompressed_buf_capacity_(0){};
~LZ4Compressor() { destroy(); }
~LZ4Compressor() { LZ4Compressor::destroy(); }
// Owns the reused decompression buffer; a copy would double-free it.
LZ4Compressor(const LZ4Compressor&) = delete;
LZ4Compressor& operator=(const LZ4Compressor&) = delete;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/compress/zstd_compressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace storage {
class ZstdCompressor : public Compressor {
public:
ZstdCompressor() : compressed_buf_(nullptr), uncompressed_buf_(nullptr) {}
~ZstdCompressor() OVERRIDE { destroy(); }
~ZstdCompressor() OVERRIDE { ZstdCompressor::destroy(); }

int reset(bool for_compress) OVERRIDE;
void destroy() OVERRIDE;
Expand Down
7 changes: 7 additions & 0 deletions cpp/src/cwrapper/tsfile_cwrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ ResultSet tsfile_query_table(TsFileReader reader, const char* table_name,
auto* r = static_cast<storage::TsFileReader*>(reader);
storage::ResultSet* table_result_set = nullptr;
std::vector<std::string> column_names;
column_names.reserve(column_num);
for (uint32_t i = 0; i < column_num; i++) {
column_names.emplace_back(columns[i]);
}
Expand All @@ -859,6 +860,7 @@ ResultSet tsfile_query_table_on_tree(TsFileReader reader, char** columns,
auto* r = static_cast<storage::TsFileReader*>(reader);
storage::ResultSet* table_result_set = nullptr;
std::vector<std::string> column_names;
column_names.reserve(column_num);
for (uint32_t i = 0; i < column_num; i++) {
column_names.emplace_back(columns[i]);
}
Expand Down Expand Up @@ -998,6 +1000,7 @@ ResultSet tsfile_query_table_batch(TsFileReader reader, const char* table_name,
auto* r = static_cast<storage::TsFileReader*>(reader);
storage::ResultSet* table_result_set = nullptr;
std::vector<std::string> column_names;
column_names.reserve(column_num);
for (uint32_t i = 0; i < column_num; i++) {
column_names.emplace_back(columns[i]);
}
Expand Down Expand Up @@ -2049,6 +2052,9 @@ ERRNO populate_c_metadata_map_from_cpp(
if (idx == nullptr) {
continue;
}
// slot stays below timeseries_count: the array is sized
// by the non-null count and incremented once per entry.
// NOLINTNEXTLINE(clang-analyzer-security.ArrayBound)
TimeseriesMetadata& m = e.timeseries[slot];
common::String mn = idx->get_measurement_name();
m.measurement_name = strdup(mn.to_std_string().c_str());
Expand Down Expand Up @@ -3001,6 +3007,7 @@ ResultSet tsfile_query_table_with_tag_filter(
auto* r = static_cast<storage::TsFileReader*>(reader);
storage::ResultSet* table_result_set = nullptr;
std::vector<std::string> column_names;
column_names.reserve(column_num);
for (uint32_t i = 0; i < column_num; i++) {
column_names.emplace_back(columns[i]);
}
Expand Down
18 changes: 15 additions & 3 deletions cpp/src/dataset/dataset_index.cc
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,11 @@ DatasetIndexStatus MappedDatasetIndex::find_device_id(
return DatasetIndexStatus::NOT_FOUND;
}
DatasetIndexSectionView view;
section(DatasetIndexSectionType::DEVICE_NAME_INDEX, view);
if (section(DatasetIndexSectionType::DEVICE_NAME_INDEX, view) !=
DatasetIndexStatus::OK ||
view.data == nullptr) {
return DatasetIndexStatus::NOT_FOUND;
}
const DeviceNameIndexRecord* records =
reinterpret_cast<const DeviceNameIndexRecord*>(view.data);
const uint64_t hash = dataset_index_name_hash(name.data(), name.size());
Expand Down Expand Up @@ -990,7 +994,11 @@ DatasetIndexStatus MappedDatasetIndex::find_column_id(
return DatasetIndexStatus::NOT_FOUND;
}
DatasetIndexSectionView view;
section(DatasetIndexSectionType::COLUMN_NAME_INDEX, view);
if (section(DatasetIndexSectionType::COLUMN_NAME_INDEX, view) !=
DatasetIndexStatus::OK ||
view.data == nullptr) {
return DatasetIndexStatus::NOT_FOUND;
}
const ColumnNameIndexRecord* records =
reinterpret_cast<const ColumnNameIndexRecord*>(view.data);
const uint64_t hash = dataset_index_name_hash(name.data(), name.size());
Expand Down Expand Up @@ -1023,7 +1031,11 @@ DatasetIndexStatus MappedDatasetIndex::find_series_id(
return DatasetIndexStatus::NOT_FOUND;
}
DatasetIndexSectionView view;
section(DatasetIndexSectionType::LOGICAL_SERIES, view);
if (section(DatasetIndexSectionType::LOGICAL_SERIES, view) !=
DatasetIndexStatus::OK ||
view.data == nullptr) {
return DatasetIndexStatus::NOT_FOUND;
}
const LogicalSeriesRecord* records =
reinterpret_cast<const LogicalSeriesRecord*>(view.data);
uint32_t low = device->first_series_id;
Expand Down
5 changes: 5 additions & 0 deletions cpp/src/encoding/alp/alp_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ struct AlpTypeTraits<float> {
}

static bool BitwiseEqual(float lhs, float rhs) {
// Bitwise comparison is intentional here: ALP deduplicates
// identical bit patterns, including -0.0 vs 0.0 and NaNs.
// NOLINTNEXTLINE(bugprone-suspicious-memory-comparison)
return std::memcmp(&lhs, &rhs, sizeof(float)) == 0;
}
};
Expand Down Expand Up @@ -148,6 +151,8 @@ struct AlpTypeTraits<double> {
}

static bool BitwiseEqual(double lhs, double rhs) {
// See BitwiseEqual(float): bitwise comparison is intentional.
// NOLINTNEXTLINE(bugprone-suspicious-memory-comparison)
return std::memcmp(&lhs, &rhs, sizeof(double)) == 0;
}
};
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/encoding/chimp_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

namespace storage {

static constexpr int8_t CHIMP_LEADING_DECODING[8] = {0, 8, 12, 16,
18, 20, 22, 24};
static constexpr uint8_t CHIMP_LEADING_DECODING[8] = {0, 8, 12, 16,
18, 20, 22, 24};

template <typename T>
class ChimpDecoder : public Decoder {
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/encoding/chimp_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static constexpr int8_t CHIMP_LEADING_REPRESENTATION[64] = {
6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};

static constexpr int8_t CHIMP_LEADING_ROUND[64] = {
static constexpr uint8_t CHIMP_LEADING_ROUND[64] = {
0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 12, 12, 12, 12,
16, 16, 18, 18, 20, 20, 22, 22, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/encoding/dictionary_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class DictionaryEncoder : public Encoder {
return encode(std::string(value), out);
}

int encode(std::string value, common::ByteStream& out) {
int encode(const std::string& value, common::ByteStream& out) {
if (entry_index_.count(value) == 0) {
index_entry_.push_back(value);
map_size_ = map_size_ + value.length();
Expand Down
4 changes: 3 additions & 1 deletion cpp/src/encoding/plain_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ namespace storage {
class PlainEncoder : public Encoder {
public:
PlainEncoder() {}
~PlainEncoder() { destroy(); }
// Qualified call: destroy() is virtual, but a destructor must not
// dispatch to derived overrides (and none exist for PlainEncoder).
~PlainEncoder() { PlainEncoder::destroy(); }
void destroy() override { /* do nothing for PlainEncoder */
}
void reset() override { /* do thing for PlainEncoder */
Expand Down
Loading
Loading