From 3d2ac5f6f2ca96e5d1d3a7b641989d91c21729ea Mon Sep 17 00:00:00 2001 From: Colin Lee Date: Tue, 1 Dec 2026 11:31:47 +0800 Subject: [PATCH 1/4] fix(cpp): address clang-tidy findings and add static analysis config - restorable writer: propagate allocation failures during the recovery scan instead of returning E_OK - io writer: check the bloom filter add_path_entry result before serializing the index - dataset index: reject missing sections before dereferencing their records - local random-access file: reject a closed descriptor before fstat() - result_set: inherit enable_shared_from_this publicly; qualify virtual calls made from constructors/destructors - ts2diff decoder: return a defined value on corrupt input; qds: drop dead assignments - pass read-only shared_ptr/vector/string parameters by const reference, and move parameters that are stored into members - reserve vectors before loop appends; replace std::endl with '\n' in logs - use uint8_t for the chimp leading-zero tables; cast unsigned char values before streaming - add cpp/.clang-tidy (clang-analyzer, bugprone, performance checks) --- cpp/.clang-tidy | 32 +++++++++++++++ cpp/src/common/allocator/byte_stream.h | 2 +- cpp/src/common/allocator/mem_alloc.cc | 8 ++-- cpp/src/common/allocator/page_arena.h | 10 +++-- cpp/src/common/device_id.cc | 5 ++- cpp/src/common/row_record.h | 4 +- cpp/src/common/schema.h | 1 + cpp/src/common/tablet.cc | 3 +- cpp/src/common/tablet.h | 4 +- cpp/src/common/tsfile_common.cc | 6 +-- cpp/src/common/tsfile_common.h | 19 +++++---- cpp/src/compress/lz4_compressor.h | 2 +- cpp/src/compress/zstd_compressor.h | 2 +- cpp/src/cwrapper/tsfile_cwrapper.cc | 9 ++++- cpp/src/dataset/dataset_index.cc | 18 +++++++-- cpp/src/encoding/alp/alp_traits.h | 5 +++ cpp/src/encoding/chimp_decoder.h | 2 +- cpp/src/encoding/chimp_encoder.h | 2 +- cpp/src/encoding/dictionary_encoder.h | 2 +- cpp/src/encoding/plain_encoder.h | 4 +- cpp/src/encoding/ts2diff_decoder.h | 4 +- cpp/src/encoding/ts2diff_encoder.h | 4 +- cpp/src/encoding/zigzag_encoder.h | 2 - cpp/src/file/local_random_access_read_file.cc | 2 +- cpp/src/file/local_random_access_read_file.h | 6 ++- cpp/src/file/restorable_tsfile_io_writer.cc | 8 ++++ cpp/src/file/tsfile_io_reader.cc | 40 +++++++++---------- cpp/src/file/tsfile_io_reader.h | 32 +++++++-------- cpp/src/file/tsfile_io_writer.cc | 28 ++++++------- cpp/src/file/tsfile_io_writer.h | 6 +-- cpp/src/file/write_file.h | 2 +- cpp/src/reader/aligned_chunk_reader.cc | 6 +-- .../block/device_ordered_tsblock_reader.cc | 9 ++++- .../block/single_device_tsblock_reader.h | 4 +- cpp/src/reader/chunk_reader.cc | 6 +-- cpp/src/reader/expression.cc | 10 ++--- cpp/src/reader/filter/aligned_field_filter.cc | 9 +++-- cpp/src/reader/filter/aligned_field_filter.h | 6 +-- cpp/src/reader/filter/filter.h | 2 +- cpp/src/reader/filter/filter_type.h | 2 +- cpp/src/reader/filter/tag_filter.cc | 34 ++++++++-------- cpp/src/reader/filter/tag_filter.h | 34 ++++++++-------- cpp/src/reader/qds_without_timegenerator.cc | 2 - cpp/src/reader/result_set.h | 14 +++---- cpp/src/reader/table_query_executor.cc | 1 + cpp/src/reader/table_result_set.cc | 4 +- cpp/src/reader/table_result_set.h | 4 +- cpp/src/reader/task/device_query_task.cc | 3 +- cpp/src/reader/task/device_query_task.h | 8 ++-- cpp/src/reader/task/device_task_iterator.h | 15 +++---- cpp/src/reader/tsfile_reader.cc | 11 ++--- cpp/src/reader/tsfile_reader.h | 6 +-- cpp/src/reader/tsfile_series_scan_iterator.cc | 4 +- cpp/src/reader/tsfile_series_scan_iterator.h | 2 +- cpp/src/reader/tsfile_tree_reader.cc | 3 +- cpp/src/writer/tsfile_tree_writer.cc | 2 +- cpp/src/writer/tsfile_tree_writer.h | 2 +- cpp/src/writer/tsfile_writer.cc | 12 +++--- cpp/src/writer/tsfile_writer.h | 6 +-- cpp/tools/commands/row_query.cc | 3 +- 60 files changed, 298 insertions(+), 200 deletions(-) create mode 100644 cpp/.clang-tidy diff --git a/cpp/.clang-tidy b/cpp/.clang-tidy new file mode 100644 index 0000000000..cb7e2c4c6c --- /dev/null +++ b/cpp/.clang-tidy @@ -0,0 +1,32 @@ +# 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 diff --git a/cpp/src/common/allocator/byte_stream.h b/cpp/src/common/allocator/byte_stream.h index b403d3b5cb..9caac227bf 100644 --- a/cpp/src/common/allocator/byte_stream.h +++ b/cpp/src/common/allocator/byte_stream.h @@ -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_); diff --git a/cpp/src/common/allocator/mem_alloc.cc b/cpp/src/common/allocator/mem_alloc.cc index deda0b8d84..233851526f 100644 --- a/cpp/src/common/allocator/mem_alloc.cc +++ b/cpp/src/common/allocator/mem_alloc.cc @@ -223,17 +223,17 @@ 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; + << '\n'; + std::cout << "=========================" << '\n'; } BaseAllocator g_base_allocator; diff --git a/cpp/src/common/allocator/page_arena.h b/cpp/src/common/allocator/page_arena.h index 40aad4c96e..ed38d6584b 100644 --- a/cpp/src/common/allocator/page_arena.h +++ b/cpp/src/common/allocator/page_arena.h @@ -84,9 +84,13 @@ class PageArena { } INLINE char* alloc(uint32_t size, size_t alignment = alignof(std::max_align_t)) { - auto current = reinterpret_cast(cur_alloc_); - uintptr_t aligned = (current + alignment - 1) & ~(alignment - 1); - char* ret = reinterpret_cast(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(cur_alloc_) & (alignment - 1); + const uintptr_t padding = (alignment - misalignment) & (alignment - 1); + char* ret = cur_alloc_ + padding; if (ret + size > page_end_) { return nullptr; } diff --git a/cpp/src/common/device_id.cc b/cpp/src/common/device_id.cc index 0b5e6c1077..b3e4a1b069 100644 --- a/cpp/src/common/device_id.cc +++ b/cpp/src/common/device_id.cc @@ -236,8 +236,9 @@ std::vector StringArrayDeviceID::split_device_id_string( // "root" -> {"root"} final_segments.push_back(splits[0]); } else if (segment_cnt < - static_cast(storage::DEFAULT_SEGMENT_NUM_FOR_TABLE_NAME + - 1)) { + static_cast( + storage::DEFAULT_SEGMENT_NUM_FOR_TABLE_NAME) + + 1) { // "root.a" -> {"root", "a"} // "root.a.b" -> {"root.a", "b"} std::string table_name = std::accumulate( diff --git a/cpp/src/common/row_record.h b/cpp/src/common/row_record.h index a640ecc29f..b822c80024 100644 --- a/cpp/src/common/row_record.h +++ b/cpp/src/common/row_record.h @@ -93,7 +93,7 @@ struct Field { } default: { assert(false); - std::cout << "unknown data type" << std::endl; + std::cout << "unknown data type" << '\n'; } } } @@ -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 diff --git a/cpp/src/common/schema.h b/cpp/src/common/schema.h index 007e1f1db4..76e1133fa8 100644 --- a/cpp/src/common/schema.h +++ b/cpp/src/common/schema.h @@ -439,6 +439,7 @@ class TableSchema { std::vector get_data_types() const { std::vector ret; + ret.reserve(column_schemas_.size()); for (const auto& measurement_schema : column_schemas_) { ret.emplace_back(measurement_schema->data_type_); } diff --git a/cpp/src/common/tablet.cc b/cpp/src/common/tablet.cc index 3bfc54bb9d..5d9e035ce7 100644 --- a/cpp/src/common/tablet.cc +++ b/cpp/src/common/tablet.cc @@ -532,7 +532,8 @@ 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) { + // 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)); } diff --git a/cpp/src/common/tablet.h b/cpp/src/common/tablet.h index 095157ac71..7d6d5dcbc7 100644 --- a/cpp/src/common/tablet.h +++ b/cpp/src/common/tablet.h @@ -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); diff --git a/cpp/src/common/tsfile_common.cc b/cpp/src/common/tsfile_common.cc index 02a0b1216a..bc6a54007a 100644 --- a/cpp/src/common/tsfile_common.cc +++ b/cpp/src/common/tsfile_common.cc @@ -173,7 +173,7 @@ int TSMIterator::get_next(std::shared_ptr& ret_device_id, ret_ts_index.finish(); } if (UNLIKELY(ret_device_id == nullptr)) { - ret = E_TSFILE_WRITER_META_ERR; + ret = E_TSFILE_WRITER_META_ERR; // NOLINT(clang-analyzer-deadcode.DeadStores) // log_err("null device name from chunk_group_meta_iter, ret=%d", ret); ASSERT(false); } @@ -383,7 +383,7 @@ int TsFileMeta::deserialize_from(common::ByteStream& in) { /* ================ MetaIndexNode ================ */ int MetaIndexNode::binary_search_children( - std::shared_ptr key, bool exact_search, + const std::shared_ptr& key, bool exact_search, std::shared_ptr& ret_index_entry, int64_t& ret_end_offset) { return binary_search_children(key, exact_search, ret_index_entry, @@ -391,7 +391,7 @@ int MetaIndexNode::binary_search_children( } int MetaIndexNode::binary_search_children( - std::shared_ptr key, bool exact_search, + const std::shared_ptr& key, bool exact_search, std::shared_ptr& ret_index_entry, int64_t& ret_end_offset, common::PageArena& result_pa) { #if DEBUG_SE diff --git a/cpp/src/common/tsfile_common.h b/cpp/src/common/tsfile_common.h index 1ff7cc2d1c..4eaf802767 100644 --- a/cpp/src/common/tsfile_common.h +++ b/cpp/src/common/tsfile_common.h @@ -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(h.data_type_) + << ", compression_type=" + << static_cast(h.compression_type_) + << ", encoding_type=" << static_cast(h.encoding_type_) << ", num_of_pages=" << h.num_of_pages_ << ", serialized_size=" << h.serialized_size_ << ", chunk_type=" << (int)h.chunk_type_ << "}"; @@ -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(cm.data_type_) << ", offset_of_chunk_header=" << cm.offset_of_chunk_header_ << ", mask=" << ((int)cm.mask_); if (cm.statistic_ == nullptr) { @@ -303,7 +305,7 @@ struct ChunkGroupMeta { : chunk_meta_list_(pa_ptr) {} FORCE_INLINE int init(std::shared_ptr device_id) { - device_id_ = device_id; + device_id_ = std::move(device_id); return 0; } FORCE_INLINE int push(ChunkMeta* cm) { @@ -1012,14 +1014,14 @@ struct MetaIndexNode { } int binary_search_children( - std::shared_ptr key, bool exact_search, + const std::shared_ptr& key, bool exact_search, std::shared_ptr& ret_index_entry, int64_t& ret_end_offset); // Lookup copies can outlive the source node but must not accumulate in a // cached node's arena. The caller keeps result_pa alive with the result. int binary_search_children( - std::shared_ptr key, bool exact_search, + const std::shared_ptr& key, bool exact_search, std::shared_ptr& ret_index_entry, int64_t& ret_end_offset, common::PageArena& result_pa); @@ -1158,7 +1160,8 @@ struct MetaIndexNode { FORCE_INLINE bool is_empty() const { return children_.size() == 0; } - FORCE_INLINE int push_entry(std::shared_ptr entry) { + FORCE_INLINE int push_entry( + const std::shared_ptr& entry) { #if DEBUG_SE std::cout << "MetaIndexNode.push_entry(" << *entry << ")" << std::endl; #endif diff --git a/cpp/src/compress/lz4_compressor.h b/cpp/src/compress/lz4_compressor.h index 1089983453..887bb65639 100644 --- a/cpp/src/compress/lz4_compressor.h +++ b/cpp/src/compress/lz4_compressor.h @@ -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; diff --git a/cpp/src/compress/zstd_compressor.h b/cpp/src/compress/zstd_compressor.h index c0649f6ee8..655d0f2732 100644 --- a/cpp/src/compress/zstd_compressor.h +++ b/cpp/src/compress/zstd_compressor.h @@ -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; diff --git a/cpp/src/cwrapper/tsfile_cwrapper.cc b/cpp/src/cwrapper/tsfile_cwrapper.cc index c2e6f2a0d6..5f5025d2a0 100644 --- a/cpp/src/cwrapper/tsfile_cwrapper.cc +++ b/cpp/src/cwrapper/tsfile_cwrapper.cc @@ -845,6 +845,7 @@ ResultSet tsfile_query_table(TsFileReader reader, const char* table_name, auto* r = static_cast(reader); storage::ResultSet* table_result_set = nullptr; std::vector column_names; + column_names.reserve(column_num); for (uint32_t i = 0; i < column_num; i++) { column_names.emplace_back(columns[i]); } @@ -859,6 +860,7 @@ ResultSet tsfile_query_table_on_tree(TsFileReader reader, char** columns, auto* r = static_cast(reader); storage::ResultSet* table_result_set = nullptr; std::vector column_names; + column_names.reserve(column_num); for (uint32_t i = 0; i < column_num; i++) { column_names.emplace_back(columns[i]); } @@ -998,6 +1000,7 @@ ResultSet tsfile_query_table_batch(TsFileReader reader, const char* table_name, auto* r = static_cast(reader); storage::ResultSet* table_result_set = nullptr; std::vector column_names; + column_names.reserve(column_num); for (uint32_t i = 0; i < column_num; i++) { column_names.emplace_back(columns[i]); } @@ -2049,7 +2052,10 @@ ERRNO populate_c_metadata_map_from_cpp( if (idx == nullptr) { continue; } - TimeseriesMetadata& m = e.timeseries[slot]; + // slot stays below timeseries_count: the array is sized + // by the non-null count and incremented once per entry. + TimeseriesMetadata& m = + e.timeseries[slot]; // NOLINT(clang-analyzer-security.ArrayBound) common::String mn = idx->get_measurement_name(); m.measurement_name = strdup(mn.to_std_string().c_str()); if (m.measurement_name == nullptr) { @@ -3001,6 +3007,7 @@ ResultSet tsfile_query_table_with_tag_filter( auto* r = static_cast(reader); storage::ResultSet* table_result_set = nullptr; std::vector column_names; + column_names.reserve(column_num); for (uint32_t i = 0; i < column_num; i++) { column_names.emplace_back(columns[i]); } diff --git a/cpp/src/dataset/dataset_index.cc b/cpp/src/dataset/dataset_index.cc index f098e3aa2a..7bda93f8e1 100644 --- a/cpp/src/dataset/dataset_index.cc +++ b/cpp/src/dataset/dataset_index.cc @@ -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(view.data); const uint64_t hash = dataset_index_name_hash(name.data(), name.size()); @@ -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(view.data); const uint64_t hash = dataset_index_name_hash(name.data(), name.size()); @@ -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(view.data); uint32_t low = device->first_series_id; diff --git a/cpp/src/encoding/alp/alp_traits.h b/cpp/src/encoding/alp/alp_traits.h index e1046df69f..6508ddf317 100644 --- a/cpp/src/encoding/alp/alp_traits.h +++ b/cpp/src/encoding/alp/alp_traits.h @@ -88,6 +88,9 @@ struct AlpTypeTraits { } 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; } }; @@ -148,6 +151,8 @@ struct AlpTypeTraits { } 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; } }; diff --git a/cpp/src/encoding/chimp_decoder.h b/cpp/src/encoding/chimp_decoder.h index 25f6571139..80aff3f706 100644 --- a/cpp/src/encoding/chimp_decoder.h +++ b/cpp/src/encoding/chimp_decoder.h @@ -32,7 +32,7 @@ namespace storage { -static constexpr int8_t CHIMP_LEADING_DECODING[8] = {0, 8, 12, 16, +static constexpr uint8_t CHIMP_LEADING_DECODING[8] = {0, 8, 12, 16, 18, 20, 22, 24}; template diff --git a/cpp/src/encoding/chimp_encoder.h b/cpp/src/encoding/chimp_encoder.h index 0be5d3b639..a5d6b6063e 100644 --- a/cpp/src/encoding/chimp_encoder.h +++ b/cpp/src/encoding/chimp_encoder.h @@ -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, diff --git a/cpp/src/encoding/dictionary_encoder.h b/cpp/src/encoding/dictionary_encoder.h index 8f7c495c40..fa76bdb12a 100644 --- a/cpp/src/encoding/dictionary_encoder.h +++ b/cpp/src/encoding/dictionary_encoder.h @@ -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(); diff --git a/cpp/src/encoding/plain_encoder.h b/cpp/src/encoding/plain_encoder.h index 3db87e173d..21784dca17 100644 --- a/cpp/src/encoding/plain_encoder.h +++ b/cpp/src/encoding/plain_encoder.h @@ -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 */ diff --git a/cpp/src/encoding/ts2diff_decoder.h b/cpp/src/encoding/ts2diff_decoder.h index 5fa1b62bde..521b85ce45 100644 --- a/cpp/src/encoding/ts2diff_decoder.h +++ b/cpp/src/encoding/ts2diff_decoder.h @@ -475,7 +475,7 @@ class TS2DIFFDecoder : public Decoder { template <> inline int32_t TS2DIFFDecoder::decode(common::ByteStream& in) { - int32_t ret_value = stored_value_; + int32_t ret_value = 0; if (UNLIKELY(current_index_ == 0)) { if (read_header(in) != common::E_OK) { // Poison the block state so callers stop; value is undefined @@ -518,7 +518,7 @@ inline int32_t TS2DIFFDecoder::decode(common::ByteStream& in) { template <> inline int64_t TS2DIFFDecoder::decode(common::ByteStream& in) { - int64_t ret_value = stored_value_; + int64_t ret_value = 0; if (UNLIKELY(current_index_ == 0)) { if (read_header(in) != common::E_OK) { write_index_ = 0; diff --git a/cpp/src/encoding/ts2diff_encoder.h b/cpp/src/encoding/ts2diff_encoder.h index e08af0526a..1e71c653fd 100644 --- a/cpp/src/encoding/ts2diff_encoder.h +++ b/cpp/src/encoding/ts2diff_encoder.h @@ -100,7 +100,9 @@ class TS2DIFFEncoder : public Encoder { public: TS2DIFFEncoder() { init(); } - ~TS2DIFFEncoder() { destroy(); } + // Qualified call: destroy() is virtual, but a destructor must not + // dispatch to derived overrides. + ~TS2DIFFEncoder() { TS2DIFFEncoder::destroy(); } void reset() override { write_index_ = -1; } diff --git a/cpp/src/encoding/zigzag_encoder.h b/cpp/src/encoding/zigzag_encoder.h index 96d3cb9cc8..4ecea6e307 100644 --- a/cpp/src/encoding/zigzag_encoder.h +++ b/cpp/src/encoding/zigzag_encoder.h @@ -144,7 +144,6 @@ inline int ZigzagEncoder::encode(int32_t value) { } write_byte_without_subsequence(value_zigzag); - value_zigzag = (uint32_t)value_zigzag >> 7; return common::E_OK; } @@ -176,7 +175,6 @@ inline int ZigzagEncoder::encode(int64_t value) { } write_byte_without_subsequence(value_zigzag); - value_zigzag = (uint64_t)value_zigzag >> 7; return common::E_OK; } diff --git a/cpp/src/file/local_random_access_read_file.cc b/cpp/src/file/local_random_access_read_file.cc index cc42d41612..7192459482 100644 --- a/cpp/src/file/local_random_access_read_file.cc +++ b/cpp/src/file/local_random_access_read_file.cc @@ -97,10 +97,10 @@ int LocalRandomAccessReadFile::generation(uint64_t& size, int LocalRandomAccessReadFile::get_file_generation_from_descriptor( uint64_t& size, uint64_t& fingerprint) const { int64_t mtime_ns = 0; -#ifdef _WIN32 if (fd_ < 0) { return E_FILE_READ_ERR; } +#ifdef _WIN32 intptr_t handle_value = _get_osfhandle(fd_); if (handle_value == -1) { return E_FILE_READ_ERR; diff --git a/cpp/src/file/local_random_access_read_file.h b/cpp/src/file/local_random_access_read_file.h index 4d74254fd5..392aea3a24 100644 --- a/cpp/src/file/local_random_access_read_file.h +++ b/cpp/src/file/local_random_access_read_file.h @@ -35,12 +35,14 @@ namespace storage { class LocalRandomAccessReadFile : public RandomAccessReadFile { public: LocalRandomAccessReadFile(); - ~LocalRandomAccessReadFile() override { destroy(); } + ~LocalRandomAccessReadFile() override { + LocalRandomAccessReadFile::destroy(); + } LocalRandomAccessReadFile(const LocalRandomAccessReadFile&) = delete; LocalRandomAccessReadFile& operator=(const LocalRandomAccessReadFile&) = delete; - void destroy() { close(); } + void destroy() { LocalRandomAccessReadFile::close(); } int open(const std::string& file_path); FORCE_INLINE bool is_opened() const override { diff --git a/cpp/src/file/restorable_tsfile_io_writer.cc b/cpp/src/file/restorable_tsfile_io_writer.cc index 605ff6e033..ff011a356a 100644 --- a/cpp/src/file/restorable_tsfile_io_writer.cc +++ b/cpp/src/file/restorable_tsfile_io_writer.cc @@ -825,6 +825,14 @@ int RestorableTsFileIOWriter::self_check(bool truncate_corrupted) { return E_TSFILE_CORRUPTED; } + // Read errors during the scan are treated as a truncated tail and + // recovered below, but an allocation failure is not corruption: surface + // it instead of silently returning a recovered writer. + if (ret == common::E_OOM) { + reader.close(); + return ret; + } + flush_chunk_group(); get_schema()->finalize_table_schemas(); reader.close(); diff --git a/cpp/src/file/tsfile_io_reader.cc b/cpp/src/file/tsfile_io_reader.cc index 6de4ed20da..ff351fccac 100644 --- a/cpp/src/file/tsfile_io_reader.cc +++ b/cpp/src/file/tsfile_io_reader.cc @@ -86,7 +86,7 @@ void TsFileIOReader::reset() { } } -int TsFileIOReader::alloc_ssi(std::shared_ptr device_id, +int TsFileIOReader::alloc_ssi(const std::shared_ptr& device_id, const std::string& measurement_name, TsFileSeriesScanIterator*& ssi, common::PageArena& pa, Filter* time_filter) { @@ -94,7 +94,7 @@ int TsFileIOReader::alloc_ssi(std::shared_ptr device_id, nullptr); } -int TsFileIOReader::alloc_ssi(std::shared_ptr device_id, +int TsFileIOReader::alloc_ssi(const std::shared_ptr& device_id, const std::string& measurement_name, TsFileSeriesScanIterator*& ssi, common::PageArena& pa, Filter* time_filter, @@ -339,7 +339,7 @@ int TsFileIOReader::alloc_prepared_multi_ssi( } int TsFileIOReader::alloc_multi_ssi( - std::shared_ptr device_id, + const std::shared_ptr& device_id, const std::vector& measurement_names, TsFileSeriesScanIterator*& ssi, common::PageArena& pa, Filter* time_filter, AlignedFieldFilter* field_filter) { @@ -450,7 +450,7 @@ void TsFileIOReader::revert_ssi(TsFileSeriesScanIterator* ssi) { } int TsFileIOReader::get_device_timeseries_meta_without_chunk_meta( - std::shared_ptr device_id, + const std::shared_ptr& device_id, std::vector& timeseries_indexs, PageArena& pa) { int ret = E_OK; if (RET_FAIL(load_tsfile_meta_if_necessary())) { @@ -677,7 +677,7 @@ std::string TsFileIOReader::device_node_cache_key( return key; } -int TsFileIOReader::get_cached_device_node(std::shared_ptr device_id, +int TsFileIOReader::get_cached_device_node(const std::shared_ptr& device_id, common::PageArena& pa, CachedDeviceNode& out) { (void)pa; @@ -757,7 +757,7 @@ int TsFileIOReader::get_cached_device_node(std::shared_ptr device_id, } int TsFileIOReader::load_timeseries_index_for_ssi( - std::shared_ptr device_id, const std::string& measurement_name, + const std::shared_ptr& device_id, const std::string& measurement_name, TsFileSeriesScanIterator*& ssi) { int ret = E_OK; auto& pa = ssi->timeseries_index_pa_; @@ -811,7 +811,7 @@ int TsFileIOReader::load_timeseries_index_for_ssi( } int TsFileIOReader::load_device_index_entry( - std::shared_ptr device_name, + const std::shared_ptr& device_name, std::shared_ptr& device_index_entry, int64_t& end_offset) { int ret = E_OK; std::shared_ptr device_id_comparable = @@ -846,7 +846,7 @@ int TsFileIOReader::load_device_index_entry( int TsFileIOReader::load_measurement_index_entry( const std::string& measurement_name_str, - std::shared_ptr top_node, + const std::shared_ptr& top_node, std::shared_ptr& ret_measurement_index_entry, int64_t& ret_end_offset, common::PageArena& result_pa) { int ret = E_OK; @@ -942,7 +942,7 @@ int TsFileIOReader::read_device_meta_index(int64_t start_offset, } int TsFileIOReader::get_timeseries_indexes( - std::shared_ptr device_id, + const std::shared_ptr& device_id, const std::unordered_set& measurement_names, std::vector& timeseries_indexs, common::PageArena& pa) { int ret = E_OK; @@ -1077,8 +1077,8 @@ int TsFileIOReader::get_timeseries_indexes( * @index_node leaf device node or leaf measurement node */ int TsFileIOReader::search_from_leaf_node( - std::shared_ptr target_name, - std::shared_ptr index_node, + const std::shared_ptr& target_name, + const std::shared_ptr& index_node, std::shared_ptr& ret_index_entry, int64_t& ret_end_offset) { int ret = E_OK; @@ -1160,8 +1160,8 @@ int TsFileIOReader::get_cached_index_node(int64_t start_offset, } int TsFileIOReader::search_from_internal_node( - std::shared_ptr target_name, bool is_device, - std::shared_ptr index_node, + const std::shared_ptr& target_name, bool is_device, + const std::shared_ptr& index_node, std::shared_ptr& ret_index_entry, int64_t& ret_end_offset, common::PageArena* result_pa) { int ret = E_OK; @@ -1172,7 +1172,7 @@ int TsFileIOReader::search_from_internal_node( ASSERT(index_node->node_type_ == INTERNAL_MEASUREMENT || index_node->node_type_ == INTERNAL_DEVICE); if (RET_FAIL(index_node->binary_search_children( - target_name, /*exact=*/false, index_entry, end_offset, + target_name, /*exact_search=*/false, index_entry, end_offset, output_pa))) { return ret; } @@ -1199,15 +1199,15 @@ int TsFileIOReader::search_from_internal_node( } if (cur_level.node->node_type_ == LEAF_DEVICE) { return cur_level.node->binary_search_children( - target_name, /*exact=*/true, ret_index_entry, ret_end_offset, + target_name, /*exact_search=*/true, ret_index_entry, ret_end_offset, output_pa); } else if (cur_level.node->node_type_ == LEAF_MEASUREMENT) { return cur_level.node->binary_search_children( - target_name, /*exact=*/false, ret_index_entry, ret_end_offset, + target_name, /*exact_search=*/false, ret_index_entry, ret_end_offset, output_pa); } else { ret = cur_level.node->binary_search_children( - target_name, /*exact=*/false, index_entry, end_offset, + target_name, /*exact_search=*/false, index_entry, end_offset, output_pa); } } @@ -1215,7 +1215,7 @@ int TsFileIOReader::search_from_internal_node( } bool TsFileIOReader::is_aligned_device( - std::shared_ptr measurement_node) { + const std::shared_ptr& measurement_node) { if (measurement_node->children_.empty()) { return false; } @@ -1225,7 +1225,7 @@ bool TsFileIOReader::is_aligned_device( } int TsFileIOReader::get_time_column_metadata( - std::shared_ptr measurement_node, + const std::shared_ptr& measurement_node, TimeseriesIndex*& ret_timeseries_index, PageArena& pa) { int ret = E_OK; if (!is_aligned_device(measurement_node)) { @@ -1486,7 +1486,7 @@ int TsFileIOReader::do_load_all_timeseries_index( } int TsFileIOReader::get_all_leaf( - std::shared_ptr index_node, + const std::shared_ptr& index_node, std::vector, int64_t>>& index_node_entry_list, common::PageArena& pa) { diff --git a/cpp/src/file/tsfile_io_reader.h b/cpp/src/file/tsfile_io_reader.h index f996991cd8..c16a02695b 100644 --- a/cpp/src/file/tsfile_io_reader.h +++ b/cpp/src/file/tsfile_io_reader.h @@ -84,7 +84,7 @@ class TsFileIOReader { // Backward-compatible overload for callers compiled against the // previous signature; forwards a null series-type out-param. - int alloc_ssi(std::shared_ptr device_id, + int alloc_ssi(const std::shared_ptr& device_id, const std::string& measurement_name, TsFileSeriesScanIterator*& ssi, common::PageArena& pa, Filter* time_filter = nullptr); @@ -92,12 +92,12 @@ class TsFileIOReader { // out_series_type when the series exists but has no data in the query // range. The final argument is required to keep overload resolution // unambiguous with the overload above. - int alloc_ssi(std::shared_ptr device_id, + int alloc_ssi(const std::shared_ptr& device_id, const std::string& measurement_name, TsFileSeriesScanIterator*& ssi, common::PageArena& pa, Filter* time_filter, common::TSDataType* out_series_type); - int alloc_multi_ssi(std::shared_ptr device_id, + int alloc_multi_ssi(const std::shared_ptr& device_id, const std::vector& measurement_names, TsFileSeriesScanIterator*& ssi, common::PageArena& pa, Filter* time_filter = nullptr, @@ -141,7 +141,7 @@ class TsFileIOReader { } int get_device_timeseries_meta_without_chunk_meta( - std::shared_ptr device_id, + const std::shared_ptr& device_id, std::vector& timeseries_indexs, common::PageArena& pa); @@ -151,7 +151,7 @@ class TsFileIOReader { common::PageArena& pa, MetaIndexNode*& device_meta_index, bool leaf); int get_timeseries_indexes( - std::shared_ptr device_id, + const std::shared_ptr& device_id, const std::unordered_set& measurement_names, std::vector& timeseries_indexs, common::PageArena& pa); @@ -162,7 +162,7 @@ class TsFileIOReader { common::PageArena& pa); int load_device_index_entry( - std::shared_ptr target_name, + const std::shared_ptr& target_name, std::shared_ptr& device_index_entry, int64_t& end_offset); @@ -175,7 +175,7 @@ class TsFileIOReader { int load_measurement_index_entry( const std::string& measurement_name, - std::shared_ptr top_node, + const std::shared_ptr& top_node, std::shared_ptr& ret_measurement_index_entry, int64_t& ret_end_offset, common::PageArena& result_pa); @@ -184,10 +184,10 @@ class TsFileIOReader { std::vector, int64_t>>& ret_measurement_index_entry); - bool is_aligned_device(std::shared_ptr measurement_node); + bool is_aligned_device(const std::shared_ptr& measurement_node); int get_time_column_metadata( - std::shared_ptr measurement_node, + const std::shared_ptr& measurement_node, TimeseriesIndex*& ret_timeseries_index, common::PageArena& pa); int do_load_timeseries_index(const std::string& measurement_name_str, @@ -210,18 +210,18 @@ class TsFileIOReader { int64_t start_offset, int64_t end_offset, common::PageArena& pa, std::vector& ts_indexs); - int load_timeseries_index_for_ssi(std::shared_ptr device_id, + int load_timeseries_index_for_ssi(const std::shared_ptr& device_id, const std::string& measurement_name, TsFileSeriesScanIterator*& ssi); - int search_from_leaf_node(std::shared_ptr target_name, - std::shared_ptr index_node, + int search_from_leaf_node(const std::shared_ptr& target_name, + const std::shared_ptr& index_node, std::shared_ptr& ret_index_entry, int64_t& ret_end_offset); int search_from_internal_node( - std::shared_ptr target_name, bool is_device, - std::shared_ptr index_node, + const std::shared_ptr& target_name, bool is_device, + const std::shared_ptr& index_node, std::shared_ptr& ret_index_entry, int64_t& ret_end_offset, common::PageArena* result_pa = nullptr); @@ -237,7 +237,7 @@ class TsFileIOReader { // outlive index_node_entry_list. Callers pass the same arena they later // hand to do_load_all_timeseries_index(). int get_all_leaf( - std::shared_ptr index_node, + const std::shared_ptr& index_node, std::vector, int64_t>>& index_node_entry_list, common::PageArena& pa); @@ -329,7 +329,7 @@ class TsFileIOReader { // failure (E_DEVICE_NOT_EXIST when the device is absent, the propagated // error otherwise). Copying into out keeps the caller safe from rehash / // concurrent eviction of the cache map. - int get_cached_device_node(std::shared_ptr device_id, + int get_cached_device_node(const std::shared_ptr& device_id, common::PageArena& pa, CachedDeviceNode& out); #ifdef ENABLE_TEST diff --git a/cpp/src/file/tsfile_io_writer.cc b/cpp/src/file/tsfile_io_writer.cc index 20d83e1502..2d5712d8a7 100644 --- a/cpp/src/file/tsfile_io_writer.cc +++ b/cpp/src/file/tsfile_io_writer.cc @@ -164,7 +164,7 @@ int TsFileIOWriter::start_file() { } int TsFileIOWriter::start_flush_chunk_group( - std::shared_ptr device_name, bool is_aligned) { + const std::shared_ptr& device_name, bool is_aligned) { int ret = write_byte(CHUNK_GROUP_HEADER_MARKER); if (ret != common::E_OK) { return ret; @@ -320,15 +320,15 @@ int TsFileIOWriter::end_file() { OFFSET_DEBUG("before end file"); if (RET_FAIL(write_log_index_range())) { - std::cout << "writer range index error, ret =" << ret << std::endl; + std::cout << "writer range index error, ret =" << ret << '\n'; } else if (RET_FAIL(write_file_index())) { - std::cout << "writer file index error, ret = " << ret << std::endl; + std::cout << "writer file index error, ret = " << ret << '\n'; } else if (RET_FAIL(write_file_footer())) { - std::cout << "writer file footer error, ret = " << ret << std::endl; + std::cout << "writer file footer error, ret = " << ret << '\n'; } else if (g_config_value_.sync_on_close_ && RET_FAIL(sync_file())) { - std::cout << "sync file error, ret = " << ret << std::endl; + std::cout << "sync file error, ret = " << ret << '\n'; } else if (RET_FAIL(close_file())) { - std::cout << "close file error, ret = " << ret << std::endl; + std::cout << "close file error, ret = " << ret << '\n'; } return ret; @@ -341,13 +341,13 @@ int TsFileIOWriter::write_log_index_range() { const int64_t max_plan_index = 0; // 0x8000000000000000; // OFFSET_DEBUG("before writer log index"); if (RET_FAIL(write_byte(OPERATION_INDEX_RANGE))) { - std::cout << "writer byte error " << ret << std::endl; + std::cout << "writer byte error " << ret << '\n'; } else if (RET_FAIL(SerializationUtil::write_i64(min_plan_index, write_stream_))) { - std::cout << "min index error " << ret << std::endl; + std::cout << "min index error " << ret << '\n'; } else if (RET_FAIL(SerializationUtil::write_i64(max_plan_index, write_stream_))) { - std::cout << "max index error " << ret << std::endl; + std::cout << "max index error " << ret << '\n'; } return ret; } @@ -471,9 +471,9 @@ int TsFileIOWriter::write_file_index() { tmp_device_name.dup_from(device_id->get_device_name(), meta_allocator_); // Time column also need add to bloom filter. - ret = filter.add_path_entry(tmp_device_name, measurement_name); - - if (RET_FAIL(ts_index.serialize_to(write_stream_))) { + if (RET_FAIL( + filter.add_path_entry(tmp_device_name, measurement_name))) { + } else if (RET_FAIL(ts_index.serialize_to(write_stream_))) { } else { #if DEBUG_SE std::cout << "ts_index.serialize. ts_index=" << ts_index @@ -719,7 +719,7 @@ int TsFileIOWriter::alloc_and_init_meta_index_node( } int TsFileIOWriter::add_cur_index_node_to_queue( - std::shared_ptr node, + const std::shared_ptr& node, SimpleList>* queue) const { node->end_offset_ = cur_file_position(); #if DEBUG_SE @@ -741,7 +741,7 @@ int TsFileIOWriter::alloc_meta_index_node_queue( } int TsFileIOWriter::add_device_node( - DeviceNodeMap& device_map, std::shared_ptr device_id, + DeviceNodeMap& device_map, const std::shared_ptr& device_id, common::SimpleList>* measurement_index_node_queue, FileIndexWritingMemManager& wmm) { diff --git a/cpp/src/file/tsfile_io_writer.h b/cpp/src/file/tsfile_io_writer.h index b149358b41..1fc460a093 100644 --- a/cpp/src/file/tsfile_io_writer.h +++ b/cpp/src/file/tsfile_io_writer.h @@ -100,7 +100,7 @@ class TsFileIOWriter { int add_tsfile_property(const std::string& key, const std::vector& value); int start_file(); - int start_flush_chunk_group(std::shared_ptr device_id, + int start_flush_chunk_group(const std::shared_ptr& device_id, bool is_aligned = false); int start_flush_chunk(common::ByteStream& chunk_data, common::ColumnSchema& col_schema, @@ -159,13 +159,13 @@ class TsFileIOWriter { std::shared_ptr& ret_node, MetaIndexNodeType node_type); int add_cur_index_node_to_queue( - std::shared_ptr node, + const std::shared_ptr& node, common::SimpleList>* queue) const; int alloc_meta_index_node_queue( FileIndexWritingMemManager& wmm, common::SimpleList>*& queue); int add_device_node(DeviceNodeMap& device_map, - std::shared_ptr device_id, + const std::shared_ptr& device_id, common::SimpleList>* measurement_index_node_queue, FileIndexWritingMemManager& wmm); diff --git a/cpp/src/file/write_file.h b/cpp/src/file/write_file.h index d62c7e21e6..e5ee990140 100644 --- a/cpp/src/file/write_file.h +++ b/cpp/src/file/write_file.h @@ -42,7 +42,7 @@ class WriteFile : public RandomAccessWriteFile { // the fd — harmless on POSIX (unlink works on open files) but on Windows it // keeps the file locked so a subsequent remove() fails. close() is // idempotent, so this is a no-op when the file was already closed normally. - ~WriteFile() override { close(); } + ~WriteFile() override { WriteFile::close(); } int create(const std::string& file_name, int flags, mode_t mode); /** Kept for source compatibility; use is_opened(). */ bool file_opened() const { return is_opened(); } diff --git a/cpp/src/reader/aligned_chunk_reader.cc b/cpp/src/reader/aligned_chunk_reader.cc index 7ecda10f79..4556f69307 100644 --- a/cpp/src/reader/aligned_chunk_reader.cc +++ b/cpp/src/reader/aligned_chunk_reader.cc @@ -599,7 +599,7 @@ int AlignedChunkReader::decode_cur_time_page_data() { #endif if (ret != E_OK || time_uncompressed_buf_size != cur_time_page_header_.uncompressed_size_) { - ret = E_TSFILE_CORRUPTED; + ret = E_TSFILE_CORRUPTED; // NOLINT(clang-analyzer-deadcode.DeadStores) ASSERT(false); } } @@ -663,7 +663,7 @@ int AlignedChunkReader::decode_cur_value_page_data() { #endif if (ret != E_OK || value_uncompressed_buf_size != cur_value_page_header_.uncompressed_size_) { - ret = E_TSFILE_CORRUPTED; + ret = E_TSFILE_CORRUPTED; // NOLINT(clang-analyzer-deadcode.DeadStores) ASSERT(false); } } @@ -1069,7 +1069,7 @@ int AlignedChunkReader::decode_tv_buf_into_tsblock_by_datatype( time_in, value_in, row_appender, *pa, filter); break; default: - ret = E_NOT_SUPPORT; + ret = E_NOT_SUPPORT; // NOLINT(clang-analyzer-deadcode.DeadStores) ASSERT(false); } // An empty result only means every row of this page was filtered out; the diff --git a/cpp/src/reader/block/device_ordered_tsblock_reader.cc b/cpp/src/reader/block/device_ordered_tsblock_reader.cc index 2c9b088415..6a9577b63b 100644 --- a/cpp/src/reader/block/device_ordered_tsblock_reader.cc +++ b/cpp/src/reader/block/device_ordered_tsblock_reader.cc @@ -103,9 +103,14 @@ int DeviceOrderedTsBlockReader::next(common::TsBlock*& ret_block) { int ret = common::E_OK; bool next = false; if (RET_FAIL(has_next(next)) || !next) { - } else if (RET_FAIL(current_reader_->next(ret_block))) { + return ret; } - return ret; + // has_next() only reports true after a reader has been created; keep an + // explicit guard so a future change cannot dereference null here. + if (UNLIKELY(current_reader_ == nullptr)) { + return common::E_INVALID_ARG; + } + return current_reader_->next(ret_block); } void DeviceOrderedTsBlockReader::close() { diff --git a/cpp/src/reader/block/single_device_tsblock_reader.h b/cpp/src/reader/block/single_device_tsblock_reader.h index 079943a873..b05bc4ce34 100644 --- a/cpp/src/reader/block/single_device_tsblock_reader.h +++ b/cpp/src/reader/block/single_device_tsblock_reader.h @@ -113,7 +113,9 @@ class SingleDeviceTsBlockReader : public TsBlockReader { TsFileIOReader* tsfile_io_reader, Filter* time_filter, Filter* field_filter); - ~SingleDeviceTsBlockReader() { close(); } + // Qualified call: close() is virtual, but a destructor must not dispatch + // to derived overrides. + ~SingleDeviceTsBlockReader() { SingleDeviceTsBlockReader::close(); } int has_next(bool& has_next) override; int next(common::TsBlock*& ret_block) override; int init(DeviceQueryTask* device_query_task, uint32_t block_size, diff --git a/cpp/src/reader/chunk_reader.cc b/cpp/src/reader/chunk_reader.cc index 3c51d28f7d..5066aa8040 100644 --- a/cpp/src/reader/chunk_reader.cc +++ b/cpp/src/reader/chunk_reader.cc @@ -355,7 +355,7 @@ int ChunkReader::decode_cur_page_data(TsBlock*& ret_tsblock, Filter* filter, // uncompressed_buf, uncompressed_buf_size); if (ret != E_OK || uncompressed_buf_size != cur_page_header_.uncompressed_size_) { - ret = E_TSFILE_CORRUPTED; + ret = E_TSFILE_CORRUPTED; // NOLINT(clang-analyzer-deadcode.DeadStores) ASSERT(false); } } @@ -378,7 +378,7 @@ int ChunkReader::decode_cur_page_data(TsBlock*& ret_tsblock, Filter* filter, << ", time_buf_size=" << time_buf_size << std::endl; #endif if (uncompressed_buf_size <= var_size + time_buf_size) { - ret = E_TSFILE_CORRUPTED; + ret = E_TSFILE_CORRUPTED; // NOLINT(clang-analyzer-deadcode.DeadStores) ASSERT(false); } } @@ -892,7 +892,7 @@ int ChunkReader::decode_tv_buf_into_tsblock_by_datatype( time_in, value_in, row_appender, *pa, filter, row_offset); break; default: - ret = E_NOT_SUPPORT; + ret = E_NOT_SUPPORT; // NOLINT(clang-analyzer-deadcode.DeadStores) ASSERT(false); } // A decode that produced zero rows has two very different causes: diff --git a/cpp/src/reader/expression.cc b/cpp/src/reader/expression.cc index 3623b390e5..ce8f1613db 100644 --- a/cpp/src/reader/expression.cc +++ b/cpp/src/reader/expression.cc @@ -42,7 +42,7 @@ void QueryExpression::add_time_filter_to_query_filter(Filter* time_filter, } else { std::cout << "Expression should contains only SingleSeriesExpression " "but other type is found" - << std::endl; + << '\n'; } } @@ -61,7 +61,7 @@ Expression* QueryExpression::combine_two_global_time_filter( my_exprs_.push_back(expr); return expr; } - std::cout << "unrecognized QueryFilterOperatorType :" << type << std::endl; + std::cout << "unrecognized QueryFilterOperatorType :" << type << '\n'; return nullptr; } @@ -109,7 +109,7 @@ Expression* QueryExpression::merge_second_tree_to_first_tree( Expression* QueryExpression::push_global_time_filter_to_all_series( Expression* time_filter, std::vector& selected_series) { if (selected_series.empty()) { - std::cout << "size of selectSeries could not be 0" << std::endl; + std::cout << "size of selectSeries could not be 0" << '\n'; return nullptr; } @@ -149,7 +149,7 @@ Expression* QueryExpression::handle_one_global_time_filter( } return merge_second_tree_to_first_tree(after_transform, expr); } - std::cout << "unknown relation in Expression:" << type << std::endl; + std::cout << "unknown relation in Expression:" << type << '\n'; return nullptr; } @@ -192,7 +192,7 @@ Expression* QueryExpression::optimize(Expression* expression, } } } else { - std::cout << "unknown Expression type:" << type << std::endl; + std::cout << "unknown Expression type:" << type << '\n'; } return nullptr; } diff --git a/cpp/src/reader/filter/aligned_field_filter.cc b/cpp/src/reader/filter/aligned_field_filter.cc index afa6bbb72a..3f66cd3844 100644 --- a/cpp/src/reader/filter/aligned_field_filter.cc +++ b/cpp/src/reader/filter/aligned_field_filter.cc @@ -286,7 +286,8 @@ AlignedFieldFilter::AlignedFieldFilter(Kind kind, std::string column, AlignedFieldFilter::AlignedFieldFilter(Kind kind, Ptr left, Ptr right) : kind_(kind), left_(std::move(left)), right_(std::move(right)) {} -AlignedFieldFilter::Ptr AlignedFieldFilter::compare(std::string column, +AlignedFieldFilter::Ptr AlignedFieldFilter::compare( + const std::string& column, CompareOp op, Literal literal) { return Ptr(new AlignedFieldFilter(Kind::COMPARISON, @@ -294,13 +295,15 @@ AlignedFieldFilter::Ptr AlignedFieldFilter::compare(std::string column, std::move(literal))); } -AlignedFieldFilter::Ptr AlignedFieldFilter::is_null(std::string column) { +AlignedFieldFilter::Ptr AlignedFieldFilter::is_null( + const std::string& column) { return Ptr(new AlignedFieldFilter(Kind::IS_NULL, normalize_column_name(column), CompareOp::EQ, Literal())); } -AlignedFieldFilter::Ptr AlignedFieldFilter::is_not_null(std::string column) { +AlignedFieldFilter::Ptr AlignedFieldFilter::is_not_null( + const std::string& column) { return Ptr(new AlignedFieldFilter(Kind::IS_NOT_NULL, normalize_column_name(column), CompareOp::EQ, Literal())); diff --git a/cpp/src/reader/filter/aligned_field_filter.h b/cpp/src/reader/filter/aligned_field_filter.h index 659d165b28..90991ea28f 100644 --- a/cpp/src/reader/filter/aligned_field_filter.h +++ b/cpp/src/reader/filter/aligned_field_filter.h @@ -78,9 +78,9 @@ class AlignedFieldFilter : public Filter { ~AlignedFieldFilter() override = default; - static Ptr compare(std::string column, CompareOp op, Literal literal); - static Ptr is_null(std::string column); - static Ptr is_not_null(std::string column); + static Ptr compare(const std::string& column, CompareOp op, Literal literal); + static Ptr is_null(const std::string& column); + static Ptr is_not_null(const std::string& column); // Logical operands must be non-null. A missing operand remains an invalid // non-null tree, rejected with E_INVALID_ARG when bound or queried. static Ptr and_filter(Ptr left, Ptr right); diff --git a/cpp/src/reader/filter/filter.h b/cpp/src/reader/filter/filter.h index fc2494fac5..85ba223460 100644 --- a/cpp/src/reader/filter/filter.h +++ b/cpp/src/reader/filter/filter.h @@ -55,7 +55,7 @@ class Filter { return false; } virtual bool satisfyRow(int time, - std::vector segments) const { + const std::vector& segments) const { ASSERT(false); return false; } diff --git a/cpp/src/reader/filter/filter_type.h b/cpp/src/reader/filter/filter_type.h index 4714a11621..41c66eee5c 100644 --- a/cpp/src/reader/filter/filter_type.h +++ b/cpp/src/reader/filter/filter_type.h @@ -40,7 +40,7 @@ FORCE_INLINE std::string filter_type_to_string(FilterType type) { } default: { std::cout << "filter_type_to_string unknown type:" << type - << std::endl; + << '\n'; return ""; } } diff --git a/cpp/src/reader/filter/tag_filter.cc b/cpp/src/reader/filter/tag_filter.cc index 03b8ae7856..9436d81367 100644 --- a/cpp/src/reader/filter/tag_filter.cc +++ b/cpp/src/reader/filter/tag_filter.cc @@ -30,11 +30,11 @@ TagFilter::TagFilter(int col_idx, std::string tag_value) TagFilter::~TagFilter() = default; -bool TagFilter::satisfyRow(int time, std::vector segments) const { +bool TagFilter::satisfyRow(int time, const std::vector& segments) const { return satisfyRow(segments); } -bool TagFilter::satisfyRow(std::vector segments) const { +bool TagFilter::satisfyRow(const std::vector& segments) const { ASSERT(false); return false; } @@ -43,7 +43,7 @@ bool TagFilter::satisfyRow(std::vector segments) const { TagEq::TagEq(int col_idx, std::string tag_value) : TagFilter(col_idx, std::move(tag_value)) {} -bool TagEq::satisfyRow(std::vector segments) const { +bool TagEq::satisfyRow(const std::vector& segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr) return false; return *segments[col_idx_] == value_; @@ -53,7 +53,7 @@ bool TagEq::satisfyRow(std::vector segments) const { TagNeq::TagNeq(int col_idx, std::string tag_value) : TagFilter(col_idx, std::move(tag_value)) {} -bool TagNeq::satisfyRow(std::vector segments) const { +bool TagNeq::satisfyRow(const std::vector& segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr) return false; return *segments[col_idx_] != value_; @@ -63,7 +63,7 @@ bool TagNeq::satisfyRow(std::vector segments) const { TagLt::TagLt(int col_idx, std::string tag_value) : TagFilter(col_idx, std::move(tag_value)) {} -bool TagLt::satisfyRow(std::vector segments) const { +bool TagLt::satisfyRow(const std::vector& segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr) return false; return *segments[col_idx_] < value_; @@ -73,7 +73,7 @@ bool TagLt::satisfyRow(std::vector segments) const { TagLteq::TagLteq(int col_idx, std::string tag_value) : TagFilter(col_idx, std::move(tag_value)) {} -bool TagLteq::satisfyRow(std::vector segments) const { +bool TagLteq::satisfyRow(const std::vector& segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr) return false; return *segments[col_idx_] <= value_; @@ -83,7 +83,7 @@ bool TagLteq::satisfyRow(std::vector segments) const { TagGt::TagGt(int col_idx, std::string tag_value) : TagFilter(col_idx, std::move(tag_value)) {} -bool TagGt::satisfyRow(std::vector segments) const { +bool TagGt::satisfyRow(const std::vector& segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr) return false; return *segments[col_idx_] > value_; @@ -93,7 +93,7 @@ bool TagGt::satisfyRow(std::vector segments) const { TagGteq::TagGteq(int col_idx, std::string tag_value) : TagFilter(col_idx, std::move(tag_value)) {} -bool TagGteq::satisfyRow(std::vector segments) const { +bool TagGteq::satisfyRow(const std::vector& segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr) return false; return *segments[col_idx_] >= value_; @@ -110,7 +110,7 @@ TagRegExp::TagRegExp(int col_idx, std::string tag_value) } } -bool TagRegExp::satisfyRow(std::vector segments) const { +bool TagRegExp::satisfyRow(const std::vector& segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr || !is_valid_pattern_) return false; @@ -132,7 +132,7 @@ TagNotRegExp::TagNotRegExp(int col_idx, std::string tag_value) } } -bool TagNotRegExp::satisfyRow(std::vector segments) const { +bool TagNotRegExp::satisfyRow(const std::vector& segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr || !is_valid_pattern_) return false; @@ -146,7 +146,7 @@ bool TagNotRegExp::satisfyRow(std::vector segments) const { // TagIsNull implementation TagIsNull::TagIsNull(int col_idx) : TagFilter(col_idx, "") {} -bool TagIsNull::satisfyRow(std::vector segments) const { +bool TagIsNull::satisfyRow(const std::vector& segments) const { // A tag is null when its segment is an explicit null pointer or when the // device id omits the (trailing) segment entirely. return col_idx_ >= segments.size() || segments[col_idx_] == nullptr; @@ -155,7 +155,7 @@ bool TagIsNull::satisfyRow(std::vector segments) const { // TagIsNotNull implementation TagIsNotNull::TagIsNotNull(int col_idx) : TagFilter(col_idx, "") {} -bool TagIsNotNull::satisfyRow(std::vector segments) const { +bool TagIsNotNull::satisfyRow(const std::vector& segments) const { return col_idx_ < segments.size() && segments[col_idx_] != nullptr; } @@ -166,7 +166,7 @@ TagBetween::TagBetween(int col_idx, std::string lower_value, value2_ = std::move(upper_value); } -bool TagBetween::satisfyRow(std::vector segments) const { +bool TagBetween::satisfyRow(const std::vector& segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr) return false; const std::string& segment_value = *segments[col_idx_]; @@ -180,7 +180,7 @@ TagNotBetween::TagNotBetween(int col_idx, std::string lower_value, value2_ = std::move(upper_value); } -bool TagNotBetween::satisfyRow(std::vector segments) const { +bool TagNotBetween::satisfyRow(const std::vector& segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr) return false; const std::string& segment_value = *segments[col_idx_]; @@ -196,7 +196,7 @@ TagAnd::~TagAnd() { delete right_; } -bool TagAnd::satisfyRow(std::vector segments) const { +bool TagAnd::satisfyRow(const std::vector& segments) const { return left_->satisfyRow(segments) && right_->satisfyRow(segments); } @@ -209,7 +209,7 @@ TagOr::~TagOr() { delete right_; } -bool TagOr::satisfyRow(std::vector segments) const { +bool TagOr::satisfyRow(const std::vector& segments) const { return left_->satisfyRow(segments) || right_->satisfyRow(segments); } @@ -218,7 +218,7 @@ TagNot::TagNot(TagFilter* filter) : TagFilter(-1, ""), filter_(filter) {} TagNot::~TagNot() { delete filter_; } -bool TagNot::satisfyRow(std::vector segments) const { +bool TagNot::satisfyRow(const std::vector& segments) const { return !filter_->satisfyRow(segments); } diff --git a/cpp/src/reader/filter/tag_filter.h b/cpp/src/reader/filter/tag_filter.h index 50c750d441..12da736fa1 100644 --- a/cpp/src/reader/filter/tag_filter.h +++ b/cpp/src/reader/filter/tag_filter.h @@ -36,8 +36,8 @@ class TagFilter : public Filter { ~TagFilter() override; bool satisfyRow(int time, - std::vector segments) const override; - virtual bool satisfyRow(std::vector segments) const; + const std::vector& segments) const override; + virtual bool satisfyRow(const std::vector& segments) const; std::string value_; std::string value2_; // For range queries @@ -48,42 +48,42 @@ class TagFilter : public Filter { class TagEq : public TagFilter { public: TagEq(int col_idx, std::string tag_value); - bool satisfyRow(std::vector segments) const override; + bool satisfyRow(const std::vector& segments) const override; }; // Inequality comparison class TagNeq : public TagFilter { public: TagNeq(int col_idx, std::string tag_value); - bool satisfyRow(std::vector segments) const override; + bool satisfyRow(const std::vector& segments) const override; }; // Less than comparison class TagLt : public TagFilter { public: TagLt(int col_idx, std::string tag_value); - bool satisfyRow(std::vector segments) const override; + bool satisfyRow(const std::vector& segments) const override; }; // Less than or equal comparison class TagLteq : public TagFilter { public: TagLteq(int col_idx, std::string tag_value); - bool satisfyRow(std::vector segments) const override; + bool satisfyRow(const std::vector& segments) const override; }; // Greater than comparison class TagGt : public TagFilter { public: TagGt(int col_idx, std::string tag_value); - bool satisfyRow(std::vector segments) const override; + bool satisfyRow(const std::vector& segments) const override; }; // Greater than or equal comparison class TagGteq : public TagFilter { public: TagGteq(int col_idx, std::string tag_value); - bool satisfyRow(std::vector segments) const override; + bool satisfyRow(const std::vector& segments) const override; }; // Regular expression match @@ -93,7 +93,7 @@ class TagRegExp : public TagFilter { public: TagRegExp(int col_idx, std::string tag_value); - bool satisfyRow(std::vector segments) const override; + bool satisfyRow(const std::vector& segments) const override; }; // Regular expression not match @@ -103,7 +103,7 @@ class TagNotRegExp : public TagFilter { public: TagNotRegExp(int col_idx, std::string tag_value); - bool satisfyRow(std::vector segments) const override; + bool satisfyRow(const std::vector& segments) const override; }; // IS NULL: tag column has no value for this device. An absent trailing @@ -111,21 +111,21 @@ class TagNotRegExp : public TagFilter { class TagIsNull : public TagFilter { public: explicit TagIsNull(int col_idx); - bool satisfyRow(std::vector segments) const override; + bool satisfyRow(const std::vector& segments) const override; }; // IS NOT NULL: tag column has a concrete value for this device. class TagIsNotNull : public TagFilter { public: explicit TagIsNotNull(int col_idx); - bool satisfyRow(std::vector segments) const override; + bool satisfyRow(const std::vector& segments) const override; }; // Range query [value_, value2_] class TagBetween : public TagFilter { public: TagBetween(int col_idx, std::string lower_value, std::string upper_value); - bool satisfyRow(std::vector segments) const override; + bool satisfyRow(const std::vector& segments) const override; }; // Not in range @@ -133,7 +133,7 @@ class TagNotBetween : public TagFilter { public: TagNotBetween(int col_idx, std::string lower_value, std::string upper_value); - bool satisfyRow(std::vector segments) const override; + bool satisfyRow(const std::vector& segments) const override; }; // Logical AND operation (binary) @@ -141,7 +141,7 @@ class TagAnd : public TagFilter { public: TagAnd(TagFilter* left, TagFilter* right); ~TagAnd() override; - bool satisfyRow(std::vector segments) const override; + bool satisfyRow(const std::vector& segments) const override; private: TagFilter* left_; @@ -153,7 +153,7 @@ class TagOr : public TagFilter { public: TagOr(TagFilter* left, TagFilter* right); ~TagOr() override; - bool satisfyRow(std::vector segments) const override; + bool satisfyRow(const std::vector& segments) const override; private: TagFilter* left_; @@ -165,7 +165,7 @@ class TagNot : public TagFilter { public: explicit TagNot(TagFilter* filter); ~TagNot() override; - bool satisfyRow(std::vector segments) const override; + bool satisfyRow(const std::vector& segments) const override; private: TagFilter* filter_; diff --git a/cpp/src/reader/qds_without_timegenerator.cc b/cpp/src/reader/qds_without_timegenerator.cc index f4d869aaa1..87499d60ee 100644 --- a/cpp/src/reader/qds_without_timegenerator.cc +++ b/cpp/src/reader/qds_without_timegenerator.cc @@ -128,7 +128,6 @@ int QDSWithoutTimeGenerator::init_internal(TsFileIOReader* io_reader, ret == E_NOT_EXIST) { // Java-aligned: silently skip paths whose device or measurement // doesn't exist in this file. - ret = E_OK; continue; } if (ret == E_NO_MORE_DATA) { @@ -145,7 +144,6 @@ int QDSWithoutTimeGenerator::init_internal(TsFileIOReader* io_reader, valid_paths.push_back(paths[i]); column_names.push_back(paths[i].full_path_); ssi_data_types.push_back(empty_series_type); - ret = E_OK; continue; } if (ret != E_OK) { diff --git a/cpp/src/reader/result_set.h b/cpp/src/reader/result_set.h index 0b73595d45..c7e97df117 100644 --- a/cpp/src/reader/result_set.h +++ b/cpp/src/reader/result_set.h @@ -99,7 +99,7 @@ class ResultSetIterator; * it should be QDSWithTimeGenerator. * @note If the query uses the table model, the cast should be TableResultSet */ -class ResultSet : std::enable_shared_from_this { +class ResultSet : public std::enable_shared_from_this { public: ResultSet() {} virtual ~ResultSet() {} @@ -361,19 +361,19 @@ inline ResultSetIterator ResultSet::iterator() { MAYBE_UNUSED static void print_table_result_set( storage::ResultSet* table_result_set) { if (table_result_set == nullptr) { - std::cout << "TableResultSet is nullptr" << std::endl; + std::cout << "TableResultSet is nullptr" << '\n'; return; } auto metadata = table_result_set->get_metadata(); if (metadata == nullptr) { - std::cout << "Metadata is nullptr" << std::endl; + std::cout << "Metadata is nullptr" << '\n'; return; } uint32_t column_count = metadata->get_column_count(); if (column_count == 0) { - std::cout << "No columns in result set" << std::endl; + std::cout << "No columns in result set" << '\n'; return; } @@ -383,7 +383,7 @@ MAYBE_UNUSED static void print_table_result_set( std::cout << "\t"; } } - std::cout << std::endl; + std::cout << '\n'; bool has_next = false; int row_count = 0; @@ -440,10 +440,10 @@ MAYBE_UNUSED static void print_table_result_set( std::cout << "\t"; } } - std::cout << std::endl; + std::cout << '\n'; row_count++; } - std::cout << "Total rows: " << row_count << std::endl; + std::cout << "Total rows: " << row_count << '\n'; } } // namespace storage diff --git a/cpp/src/reader/table_query_executor.cc b/cpp/src/reader/table_query_executor.cc index 8ecc1256de..772c5dfee4 100644 --- a/cpp/src/reader/table_query_executor.cc +++ b/cpp/src/reader/table_query_executor.cc @@ -220,6 +220,7 @@ int TableQueryExecutor::query_on_tree( } std::vector col_schema; + col_schema.reserve(tag_columns.size()); for (auto const& tag : tag_columns) { col_schema.emplace_back(tag, common::TSDataType::STRING, common::ColumnCategory::TAG); diff --git a/cpp/src/reader/table_result_set.cc b/cpp/src/reader/table_result_set.cc index 63c598c613..99588dde18 100644 --- a/cpp/src/reader/table_result_set.cc +++ b/cpp/src/reader/table_result_set.cc @@ -36,7 +36,9 @@ void TableResultSet::init() { std::make_shared(column_names_, data_types_); } -TableResultSet::~TableResultSet() { close(); } +// Qualified call: close() is virtual, but a destructor must not dispatch to +// derived overrides. +TableResultSet::~TableResultSet() { TableResultSet::close(); } int TableResultSet::next(bool& has_next) { int ret = common::E_OK; diff --git a/cpp/src/reader/table_result_set.h b/cpp/src/reader/table_result_set.h index b42b69c3ff..3d724c637e 100644 --- a/cpp/src/reader/table_result_set.h +++ b/cpp/src/reader/table_result_set.h @@ -34,8 +34,8 @@ class TableResultSet : public ResultSet { std::vector data_types, int return_mode = RETURN_ROW) : tsblock_reader_(std::move(tsblock_reader)), - column_names_(column_names), - data_types_(data_types), + column_names_(std::move(column_names)), + data_types_(std::move(data_types)), return_mode_(return_mode) { init(); } diff --git a/cpp/src/reader/task/device_query_task.cc b/cpp/src/reader/task/device_query_task.cc index 6345c93fab..7bfe6bb115 100644 --- a/cpp/src/reader/task/device_query_task.cc +++ b/cpp/src/reader/task/device_query_task.cc @@ -31,7 +31,8 @@ DeviceQueryTask* DeviceQueryTask::create_device_query_task( return nullptr; } DeviceQueryTask* task = new (buf) DeviceQueryTask( - device_id, column_names, column_mapping, index_root, table_schema); + std::move(device_id), std::move(column_names), + std::move(column_mapping), index_root, std::move(table_schema)); return task; } diff --git a/cpp/src/reader/task/device_query_task.h b/cpp/src/reader/task/device_query_task.h index 75043e44b1..a51a4ac1be 100644 --- a/cpp/src/reader/task/device_query_task.h +++ b/cpp/src/reader/task/device_query_task.h @@ -30,11 +30,11 @@ class DeviceQueryTask { std::shared_ptr column_mapping, MetaIndexNode* index_root, std::shared_ptr table_schema) - : device_id_(device_id), - column_names_(column_names), - column_mapping_(column_mapping), + : device_id_(std::move(device_id)), + column_names_(std::move(column_names)), + column_mapping_(std::move(column_mapping)), index_root_(index_root), - table_schema_(table_schema) {} + table_schema_(std::move(table_schema)) {} ~DeviceQueryTask(); static DeviceQueryTask* create_device_query_task( diff --git a/cpp/src/reader/task/device_task_iterator.h b/cpp/src/reader/task/device_task_iterator.h index ad86dbc1dd..db74d3c343 100644 --- a/cpp/src/reader/task/device_task_iterator.h +++ b/cpp/src/reader/task/device_task_iterator.h @@ -36,11 +36,11 @@ class DeviceTaskIterator { IMetadataQuerier* metadata_querier, const Filter* id_filter, std::shared_ptr table_schema) - : column_names_(column_names), - column_mapping_(column_mapping), + : column_names_(std::move(column_names)), + column_mapping_(std::move(column_mapping)), device_meta_iterator_( metadata_querier->device_iterator(index_root, id_filter)), - table_schema_(table_schema) { + table_schema_(std::move(table_schema)) { pa_.init(512, common::MOD_DEVICE_TASK_ITER); } @@ -50,11 +50,12 @@ class DeviceTaskIterator { IMetadataQuerier* metadata_querier, const Filter* id_filter, std::shared_ptr table_schema) - : column_names_(column_names), - column_mapping_(column_mapping), + : column_names_(std::move(column_names)), + column_mapping_(std::move(column_mapping)), device_meta_iterator_( - metadata_querier->device_iterator(index_roots, id_filter)), - table_schema_(table_schema) { + metadata_querier->device_iterator(std::move(index_roots), + id_filter)), + table_schema_(std::move(table_schema)) { pa_.init(512, common::MOD_DEVICE_TASK_ITER); } diff --git a/cpp/src/reader/tsfile_reader.cc b/cpp/src/reader/tsfile_reader.cc index 4a39a9f232..f6256548dc 100644 --- a/cpp/src/reader/tsfile_reader.cc +++ b/cpp/src/reader/tsfile_reader.cc @@ -56,7 +56,7 @@ int parse_paths(const std::vector& path_list, } int get_all_device_entries(std::vector& entries, - std::shared_ptr index_node, + const std::shared_ptr& index_node, RandomAccessReadFile* read_file, PageArena& pa) { int ret = E_OK; if (index_node == nullptr) { @@ -586,7 +586,7 @@ std::vector> TsFileReader::get_all_devices( // The error code is ignored to preserve the legacy interface. // New code should use the error-reporting overload and check its return // code. - get_all_devices(table_name, device_ids); + get_all_devices(std::move(table_name), device_ids); return device_ids; } @@ -650,7 +650,7 @@ int TsFileReader::get_all_devices( int TsFileReader::get_all_devices( std::vector>& device_ids, - std::shared_ptr index_node, PageArena& pa) { + const std::shared_ptr& index_node, PageArena& pa) { int ret = E_OK; if (index_node != nullptr) { if (index_node->node_type_ == LEAF_DEVICE) { @@ -744,7 +744,7 @@ int read_chunk_header_codec(RandomAccessReadFile* read_file, } // namespace int TsFileReader::get_timeseries_schema( - std::shared_ptr device_id, + const std::shared_ptr& device_id, std::vector& result) { int ret = E_OK; std::vector timeseries_indexs; @@ -807,7 +807,7 @@ int TsFileReader::get_timeseries_schema( } int TsFileReader::get_timeseries_metadata_impl( - std::shared_ptr device_id, + const std::shared_ptr& device_id, std::vector>& result) { int ret = E_OK; std::vector timeseries_indexs; @@ -916,6 +916,7 @@ int TsFileReader::get_timeseries_metadata(DeviceTimeseriesMetadataMap& result) { return ret; } else { std::vector> list; + list.reserve(raw_ts_indexes.size()); for (auto ts_idx : raw_ts_indexes) { list.emplace_back( std::shared_ptr(ts_idx, noop_deleter)); diff --git a/cpp/src/reader/tsfile_reader.h b/cpp/src/reader/tsfile_reader.h index 6f2c7d3408..06ea1376f7 100644 --- a/cpp/src/reader/tsfile_reader.h +++ b/cpp/src/reader/tsfile_reader.h @@ -260,7 +260,7 @@ class TsFileReader { * list * @return Returns 0 on success, or a non-zero error code on failure. */ - int get_timeseries_schema(std::shared_ptr device_id, + int get_timeseries_schema(const std::shared_ptr& device_id, std::vector& result); /** @@ -347,10 +347,10 @@ class TsFileReader { unsigned char file_version); int ensure_table_query_executor(int batch_size); int get_timeseries_metadata_impl( - std::shared_ptr device_id, + const std::shared_ptr& device_id, std::vector>& result); int get_all_devices(std::vector>& device_ids, - std::shared_ptr index_node, + const std::shared_ptr& index_node, common::PageArena& pa); std::unique_ptr read_file_; storage::TsFileExecutor* tsfile_executor_; diff --git a/cpp/src/reader/tsfile_series_scan_iterator.cc b/cpp/src/reader/tsfile_series_scan_iterator.cc index ba7834e0be..a88b974ea9 100644 --- a/cpp/src/reader/tsfile_series_scan_iterator.cc +++ b/cpp/src/reader/tsfile_series_scan_iterator.cc @@ -284,7 +284,9 @@ int TsFileSeriesScanIterator::get_next(TsBlock*& ret_tsblock, bool alloc, bool force_load_next_chunk = false; while (true) { if (!chunk_reader_->has_more_data() || force_load_next_chunk) { - force_load_next_chunk = false; + // Defensive reset; the flag is only re-read through the outer + // condition after being set again below. + force_load_next_chunk = false; // NOLINT(clang-analyzer-deadcode.DeadStores) while (true) { if (!has_next_chunk()) { return E_NO_MORE_DATA; diff --git a/cpp/src/reader/tsfile_series_scan_iterator.h b/cpp/src/reader/tsfile_series_scan_iterator.h index 44cca99b53..fb5b44d2ea 100644 --- a/cpp/src/reader/tsfile_series_scan_iterator.h +++ b/cpp/src/reader/tsfile_series_scan_iterator.h @@ -66,7 +66,7 @@ class TsFileSeriesScanIterator { common::PageArena& data_pa, AlignedFieldFilter* field_filter = nullptr) { ASSERT(read_file != nullptr); - device_id_ = device_id; + device_id_ = std::move(device_id); measurement_name_ = measurement_name; read_file_ = read_file; time_filter_ = time_filter; diff --git a/cpp/src/reader/tsfile_tree_reader.cc b/cpp/src/reader/tsfile_tree_reader.cc index 6d7b77e1b0..54ebe79b7a 100644 --- a/cpp/src/reader/tsfile_tree_reader.cc +++ b/cpp/src/reader/tsfile_tree_reader.cc @@ -76,7 +76,8 @@ std::vector TsFileTreeReader::get_device_schema( std::vector TsFileTreeReader::get_all_device_ids() { std::vector ret_device_ids; auto device_ids = tsfile_reader_->get_all_device_ids(); - for (auto device_id : device_ids) { + ret_device_ids.reserve(device_ids.size()); + for (const auto& device_id : device_ids) { ret_device_ids.emplace_back(device_id->get_device_name()); } return ret_device_ids; diff --git a/cpp/src/writer/tsfile_tree_writer.cc b/cpp/src/writer/tsfile_tree_writer.cc index e3f1a79bbb..4dc3d94f37 100644 --- a/cpp/src/writer/tsfile_tree_writer.cc +++ b/cpp/src/writer/tsfile_tree_writer.cc @@ -46,7 +46,7 @@ int TsFileTreeWriter::register_timeseries(std::string& device_id, } int TsFileTreeWriter::register_timeseries( - std::string& device_id, std::vector schemas) { + std::string& device_id, const std::vector& schemas) { return tsfile_writer_->register_aligned_timeseries(device_id, schemas); } diff --git a/cpp/src/writer/tsfile_tree_writer.h b/cpp/src/writer/tsfile_tree_writer.h index 170c06ddcb..bff8172a40 100644 --- a/cpp/src/writer/tsfile_tree_writer.h +++ b/cpp/src/writer/tsfile_tree_writer.h @@ -95,7 +95,7 @@ class TsFileTreeWriter { * @return Returns 0 on success, or a non-zero error code on failure. */ int register_timeseries(std::string& device_id, - std::vector schemas); + const std::vector& schemas); /** * Writes a batch of data points (tablet) for one or more time series into diff --git a/cpp/src/writer/tsfile_writer.cc b/cpp/src/writer/tsfile_writer.cc index 5e8cbb6831..5677e8f474 100644 --- a/cpp/src/writer/tsfile_writer.cc +++ b/cpp/src/writer/tsfile_writer.cc @@ -170,7 +170,8 @@ int TsFileWriter::init(std::unique_ptr write_file) { if (ret != E_OK) { return ret; } - write_file.release(); + // release() yields the raw pointer that init() already stored. + write_file.release(); // NOLINT(bugprone-unused-return-value) if (previous != nullptr && previous != raw) { delete previous; } @@ -380,7 +381,8 @@ int TsFileWriter::register_aligned_timeseries( } } schemas_.insert(std::make_pair(id, group.get())); - group.release(); + // Ownership is tracked through schemas_; the pointer is stored. + group.release(); // NOLINT(bugprone-unused-return-value) return E_OK; } @@ -547,7 +549,7 @@ std::shared_ptr TsFileWriter::get_table_schema( template int TsFileWriter::do_check_schema( - std::shared_ptr device_id, + const std::shared_ptr& device_id, MeasurementNamesGetter& measurement_names, SimpleVector& chunk_writers, SimpleVector& data_types) { @@ -619,7 +621,7 @@ int TsFileWriter::ensure_aligned_value_chunk_writer( template int TsFileWriter::do_check_schema_aligned( - std::shared_ptr device_id, + const std::shared_ptr& device_id, MeasurementNamesGetter& measurement_names, storage::TimeChunkWriter*& time_chunk_writer, common::SimpleVector& value_chunk_writers, @@ -661,7 +663,7 @@ int TsFileWriter::do_check_schema_aligned( } int TsFileWriter::do_check_schema_table( - std::shared_ptr device_id, Tablet& tablet, + const std::shared_ptr& device_id, Tablet& tablet, storage::TimeChunkWriter*& time_chunk_writer, common::SimpleVector& value_chunk_writers) { int ret = E_OK; diff --git a/cpp/src/writer/tsfile_writer.h b/cpp/src/writer/tsfile_writer.h index 953cc67e1d..934299c31d 100644 --- a/cpp/src/writer/tsfile_writer.h +++ b/cpp/src/writer/tsfile_writer.h @@ -178,20 +178,20 @@ class TsFileWriter { template int do_check_schema( - std::shared_ptr device_id, + const std::shared_ptr& device_id, MeasurementNamesGetter& measurement_names, common::SimpleVector& chunk_writers, common::SimpleVector& data_types); template int do_check_schema_aligned( - std::shared_ptr device_id, + const std::shared_ptr& device_id, MeasurementNamesGetter& measurement_names, storage::TimeChunkWriter*& time_chunk_writer, common::SimpleVector& value_chunk_writers, common::SimpleVector& data_types); int do_check_schema_table( - std::shared_ptr device_id, Tablet& tablet, + const std::shared_ptr& device_id, Tablet& tablet, storage::TimeChunkWriter*& time_chunk_writer, common::SimpleVector& value_chunk_writers); diff --git a/cpp/tools/commands/row_query.cc b/cpp/tools/commands/row_query.cc index 04908a8dfc..dc5aaf290b 100644 --- a/cpp/tools/commands/row_query.cc +++ b/cpp/tools/commands/row_query.cc @@ -44,7 +44,8 @@ class CliFullMatchTagRegExp : public storage::TagFilter { CliFullMatchTagRegExp(int col_idx, const std::string& pattern) : storage::TagFilter(col_idx, pattern), pattern_(pattern) {} - bool satisfyRow(std::vector segments) const override { + bool satisfyRow( + const std::vector& segments) const override { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr) { return false; } From 8953440767a350d1aefce660bbf8704fdd2ea420 Mon Sep 17 00:00:00 2001 From: Colin Lee Date: Tue, 1 Dec 2026 14:31:29 +0800 Subject: [PATCH 2/4] style(cpp): apply clang-format and add license header to .clang-tidy --- cpp/.clang-tidy | 17 +++++++++++++++++ cpp/src/common/allocator/mem_alloc.cc | 3 +-- cpp/src/common/allocator/page_arena.h | 3 ++- cpp/src/common/device_id.cc | 7 +++---- cpp/src/common/tablet.cc | 7 ++++--- cpp/src/common/tsfile_common.cc | 3 ++- cpp/src/common/tsfile_common.h | 3 +-- cpp/src/cwrapper/tsfile_cwrapper.cc | 3 ++- cpp/src/encoding/chimp_decoder.h | 2 +- cpp/src/file/tsfile_io_reader.cc | 18 +++++++++--------- cpp/src/file/tsfile_io_reader.h | 9 +++++---- cpp/src/reader/aligned_chunk_reader.cc | 6 ++++-- cpp/src/reader/chunk_reader.cc | 6 ++++-- cpp/src/reader/filter/aligned_field_filter.cc | 6 ++---- cpp/src/reader/filter/aligned_field_filter.h | 3 ++- cpp/src/reader/filter/filter_type.h | 3 +-- cpp/src/reader/filter/tag_filter.cc | 6 ++++-- cpp/src/reader/task/device_task_iterator.h | 5 ++--- cpp/src/reader/tsfile_series_scan_iterator.cc | 3 ++- 19 files changed, 68 insertions(+), 45 deletions(-) diff --git a/cpp/.clang-tidy b/cpp/.clang-tidy index cb7e2c4c6c..b118351b92 100644 --- a/cpp/.clang-tidy +++ b/cpp/.clang-tidy @@ -1,3 +1,20 @@ +# 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. diff --git a/cpp/src/common/allocator/mem_alloc.cc b/cpp/src/common/allocator/mem_alloc.cc index 233851526f..c8091c3948 100644 --- a/cpp/src/common/allocator/mem_alloc.cc +++ b/cpp/src/common/allocator/mem_alloc.cc @@ -231,8 +231,7 @@ void ModStat::print_stat() { double kb = total / 1024.0; double mb = kb / 1024.0; std::cout << " TOTAL: " << total << " bytes / " << std::fixed - << std::setprecision(2) << kb << " KB / " << mb << " MB" - << '\n'; + << std::setprecision(2) << kb << " KB / " << mb << " MB" << '\n'; std::cout << "=========================" << '\n'; } diff --git a/cpp/src/common/allocator/page_arena.h b/cpp/src/common/allocator/page_arena.h index ed38d6584b..804c44563b 100644 --- a/cpp/src/common/allocator/page_arena.h +++ b/cpp/src/common/allocator/page_arena.h @@ -89,7 +89,8 @@ class PageArena { // pessimizes aliasing analysis). const uintptr_t misalignment = reinterpret_cast(cur_alloc_) & (alignment - 1); - const uintptr_t padding = (alignment - misalignment) & (alignment - 1); + const uintptr_t padding = + (alignment - misalignment) & (alignment - 1); char* ret = cur_alloc_ + padding; if (ret + size > page_end_) { return nullptr; diff --git a/cpp/src/common/device_id.cc b/cpp/src/common/device_id.cc index b3e4a1b069..6e096ebc52 100644 --- a/cpp/src/common/device_id.cc +++ b/cpp/src/common/device_id.cc @@ -235,10 +235,9 @@ std::vector StringArrayDeviceID::split_device_id_string( if (segment_cnt == 1) { // "root" -> {"root"} final_segments.push_back(splits[0]); - } else if (segment_cnt < - static_cast( - storage::DEFAULT_SEGMENT_NUM_FOR_TABLE_NAME) + - 1) { + } else if (segment_cnt < static_cast( + storage::DEFAULT_SEGMENT_NUM_FOR_TABLE_NAME) + + 1) { // "root.a" -> {"root", "a"} // "root.a.b" -> {"root.a", "b"} std::string table_name = std::accumulate( diff --git a/cpp/src/common/tablet.cc b/cpp/src/common/tablet.cc index 5d9e035ce7..d234e61d6f 100644 --- a/cpp/src/common/tablet.cc +++ b/cpp/src/common/tablet.cc @@ -531,9 +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, - // Signature must match the primary template (T val). - std::string val) { // NOLINT(performance-unnecessary-value-param) +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)); } diff --git a/cpp/src/common/tsfile_common.cc b/cpp/src/common/tsfile_common.cc index bc6a54007a..524c9d5874 100644 --- a/cpp/src/common/tsfile_common.cc +++ b/cpp/src/common/tsfile_common.cc @@ -173,7 +173,8 @@ int TSMIterator::get_next(std::shared_ptr& ret_device_id, ret_ts_index.finish(); } if (UNLIKELY(ret_device_id == nullptr)) { - ret = E_TSFILE_WRITER_META_ERR; // NOLINT(clang-analyzer-deadcode.DeadStores) + ret = + E_TSFILE_WRITER_META_ERR; // NOLINT(clang-analyzer-deadcode.DeadStores) // log_err("null device name from chunk_group_meta_iter, ret=%d", ret); ASSERT(false); } diff --git a/cpp/src/common/tsfile_common.h b/cpp/src/common/tsfile_common.h index 4eaf802767..3392e30e2e 100644 --- a/cpp/src/common/tsfile_common.h +++ b/cpp/src/common/tsfile_common.h @@ -1160,8 +1160,7 @@ struct MetaIndexNode { FORCE_INLINE bool is_empty() const { return children_.size() == 0; } - FORCE_INLINE int push_entry( - const std::shared_ptr& entry) { + FORCE_INLINE int push_entry(const std::shared_ptr& entry) { #if DEBUG_SE std::cout << "MetaIndexNode.push_entry(" << *entry << ")" << std::endl; #endif diff --git a/cpp/src/cwrapper/tsfile_cwrapper.cc b/cpp/src/cwrapper/tsfile_cwrapper.cc index 5f5025d2a0..34995996e4 100644 --- a/cpp/src/cwrapper/tsfile_cwrapper.cc +++ b/cpp/src/cwrapper/tsfile_cwrapper.cc @@ -2055,7 +2055,8 @@ ERRNO populate_c_metadata_map_from_cpp( // slot stays below timeseries_count: the array is sized // by the non-null count and incremented once per entry. TimeseriesMetadata& m = - e.timeseries[slot]; // NOLINT(clang-analyzer-security.ArrayBound) + e.timeseries + [slot]; // NOLINT(clang-analyzer-security.ArrayBound) common::String mn = idx->get_measurement_name(); m.measurement_name = strdup(mn.to_std_string().c_str()); if (m.measurement_name == nullptr) { diff --git a/cpp/src/encoding/chimp_decoder.h b/cpp/src/encoding/chimp_decoder.h index 80aff3f706..6f1c26b862 100644 --- a/cpp/src/encoding/chimp_decoder.h +++ b/cpp/src/encoding/chimp_decoder.h @@ -33,7 +33,7 @@ namespace storage { static constexpr uint8_t CHIMP_LEADING_DECODING[8] = {0, 8, 12, 16, - 18, 20, 22, 24}; + 18, 20, 22, 24}; template class ChimpDecoder : public Decoder { diff --git a/cpp/src/file/tsfile_io_reader.cc b/cpp/src/file/tsfile_io_reader.cc index ff351fccac..635b002914 100644 --- a/cpp/src/file/tsfile_io_reader.cc +++ b/cpp/src/file/tsfile_io_reader.cc @@ -677,9 +677,9 @@ std::string TsFileIOReader::device_node_cache_key( return key; } -int TsFileIOReader::get_cached_device_node(const std::shared_ptr& device_id, - common::PageArena& pa, - CachedDeviceNode& out) { +int TsFileIOReader::get_cached_device_node( + const std::shared_ptr& device_id, common::PageArena& pa, + CachedDeviceNode& out) { (void)pa; std::string dev_name = device_node_cache_key(device_id); @@ -757,8 +757,8 @@ int TsFileIOReader::get_cached_device_node(const std::shared_ptr& dev } int TsFileIOReader::load_timeseries_index_for_ssi( - const std::shared_ptr& device_id, const std::string& measurement_name, - TsFileSeriesScanIterator*& ssi) { + const std::shared_ptr& device_id, + const std::string& measurement_name, TsFileSeriesScanIterator*& ssi) { int ret = E_OK; auto& pa = ssi->timeseries_index_pa_; @@ -1199,12 +1199,12 @@ int TsFileIOReader::search_from_internal_node( } if (cur_level.node->node_type_ == LEAF_DEVICE) { return cur_level.node->binary_search_children( - target_name, /*exact_search=*/true, ret_index_entry, ret_end_offset, - output_pa); + target_name, /*exact_search=*/true, ret_index_entry, + ret_end_offset, output_pa); } else if (cur_level.node->node_type_ == LEAF_MEASUREMENT) { return cur_level.node->binary_search_children( - target_name, /*exact_search=*/false, ret_index_entry, ret_end_offset, - output_pa); + target_name, /*exact_search=*/false, ret_index_entry, + ret_end_offset, output_pa); } else { ret = cur_level.node->binary_search_children( target_name, /*exact_search=*/false, index_entry, end_offset, diff --git a/cpp/src/file/tsfile_io_reader.h b/cpp/src/file/tsfile_io_reader.h index c16a02695b..1a71014a3c 100644 --- a/cpp/src/file/tsfile_io_reader.h +++ b/cpp/src/file/tsfile_io_reader.h @@ -184,7 +184,8 @@ class TsFileIOReader { std::vector, int64_t>>& ret_measurement_index_entry); - bool is_aligned_device(const std::shared_ptr& measurement_node); + bool is_aligned_device( + const std::shared_ptr& measurement_node); int get_time_column_metadata( const std::shared_ptr& measurement_node, @@ -210,9 +211,9 @@ class TsFileIOReader { int64_t start_offset, int64_t end_offset, common::PageArena& pa, std::vector& ts_indexs); - int load_timeseries_index_for_ssi(const std::shared_ptr& device_id, - const std::string& measurement_name, - TsFileSeriesScanIterator*& ssi); + int load_timeseries_index_for_ssi( + const std::shared_ptr& device_id, + const std::string& measurement_name, TsFileSeriesScanIterator*& ssi); int search_from_leaf_node(const std::shared_ptr& target_name, const std::shared_ptr& index_node, diff --git a/cpp/src/reader/aligned_chunk_reader.cc b/cpp/src/reader/aligned_chunk_reader.cc index 4556f69307..c222862c94 100644 --- a/cpp/src/reader/aligned_chunk_reader.cc +++ b/cpp/src/reader/aligned_chunk_reader.cc @@ -599,7 +599,8 @@ int AlignedChunkReader::decode_cur_time_page_data() { #endif if (ret != E_OK || time_uncompressed_buf_size != cur_time_page_header_.uncompressed_size_) { - ret = E_TSFILE_CORRUPTED; // NOLINT(clang-analyzer-deadcode.DeadStores) + ret = + E_TSFILE_CORRUPTED; // NOLINT(clang-analyzer-deadcode.DeadStores) ASSERT(false); } } @@ -663,7 +664,8 @@ int AlignedChunkReader::decode_cur_value_page_data() { #endif if (ret != E_OK || value_uncompressed_buf_size != cur_value_page_header_.uncompressed_size_) { - ret = E_TSFILE_CORRUPTED; // NOLINT(clang-analyzer-deadcode.DeadStores) + ret = + E_TSFILE_CORRUPTED; // NOLINT(clang-analyzer-deadcode.DeadStores) ASSERT(false); } } diff --git a/cpp/src/reader/chunk_reader.cc b/cpp/src/reader/chunk_reader.cc index 5066aa8040..ea6d0c214a 100644 --- a/cpp/src/reader/chunk_reader.cc +++ b/cpp/src/reader/chunk_reader.cc @@ -355,7 +355,8 @@ int ChunkReader::decode_cur_page_data(TsBlock*& ret_tsblock, Filter* filter, // uncompressed_buf, uncompressed_buf_size); if (ret != E_OK || uncompressed_buf_size != cur_page_header_.uncompressed_size_) { - ret = E_TSFILE_CORRUPTED; // NOLINT(clang-analyzer-deadcode.DeadStores) + ret = + E_TSFILE_CORRUPTED; // NOLINT(clang-analyzer-deadcode.DeadStores) ASSERT(false); } } @@ -378,7 +379,8 @@ int ChunkReader::decode_cur_page_data(TsBlock*& ret_tsblock, Filter* filter, << ", time_buf_size=" << time_buf_size << std::endl; #endif if (uncompressed_buf_size <= var_size + time_buf_size) { - ret = E_TSFILE_CORRUPTED; // NOLINT(clang-analyzer-deadcode.DeadStores) + ret = + E_TSFILE_CORRUPTED; // NOLINT(clang-analyzer-deadcode.DeadStores) ASSERT(false); } } diff --git a/cpp/src/reader/filter/aligned_field_filter.cc b/cpp/src/reader/filter/aligned_field_filter.cc index 3f66cd3844..7d738ff5a7 100644 --- a/cpp/src/reader/filter/aligned_field_filter.cc +++ b/cpp/src/reader/filter/aligned_field_filter.cc @@ -286,8 +286,7 @@ AlignedFieldFilter::AlignedFieldFilter(Kind kind, std::string column, AlignedFieldFilter::AlignedFieldFilter(Kind kind, Ptr left, Ptr right) : kind_(kind), left_(std::move(left)), right_(std::move(right)) {} -AlignedFieldFilter::Ptr AlignedFieldFilter::compare( - const std::string& column, +AlignedFieldFilter::Ptr AlignedFieldFilter::compare(const std::string& column, CompareOp op, Literal literal) { return Ptr(new AlignedFieldFilter(Kind::COMPARISON, @@ -295,8 +294,7 @@ AlignedFieldFilter::Ptr AlignedFieldFilter::compare( std::move(literal))); } -AlignedFieldFilter::Ptr AlignedFieldFilter::is_null( - const std::string& column) { +AlignedFieldFilter::Ptr AlignedFieldFilter::is_null(const std::string& column) { return Ptr(new AlignedFieldFilter(Kind::IS_NULL, normalize_column_name(column), CompareOp::EQ, Literal())); diff --git a/cpp/src/reader/filter/aligned_field_filter.h b/cpp/src/reader/filter/aligned_field_filter.h index 90991ea28f..318bdd84cd 100644 --- a/cpp/src/reader/filter/aligned_field_filter.h +++ b/cpp/src/reader/filter/aligned_field_filter.h @@ -78,7 +78,8 @@ class AlignedFieldFilter : public Filter { ~AlignedFieldFilter() override = default; - static Ptr compare(const std::string& column, CompareOp op, Literal literal); + static Ptr compare(const std::string& column, CompareOp op, + Literal literal); static Ptr is_null(const std::string& column); static Ptr is_not_null(const std::string& column); // Logical operands must be non-null. A missing operand remains an invalid diff --git a/cpp/src/reader/filter/filter_type.h b/cpp/src/reader/filter/filter_type.h index 41c66eee5c..1dd123a04f 100644 --- a/cpp/src/reader/filter/filter_type.h +++ b/cpp/src/reader/filter/filter_type.h @@ -39,8 +39,7 @@ FORCE_INLINE std::string filter_type_to_string(FilterType type) { return std::string("group by"); } default: { - std::cout << "filter_type_to_string unknown type:" << type - << '\n'; + std::cout << "filter_type_to_string unknown type:" << type << '\n'; return ""; } } diff --git a/cpp/src/reader/filter/tag_filter.cc b/cpp/src/reader/filter/tag_filter.cc index 9436d81367..c99316bca4 100644 --- a/cpp/src/reader/filter/tag_filter.cc +++ b/cpp/src/reader/filter/tag_filter.cc @@ -30,7 +30,8 @@ TagFilter::TagFilter(int col_idx, std::string tag_value) TagFilter::~TagFilter() = default; -bool TagFilter::satisfyRow(int time, const std::vector& segments) const { +bool TagFilter::satisfyRow(int time, + const std::vector& segments) const { return satisfyRow(segments); } @@ -180,7 +181,8 @@ TagNotBetween::TagNotBetween(int col_idx, std::string lower_value, value2_ = std::move(upper_value); } -bool TagNotBetween::satisfyRow(const std::vector& segments) const { +bool TagNotBetween::satisfyRow( + const std::vector& segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr) return false; const std::string& segment_value = *segments[col_idx_]; diff --git a/cpp/src/reader/task/device_task_iterator.h b/cpp/src/reader/task/device_task_iterator.h index db74d3c343..1faaadc3f5 100644 --- a/cpp/src/reader/task/device_task_iterator.h +++ b/cpp/src/reader/task/device_task_iterator.h @@ -52,9 +52,8 @@ class DeviceTaskIterator { std::shared_ptr table_schema) : column_names_(std::move(column_names)), column_mapping_(std::move(column_mapping)), - device_meta_iterator_( - metadata_querier->device_iterator(std::move(index_roots), - id_filter)), + device_meta_iterator_(metadata_querier->device_iterator( + std::move(index_roots), id_filter)), table_schema_(std::move(table_schema)) { pa_.init(512, common::MOD_DEVICE_TASK_ITER); } diff --git a/cpp/src/reader/tsfile_series_scan_iterator.cc b/cpp/src/reader/tsfile_series_scan_iterator.cc index a88b974ea9..e6a7c56f9b 100644 --- a/cpp/src/reader/tsfile_series_scan_iterator.cc +++ b/cpp/src/reader/tsfile_series_scan_iterator.cc @@ -286,7 +286,8 @@ int TsFileSeriesScanIterator::get_next(TsBlock*& ret_tsblock, bool alloc, if (!chunk_reader_->has_more_data() || force_load_next_chunk) { // Defensive reset; the flag is only re-read through the outer // condition after being set again below. - force_load_next_chunk = false; // NOLINT(clang-analyzer-deadcode.DeadStores) + force_load_next_chunk = + false; // NOLINT(clang-analyzer-deadcode.DeadStores) while (true) { if (!has_next_chunk()) { return E_NO_MORE_DATA; From 67ede9ef6d69a3d1ffa0e50e676636e309d90fd1 Mon Sep 17 00:00:00 2001 From: Colin Lee Date: Tue, 1 Dec 2026 15:34:41 +0800 Subject: [PATCH 3/4] style(cpp): keep clang-tidy suppressors on wrapped statements --- cpp/src/common/tsfile_common.cc | 4 ++-- cpp/src/cwrapper/tsfile_cwrapper.cc | 5 ++--- cpp/src/reader/aligned_chunk_reader.cc | 8 ++++---- cpp/src/reader/chunk_reader.cc | 8 ++++---- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/cpp/src/common/tsfile_common.cc b/cpp/src/common/tsfile_common.cc index 524c9d5874..62de7c1000 100644 --- a/cpp/src/common/tsfile_common.cc +++ b/cpp/src/common/tsfile_common.cc @@ -173,8 +173,8 @@ int TSMIterator::get_next(std::shared_ptr& ret_device_id, ret_ts_index.finish(); } if (UNLIKELY(ret_device_id == nullptr)) { - ret = - E_TSFILE_WRITER_META_ERR; // NOLINT(clang-analyzer-deadcode.DeadStores) + // 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); } diff --git a/cpp/src/cwrapper/tsfile_cwrapper.cc b/cpp/src/cwrapper/tsfile_cwrapper.cc index 34995996e4..9672ff3b40 100644 --- a/cpp/src/cwrapper/tsfile_cwrapper.cc +++ b/cpp/src/cwrapper/tsfile_cwrapper.cc @@ -2054,9 +2054,8 @@ ERRNO populate_c_metadata_map_from_cpp( } // slot stays below timeseries_count: the array is sized // by the non-null count and incremented once per entry. - TimeseriesMetadata& m = - e.timeseries - [slot]; // NOLINT(clang-analyzer-security.ArrayBound) + // 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()); if (m.measurement_name == nullptr) { diff --git a/cpp/src/reader/aligned_chunk_reader.cc b/cpp/src/reader/aligned_chunk_reader.cc index c222862c94..1c8e747d45 100644 --- a/cpp/src/reader/aligned_chunk_reader.cc +++ b/cpp/src/reader/aligned_chunk_reader.cc @@ -599,8 +599,8 @@ int AlignedChunkReader::decode_cur_time_page_data() { #endif if (ret != E_OK || time_uncompressed_buf_size != cur_time_page_header_.uncompressed_size_) { - ret = - E_TSFILE_CORRUPTED; // NOLINT(clang-analyzer-deadcode.DeadStores) + // NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores) + ret = E_TSFILE_CORRUPTED; ASSERT(false); } } @@ -664,8 +664,8 @@ int AlignedChunkReader::decode_cur_value_page_data() { #endif if (ret != E_OK || value_uncompressed_buf_size != cur_value_page_header_.uncompressed_size_) { - ret = - E_TSFILE_CORRUPTED; // NOLINT(clang-analyzer-deadcode.DeadStores) + // NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores) + ret = E_TSFILE_CORRUPTED; ASSERT(false); } } diff --git a/cpp/src/reader/chunk_reader.cc b/cpp/src/reader/chunk_reader.cc index ea6d0c214a..6aac8586a9 100644 --- a/cpp/src/reader/chunk_reader.cc +++ b/cpp/src/reader/chunk_reader.cc @@ -355,8 +355,8 @@ int ChunkReader::decode_cur_page_data(TsBlock*& ret_tsblock, Filter* filter, // uncompressed_buf, uncompressed_buf_size); if (ret != E_OK || uncompressed_buf_size != cur_page_header_.uncompressed_size_) { - ret = - E_TSFILE_CORRUPTED; // NOLINT(clang-analyzer-deadcode.DeadStores) + // NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores) + ret = E_TSFILE_CORRUPTED; ASSERT(false); } } @@ -379,8 +379,8 @@ int ChunkReader::decode_cur_page_data(TsBlock*& ret_tsblock, Filter* filter, << ", time_buf_size=" << time_buf_size << std::endl; #endif if (uncompressed_buf_size <= var_size + time_buf_size) { - ret = - E_TSFILE_CORRUPTED; // NOLINT(clang-analyzer-deadcode.DeadStores) + // NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores) + ret = E_TSFILE_CORRUPTED; ASSERT(false); } } From a31705bf6cd1d9dd8b60f93c6ad9db0eca798ba7 Mon Sep 17 00:00:00 2001 From: Colin Lee Date: Tue, 1 Dec 2026 17:11:50 +0800 Subject: [PATCH 4/4] fix(cpp): address review feedback on ABI and error paths - keep by-value parameters on exported entry points and virtual overrides so the installed headers and shared-library ABI stay unchanged; internal helpers still take const references - tsfile_io_writer: remove the success-only assertion so a failed bloom-filter insert propagates instead of aborting debug builds - restorable writer: release the pending chunk group's device reference before returning on OOM --- cpp/src/common/tsfile_common.cc | 8 ++-- cpp/src/common/tsfile_common.h | 4 +- cpp/src/file/restorable_tsfile_io_writer.cc | 8 ++++ cpp/src/file/tsfile_io_reader.cc | 35 +++++++++------- cpp/src/file/tsfile_io_reader.h | 12 +++--- cpp/src/file/tsfile_io_writer.cc | 7 +++- cpp/src/file/tsfile_io_writer.h | 2 +- cpp/src/reader/filter/aligned_field_filter.cc | 13 +++--- cpp/src/reader/filter/aligned_field_filter.h | 7 ++-- cpp/src/reader/filter/filter.h | 6 ++- cpp/src/reader/filter/tag_filter.cc | 41 ++++++++++--------- cpp/src/reader/filter/tag_filter.h | 34 +++++++-------- cpp/src/reader/tsfile_reader.cc | 5 ++- cpp/src/reader/tsfile_reader.h | 2 +- cpp/src/writer/tsfile_tree_writer.cc | 3 +- cpp/src/writer/tsfile_tree_writer.h | 2 +- cpp/tools/commands/row_query.cc | 4 +- 17 files changed, 111 insertions(+), 82 deletions(-) diff --git a/cpp/src/common/tsfile_common.cc b/cpp/src/common/tsfile_common.cc index 62de7c1000..05ebc8736a 100644 --- a/cpp/src/common/tsfile_common.cc +++ b/cpp/src/common/tsfile_common.cc @@ -384,15 +384,17 @@ int TsFileMeta::deserialize_from(common::ByteStream& in) { /* ================ MetaIndexNode ================ */ int MetaIndexNode::binary_search_children( - const std::shared_ptr& key, bool exact_search, + // NOLINTNEXTLINE(performance-unnecessary-value-param) // public ABI + std::shared_ptr key, bool exact_search, std::shared_ptr& 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( - const std::shared_ptr& key, bool exact_search, + // NOLINTNEXTLINE(performance-unnecessary-value-param) // public ABI + std::shared_ptr key, bool exact_search, std::shared_ptr& ret_index_entry, int64_t& ret_end_offset, common::PageArena& result_pa) { #if DEBUG_SE diff --git a/cpp/src/common/tsfile_common.h b/cpp/src/common/tsfile_common.h index 3392e30e2e..a61f1b845a 100644 --- a/cpp/src/common/tsfile_common.h +++ b/cpp/src/common/tsfile_common.h @@ -1014,14 +1014,14 @@ struct MetaIndexNode { } int binary_search_children( - const std::shared_ptr& key, bool exact_search, + std::shared_ptr key, bool exact_search, std::shared_ptr& ret_index_entry, int64_t& ret_end_offset); // Lookup copies can outlive the source node but must not accumulate in a // cached node's arena. The caller keeps result_pa alive with the result. int binary_search_children( - const std::shared_ptr& key, bool exact_search, + std::shared_ptr key, bool exact_search, std::shared_ptr& ret_index_entry, int64_t& ret_end_offset, common::PageArena& result_pa); diff --git a/cpp/src/file/restorable_tsfile_io_writer.cc b/cpp/src/file/restorable_tsfile_io_writer.cc index ff011a356a..7d931450a8 100644 --- a/cpp/src/file/restorable_tsfile_io_writer.cc +++ b/cpp/src/file/restorable_tsfile_io_writer.cc @@ -829,6 +829,14 @@ int RestorableTsFileIOWriter::self_check(bool truncate_corrupted) { // recovered below, but an allocation failure is not corruption: surface // it instead of silently returning a recovered writer. if (ret == common::E_OOM) { + // The pending chunk group lives in the self-check arena and was + // never registered for cleanup. Release its device reference + // before the arena is torn down without running destructors. + if (cur_cgm != nullptr) { + cur_cgm->device_id_.reset(); + cur_cgm = nullptr; + } + cur_device_id.reset(); reader.close(); return ret; } diff --git a/cpp/src/file/tsfile_io_reader.cc b/cpp/src/file/tsfile_io_reader.cc index 635b002914..2b5fffb048 100644 --- a/cpp/src/file/tsfile_io_reader.cc +++ b/cpp/src/file/tsfile_io_reader.cc @@ -86,19 +86,20 @@ void TsFileIOReader::reset() { } } -int TsFileIOReader::alloc_ssi(const std::shared_ptr& device_id, - const std::string& measurement_name, - TsFileSeriesScanIterator*& ssi, - common::PageArena& pa, Filter* time_filter) { - return alloc_ssi(device_id, measurement_name, ssi, pa, time_filter, - nullptr); +int TsFileIOReader::alloc_ssi( + // NOLINTNEXTLINE(performance-unnecessary-value-param) // public ABI + std::shared_ptr device_id, const std::string& measurement_name, + TsFileSeriesScanIterator*& ssi, common::PageArena& pa, + Filter* time_filter) { + return alloc_ssi(std::move(device_id), measurement_name, ssi, pa, + time_filter, nullptr); } -int TsFileIOReader::alloc_ssi(const std::shared_ptr& device_id, - const std::string& measurement_name, - TsFileSeriesScanIterator*& ssi, - common::PageArena& pa, Filter* time_filter, - common::TSDataType* out_series_type) { +int TsFileIOReader::alloc_ssi( + // NOLINTNEXTLINE(performance-unnecessary-value-param) // public ABI + std::shared_ptr device_id, const std::string& measurement_name, + TsFileSeriesScanIterator*& ssi, common::PageArena& pa, Filter* time_filter, + common::TSDataType* out_series_type) { int ret = E_OK; if (RET_FAIL(load_tsfile_meta_if_necessary())) { } else if (!bloom_filter_contains(device_id->get_device_name(), @@ -339,7 +340,8 @@ int TsFileIOReader::alloc_prepared_multi_ssi( } int TsFileIOReader::alloc_multi_ssi( - const std::shared_ptr& device_id, + // NOLINTNEXTLINE(performance-unnecessary-value-param) // public ABI + std::shared_ptr device_id, const std::vector& measurement_names, TsFileSeriesScanIterator*& ssi, common::PageArena& pa, Filter* time_filter, AlignedFieldFilter* field_filter) { @@ -450,7 +452,8 @@ void TsFileIOReader::revert_ssi(TsFileSeriesScanIterator* ssi) { } int TsFileIOReader::get_device_timeseries_meta_without_chunk_meta( - const std::shared_ptr& device_id, + // NOLINTNEXTLINE(performance-unnecessary-value-param) // public ABI + std::shared_ptr device_id, std::vector& timeseries_indexs, PageArena& pa) { int ret = E_OK; if (RET_FAIL(load_tsfile_meta_if_necessary())) { @@ -811,7 +814,8 @@ int TsFileIOReader::load_timeseries_index_for_ssi( } int TsFileIOReader::load_device_index_entry( - const std::shared_ptr& device_name, + // NOLINTNEXTLINE(performance-unnecessary-value-param) // public ABI + std::shared_ptr device_name, std::shared_ptr& device_index_entry, int64_t& end_offset) { int ret = E_OK; std::shared_ptr device_id_comparable = @@ -942,7 +946,8 @@ int TsFileIOReader::read_device_meta_index(int64_t start_offset, } int TsFileIOReader::get_timeseries_indexes( - const std::shared_ptr& device_id, + // NOLINTNEXTLINE(performance-unnecessary-value-param) // public ABI + std::shared_ptr device_id, const std::unordered_set& measurement_names, std::vector& timeseries_indexs, common::PageArena& pa) { int ret = E_OK; diff --git a/cpp/src/file/tsfile_io_reader.h b/cpp/src/file/tsfile_io_reader.h index 1a71014a3c..fbf890245f 100644 --- a/cpp/src/file/tsfile_io_reader.h +++ b/cpp/src/file/tsfile_io_reader.h @@ -84,7 +84,7 @@ class TsFileIOReader { // Backward-compatible overload for callers compiled against the // previous signature; forwards a null series-type out-param. - int alloc_ssi(const std::shared_ptr& device_id, + int alloc_ssi(std::shared_ptr device_id, const std::string& measurement_name, TsFileSeriesScanIterator*& ssi, common::PageArena& pa, Filter* time_filter = nullptr); @@ -92,12 +92,12 @@ class TsFileIOReader { // out_series_type when the series exists but has no data in the query // range. The final argument is required to keep overload resolution // unambiguous with the overload above. - int alloc_ssi(const std::shared_ptr& device_id, + int alloc_ssi(std::shared_ptr device_id, const std::string& measurement_name, TsFileSeriesScanIterator*& ssi, common::PageArena& pa, Filter* time_filter, common::TSDataType* out_series_type); - int alloc_multi_ssi(const std::shared_ptr& device_id, + int alloc_multi_ssi(std::shared_ptr device_id, const std::vector& measurement_names, TsFileSeriesScanIterator*& ssi, common::PageArena& pa, Filter* time_filter = nullptr, @@ -141,7 +141,7 @@ class TsFileIOReader { } int get_device_timeseries_meta_without_chunk_meta( - const std::shared_ptr& device_id, + std::shared_ptr device_id, std::vector& timeseries_indexs, common::PageArena& pa); @@ -151,7 +151,7 @@ class TsFileIOReader { common::PageArena& pa, MetaIndexNode*& device_meta_index, bool leaf); int get_timeseries_indexes( - const std::shared_ptr& device_id, + std::shared_ptr device_id, const std::unordered_set& measurement_names, std::vector& timeseries_indexs, common::PageArena& pa); @@ -162,7 +162,7 @@ class TsFileIOReader { common::PageArena& pa); int load_device_index_entry( - const std::shared_ptr& target_name, + std::shared_ptr target_name, std::shared_ptr& device_index_entry, int64_t& end_offset); diff --git a/cpp/src/file/tsfile_io_writer.cc b/cpp/src/file/tsfile_io_writer.cc index 2d5712d8a7..7c08ea40f8 100644 --- a/cpp/src/file/tsfile_io_writer.cc +++ b/cpp/src/file/tsfile_io_writer.cc @@ -164,7 +164,8 @@ int TsFileIOWriter::start_file() { } int TsFileIOWriter::start_flush_chunk_group( - const std::shared_ptr& device_name, bool is_aligned) { + // NOLINTNEXTLINE(performance-unnecessary-value-param) // public ABI + std::shared_ptr device_name, bool is_aligned) { int ret = write_byte(CHUNK_GROUP_HEADER_MARKER); if (ret != common::E_OK) { return ret; @@ -487,7 +488,9 @@ int TsFileIOWriter::write_file_index() { if (ret == E_NO_MORE_DATA) { ret = E_OK; } - ASSERT(ret == E_OK); + // A non-OK value here is a propagated failure (for example a failed + // bloom-filter allocation); the guarded finalization below skips + // itself and the error is returned to the caller. if (IS_SUCC(ret) && cur_index_node != nullptr && cur_index_node_queue != nullptr) { // iter finish ASSERT(cur_index_node != nullptr); diff --git a/cpp/src/file/tsfile_io_writer.h b/cpp/src/file/tsfile_io_writer.h index 1fc460a093..c203151579 100644 --- a/cpp/src/file/tsfile_io_writer.h +++ b/cpp/src/file/tsfile_io_writer.h @@ -100,7 +100,7 @@ class TsFileIOWriter { int add_tsfile_property(const std::string& key, const std::vector& value); int start_file(); - int start_flush_chunk_group(const std::shared_ptr& device_id, + int start_flush_chunk_group(std::shared_ptr device_id, bool is_aligned = false); int start_flush_chunk(common::ByteStream& chunk_data, common::ColumnSchema& col_schema, diff --git a/cpp/src/reader/filter/aligned_field_filter.cc b/cpp/src/reader/filter/aligned_field_filter.cc index 7d738ff5a7..1ee4b8cbbe 100644 --- a/cpp/src/reader/filter/aligned_field_filter.cc +++ b/cpp/src/reader/filter/aligned_field_filter.cc @@ -286,22 +286,25 @@ AlignedFieldFilter::AlignedFieldFilter(Kind kind, std::string column, AlignedFieldFilter::AlignedFieldFilter(Kind kind, Ptr left, Ptr right) : kind_(kind), left_(std::move(left)), right_(std::move(right)) {} -AlignedFieldFilter::Ptr AlignedFieldFilter::compare(const std::string& column, - CompareOp op, - Literal literal) { +AlignedFieldFilter::Ptr AlignedFieldFilter::compare( + // NOLINTNEXTLINE(performance-unnecessary-value-param) // public ABI + std::string column, CompareOp op, Literal literal) { return Ptr(new AlignedFieldFilter(Kind::COMPARISON, normalize_column_name(column), op, std::move(literal))); } -AlignedFieldFilter::Ptr AlignedFieldFilter::is_null(const std::string& column) { +AlignedFieldFilter::Ptr AlignedFieldFilter::is_null( + // NOLINTNEXTLINE(performance-unnecessary-value-param) // public ABI + std::string column) { return Ptr(new AlignedFieldFilter(Kind::IS_NULL, normalize_column_name(column), CompareOp::EQ, Literal())); } AlignedFieldFilter::Ptr AlignedFieldFilter::is_not_null( - const std::string& column) { + // NOLINTNEXTLINE(performance-unnecessary-value-param) // public ABI + std::string column) { return Ptr(new AlignedFieldFilter(Kind::IS_NOT_NULL, normalize_column_name(column), CompareOp::EQ, Literal())); diff --git a/cpp/src/reader/filter/aligned_field_filter.h b/cpp/src/reader/filter/aligned_field_filter.h index 318bdd84cd..659d165b28 100644 --- a/cpp/src/reader/filter/aligned_field_filter.h +++ b/cpp/src/reader/filter/aligned_field_filter.h @@ -78,10 +78,9 @@ class AlignedFieldFilter : public Filter { ~AlignedFieldFilter() override = default; - static Ptr compare(const std::string& column, CompareOp op, - Literal literal); - static Ptr is_null(const std::string& column); - static Ptr is_not_null(const std::string& column); + static Ptr compare(std::string column, CompareOp op, Literal literal); + static Ptr is_null(std::string column); + static Ptr is_not_null(std::string column); // Logical operands must be non-null. A missing operand remains an invalid // non-null tree, rejected with E_INVALID_ARG when bound or queried. static Ptr and_filter(Ptr left, Ptr right); diff --git a/cpp/src/reader/filter/filter.h b/cpp/src/reader/filter/filter.h index 85ba223460..b67f598223 100644 --- a/cpp/src/reader/filter/filter.h +++ b/cpp/src/reader/filter/filter.h @@ -54,11 +54,15 @@ class Filter { ASSERT(false); return false; } + // By-value keeps the virtual interface ABI-compatible: changing the + // parameter type would alter the vtable and every override's symbol. + // NOLINTBEGIN(performance-unnecessary-value-param) virtual bool satisfyRow(int time, - const std::vector& segments) const { + std::vector segments) const { ASSERT(false); return false; } + // NOLINTEND(performance-unnecessary-value-param) virtual std::vector* get_time_ranges() { ASSERT(false); return nullptr; diff --git a/cpp/src/reader/filter/tag_filter.cc b/cpp/src/reader/filter/tag_filter.cc index c99316bca4..867f10a667 100644 --- a/cpp/src/reader/filter/tag_filter.cc +++ b/cpp/src/reader/filter/tag_filter.cc @@ -24,18 +24,20 @@ namespace storage { +// By-value parameters keep the tag-filter virtual interface ABI-compatible. +// NOLINTBEGIN(performance-unnecessary-value-param) + // TagFilter base class implementation TagFilter::TagFilter(int col_idx, std::string tag_value) : value_(std::move(tag_value)), value2_(""), col_idx_(col_idx) {} TagFilter::~TagFilter() = default; -bool TagFilter::satisfyRow(int time, - const std::vector& segments) const { +bool TagFilter::satisfyRow(int time, std::vector segments) const { return satisfyRow(segments); } -bool TagFilter::satisfyRow(const std::vector& segments) const { +bool TagFilter::satisfyRow(std::vector segments) const { ASSERT(false); return false; } @@ -44,7 +46,7 @@ bool TagFilter::satisfyRow(const std::vector& segments) const { TagEq::TagEq(int col_idx, std::string tag_value) : TagFilter(col_idx, std::move(tag_value)) {} -bool TagEq::satisfyRow(const std::vector& segments) const { +bool TagEq::satisfyRow(std::vector segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr) return false; return *segments[col_idx_] == value_; @@ -54,7 +56,7 @@ bool TagEq::satisfyRow(const std::vector& segments) const { TagNeq::TagNeq(int col_idx, std::string tag_value) : TagFilter(col_idx, std::move(tag_value)) {} -bool TagNeq::satisfyRow(const std::vector& segments) const { +bool TagNeq::satisfyRow(std::vector segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr) return false; return *segments[col_idx_] != value_; @@ -64,7 +66,7 @@ bool TagNeq::satisfyRow(const std::vector& segments) const { TagLt::TagLt(int col_idx, std::string tag_value) : TagFilter(col_idx, std::move(tag_value)) {} -bool TagLt::satisfyRow(const std::vector& segments) const { +bool TagLt::satisfyRow(std::vector segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr) return false; return *segments[col_idx_] < value_; @@ -74,7 +76,7 @@ bool TagLt::satisfyRow(const std::vector& segments) const { TagLteq::TagLteq(int col_idx, std::string tag_value) : TagFilter(col_idx, std::move(tag_value)) {} -bool TagLteq::satisfyRow(const std::vector& segments) const { +bool TagLteq::satisfyRow(std::vector segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr) return false; return *segments[col_idx_] <= value_; @@ -84,7 +86,7 @@ bool TagLteq::satisfyRow(const std::vector& segments) const { TagGt::TagGt(int col_idx, std::string tag_value) : TagFilter(col_idx, std::move(tag_value)) {} -bool TagGt::satisfyRow(const std::vector& segments) const { +bool TagGt::satisfyRow(std::vector segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr) return false; return *segments[col_idx_] > value_; @@ -94,7 +96,7 @@ bool TagGt::satisfyRow(const std::vector& segments) const { TagGteq::TagGteq(int col_idx, std::string tag_value) : TagFilter(col_idx, std::move(tag_value)) {} -bool TagGteq::satisfyRow(const std::vector& segments) const { +bool TagGteq::satisfyRow(std::vector segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr) return false; return *segments[col_idx_] >= value_; @@ -111,7 +113,7 @@ TagRegExp::TagRegExp(int col_idx, std::string tag_value) } } -bool TagRegExp::satisfyRow(const std::vector& segments) const { +bool TagRegExp::satisfyRow(std::vector segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr || !is_valid_pattern_) return false; @@ -133,7 +135,7 @@ TagNotRegExp::TagNotRegExp(int col_idx, std::string tag_value) } } -bool TagNotRegExp::satisfyRow(const std::vector& segments) const { +bool TagNotRegExp::satisfyRow(std::vector segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr || !is_valid_pattern_) return false; @@ -147,7 +149,7 @@ bool TagNotRegExp::satisfyRow(const std::vector& segments) const { // TagIsNull implementation TagIsNull::TagIsNull(int col_idx) : TagFilter(col_idx, "") {} -bool TagIsNull::satisfyRow(const std::vector& segments) const { +bool TagIsNull::satisfyRow(std::vector segments) const { // A tag is null when its segment is an explicit null pointer or when the // device id omits the (trailing) segment entirely. return col_idx_ >= segments.size() || segments[col_idx_] == nullptr; @@ -156,7 +158,7 @@ bool TagIsNull::satisfyRow(const std::vector& segments) const { // TagIsNotNull implementation TagIsNotNull::TagIsNotNull(int col_idx) : TagFilter(col_idx, "") {} -bool TagIsNotNull::satisfyRow(const std::vector& segments) const { +bool TagIsNotNull::satisfyRow(std::vector segments) const { return col_idx_ < segments.size() && segments[col_idx_] != nullptr; } @@ -167,7 +169,7 @@ TagBetween::TagBetween(int col_idx, std::string lower_value, value2_ = std::move(upper_value); } -bool TagBetween::satisfyRow(const std::vector& segments) const { +bool TagBetween::satisfyRow(std::vector segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr) return false; const std::string& segment_value = *segments[col_idx_]; @@ -181,8 +183,7 @@ TagNotBetween::TagNotBetween(int col_idx, std::string lower_value, value2_ = std::move(upper_value); } -bool TagNotBetween::satisfyRow( - const std::vector& segments) const { +bool TagNotBetween::satisfyRow(std::vector segments) const { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr) return false; const std::string& segment_value = *segments[col_idx_]; @@ -198,7 +199,7 @@ TagAnd::~TagAnd() { delete right_; } -bool TagAnd::satisfyRow(const std::vector& segments) const { +bool TagAnd::satisfyRow(std::vector segments) const { return left_->satisfyRow(segments) && right_->satisfyRow(segments); } @@ -211,7 +212,7 @@ TagOr::~TagOr() { delete right_; } -bool TagOr::satisfyRow(const std::vector& segments) const { +bool TagOr::satisfyRow(std::vector segments) const { return left_->satisfyRow(segments) || right_->satisfyRow(segments); } @@ -220,7 +221,7 @@ TagNot::TagNot(TagFilter* filter) : TagFilter(-1, ""), filter_(filter) {} TagNot::~TagNot() { delete filter_; } -bool TagNot::satisfyRow(const std::vector& segments) const { +bool TagNot::satisfyRow(std::vector segments) const { return !filter_->satisfyRow(segments); } @@ -334,4 +335,6 @@ int TagFilterBuilder::get_tag_column_index(const std::string& columnName) { return idColumnOrder + 1; } +// NOLINTEND(performance-unnecessary-value-param) + } // namespace storage \ No newline at end of file diff --git a/cpp/src/reader/filter/tag_filter.h b/cpp/src/reader/filter/tag_filter.h index 12da736fa1..50c750d441 100644 --- a/cpp/src/reader/filter/tag_filter.h +++ b/cpp/src/reader/filter/tag_filter.h @@ -36,8 +36,8 @@ class TagFilter : public Filter { ~TagFilter() override; bool satisfyRow(int time, - const std::vector& segments) const override; - virtual bool satisfyRow(const std::vector& segments) const; + std::vector segments) const override; + virtual bool satisfyRow(std::vector segments) const; std::string value_; std::string value2_; // For range queries @@ -48,42 +48,42 @@ class TagFilter : public Filter { class TagEq : public TagFilter { public: TagEq(int col_idx, std::string tag_value); - bool satisfyRow(const std::vector& segments) const override; + bool satisfyRow(std::vector segments) const override; }; // Inequality comparison class TagNeq : public TagFilter { public: TagNeq(int col_idx, std::string tag_value); - bool satisfyRow(const std::vector& segments) const override; + bool satisfyRow(std::vector segments) const override; }; // Less than comparison class TagLt : public TagFilter { public: TagLt(int col_idx, std::string tag_value); - bool satisfyRow(const std::vector& segments) const override; + bool satisfyRow(std::vector segments) const override; }; // Less than or equal comparison class TagLteq : public TagFilter { public: TagLteq(int col_idx, std::string tag_value); - bool satisfyRow(const std::vector& segments) const override; + bool satisfyRow(std::vector segments) const override; }; // Greater than comparison class TagGt : public TagFilter { public: TagGt(int col_idx, std::string tag_value); - bool satisfyRow(const std::vector& segments) const override; + bool satisfyRow(std::vector segments) const override; }; // Greater than or equal comparison class TagGteq : public TagFilter { public: TagGteq(int col_idx, std::string tag_value); - bool satisfyRow(const std::vector& segments) const override; + bool satisfyRow(std::vector segments) const override; }; // Regular expression match @@ -93,7 +93,7 @@ class TagRegExp : public TagFilter { public: TagRegExp(int col_idx, std::string tag_value); - bool satisfyRow(const std::vector& segments) const override; + bool satisfyRow(std::vector segments) const override; }; // Regular expression not match @@ -103,7 +103,7 @@ class TagNotRegExp : public TagFilter { public: TagNotRegExp(int col_idx, std::string tag_value); - bool satisfyRow(const std::vector& segments) const override; + bool satisfyRow(std::vector segments) const override; }; // IS NULL: tag column has no value for this device. An absent trailing @@ -111,21 +111,21 @@ class TagNotRegExp : public TagFilter { class TagIsNull : public TagFilter { public: explicit TagIsNull(int col_idx); - bool satisfyRow(const std::vector& segments) const override; + bool satisfyRow(std::vector segments) const override; }; // IS NOT NULL: tag column has a concrete value for this device. class TagIsNotNull : public TagFilter { public: explicit TagIsNotNull(int col_idx); - bool satisfyRow(const std::vector& segments) const override; + bool satisfyRow(std::vector segments) const override; }; // Range query [value_, value2_] class TagBetween : public TagFilter { public: TagBetween(int col_idx, std::string lower_value, std::string upper_value); - bool satisfyRow(const std::vector& segments) const override; + bool satisfyRow(std::vector segments) const override; }; // Not in range @@ -133,7 +133,7 @@ class TagNotBetween : public TagFilter { public: TagNotBetween(int col_idx, std::string lower_value, std::string upper_value); - bool satisfyRow(const std::vector& segments) const override; + bool satisfyRow(std::vector segments) const override; }; // Logical AND operation (binary) @@ -141,7 +141,7 @@ class TagAnd : public TagFilter { public: TagAnd(TagFilter* left, TagFilter* right); ~TagAnd() override; - bool satisfyRow(const std::vector& segments) const override; + bool satisfyRow(std::vector segments) const override; private: TagFilter* left_; @@ -153,7 +153,7 @@ class TagOr : public TagFilter { public: TagOr(TagFilter* left, TagFilter* right); ~TagOr() override; - bool satisfyRow(const std::vector& segments) const override; + bool satisfyRow(std::vector segments) const override; private: TagFilter* left_; @@ -165,7 +165,7 @@ class TagNot : public TagFilter { public: explicit TagNot(TagFilter* filter); ~TagNot() override; - bool satisfyRow(const std::vector& segments) const override; + bool satisfyRow(std::vector segments) const override; private: TagFilter* filter_; diff --git a/cpp/src/reader/tsfile_reader.cc b/cpp/src/reader/tsfile_reader.cc index f6256548dc..fb538db6a7 100644 --- a/cpp/src/reader/tsfile_reader.cc +++ b/cpp/src/reader/tsfile_reader.cc @@ -744,7 +744,8 @@ int read_chunk_header_codec(RandomAccessReadFile* read_file, } // namespace int TsFileReader::get_timeseries_schema( - const std::shared_ptr& device_id, + // NOLINTNEXTLINE(performance-unnecessary-value-param) // public ABI + std::shared_ptr device_id, std::vector& result) { int ret = E_OK; std::vector timeseries_indexs; @@ -752,7 +753,7 @@ int TsFileReader::get_timeseries_schema( pa.init(512, MOD_TSFILE_READER); if (RET_FAIL(tsfile_executor_->get_tsfile_io_reader() ->get_device_timeseries_meta_without_chunk_meta( - device_id, timeseries_indexs, pa))) { + std::move(device_id), timeseries_indexs, pa))) { } else { for (auto timeseries_index : timeseries_indexs) { // AlignedTimeseriesIndex::get_data_type() returns the time diff --git a/cpp/src/reader/tsfile_reader.h b/cpp/src/reader/tsfile_reader.h index 06ea1376f7..61aa858c1f 100644 --- a/cpp/src/reader/tsfile_reader.h +++ b/cpp/src/reader/tsfile_reader.h @@ -260,7 +260,7 @@ class TsFileReader { * list * @return Returns 0 on success, or a non-zero error code on failure. */ - int get_timeseries_schema(const std::shared_ptr& device_id, + int get_timeseries_schema(std::shared_ptr device_id, std::vector& result); /** diff --git a/cpp/src/writer/tsfile_tree_writer.cc b/cpp/src/writer/tsfile_tree_writer.cc index 4dc3d94f37..4a5a4e45b8 100644 --- a/cpp/src/writer/tsfile_tree_writer.cc +++ b/cpp/src/writer/tsfile_tree_writer.cc @@ -46,7 +46,8 @@ int TsFileTreeWriter::register_timeseries(std::string& device_id, } int TsFileTreeWriter::register_timeseries( - std::string& device_id, const std::vector& schemas) { + // NOLINTNEXTLINE(performance-unnecessary-value-param) // public ABI + std::string& device_id, std::vector schemas) { return tsfile_writer_->register_aligned_timeseries(device_id, schemas); } diff --git a/cpp/src/writer/tsfile_tree_writer.h b/cpp/src/writer/tsfile_tree_writer.h index bff8172a40..170c06ddcb 100644 --- a/cpp/src/writer/tsfile_tree_writer.h +++ b/cpp/src/writer/tsfile_tree_writer.h @@ -95,7 +95,7 @@ class TsFileTreeWriter { * @return Returns 0 on success, or a non-zero error code on failure. */ int register_timeseries(std::string& device_id, - const std::vector& schemas); + std::vector schemas); /** * Writes a batch of data points (tablet) for one or more time series into diff --git a/cpp/tools/commands/row_query.cc b/cpp/tools/commands/row_query.cc index dc5aaf290b..5954d69ec2 100644 --- a/cpp/tools/commands/row_query.cc +++ b/cpp/tools/commands/row_query.cc @@ -44,8 +44,8 @@ class CliFullMatchTagRegExp : public storage::TagFilter { CliFullMatchTagRegExp(int col_idx, const std::string& pattern) : storage::TagFilter(col_idx, pattern), pattern_(pattern) {} - bool satisfyRow( - const std::vector& segments) const override { + // NOLINTNEXTLINE(performance-unnecessary-value-param) // virtual ABI + bool satisfyRow(std::vector segments) const override { if (col_idx_ >= segments.size() || segments[col_idx_] == nullptr) { return false; }