From babfb5a6e4babb557646e3136f2974efdd900883 Mon Sep 17 00:00:00 2001 From: tsy Date: Thu, 1 Aug 2024 13:51:40 +0800 Subject: [PATCH] [enhancement](err-msg) Add detailed column and schema info when failed to create a column iterator --- be/src/cloud/cloud_schema_change_job.cpp | 10 +++-- be/src/olap/rowset/segment_v2/segment.cpp | 51 +++++++++++------------ 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/be/src/cloud/cloud_schema_change_job.cpp b/be/src/cloud/cloud_schema_change_job.cpp index ed3e5f9433fcfdd..254a0d8d96646f3 100644 --- a/be/src/cloud/cloud_schema_change_job.cpp +++ b/be/src/cloud/cloud_schema_change_job.cpp @@ -283,9 +283,13 @@ Status CloudSchemaChangeJob::_convert_historical_rowsets(const SchemaChangeParam } } - RETURN_IF_ERROR(sc_procedure->process(rs_reader, rowset_writer.get(), _new_tablet, - _base_tablet, _base_tablet_schema, - _new_tablet_schema)); + st = sc_procedure->process(rs_reader, rowset_writer.get(), _new_tablet, _base_tablet, + _base_tablet_schema, _new_tablet_schema); + if (!st.ok()) { + return Status::InternalError( + "failed to process schema change on rowset, version=[{}-{}], status={}", + rs_reader->version().first, rs_reader->version().second, st.to_string()); + } RowsetSharedPtr new_rowset; st = rowset_writer->build(new_rowset); diff --git a/be/src/olap/rowset/segment_v2/segment.cpp b/be/src/olap/rowset/segment_v2/segment.cpp index 0208ed635e1ecaf..33c30a9f98b08a7 100644 --- a/be/src/olap/rowset/segment_v2/segment.cpp +++ b/be/src/olap/rowset/segment_v2/segment.cpp @@ -20,9 +20,8 @@ #include #include #include -#include -#include +#include #include #include @@ -51,17 +50,13 @@ #include "olap/rowset/segment_v2/segment_writer.h" // k_segment_magic_length #include "olap/schema.h" #include "olap/short_key_index.h" -#include "olap/storage_engine.h" #include "olap/tablet_schema.h" #include "olap/types.h" #include "olap/utils.h" -#include "runtime/define_primitive_type.h" #include "runtime/exec_env.h" -#include "runtime/memory/mem_tracker.h" #include "runtime/query_context.h" #include "runtime/runtime_predicate.h" #include "runtime/runtime_state.h" -#include "util/bvar_helper.h" #include "util/coding.h" #include "util/crc32c.h" #include "util/slice.h" // Slice @@ -400,7 +395,7 @@ Status Segment::load_index() { Status Segment::_load_index_impl() { return _load_index_once.call([this] { if (_tablet_schema->keys_type() == UNIQUE_KEYS && _pk_index_meta != nullptr) { - _pk_index_reader.reset(new PrimaryKeyIndexReader()); + _pk_index_reader = std::make_unique(); RETURN_IF_ERROR(_pk_index_reader->parse_index(_file_reader, *_pk_index_meta)); // _meta_mem_usage += _pk_index_reader->get_memory_size(); return Status::OK(); @@ -425,7 +420,7 @@ Status Segment::_load_index_impl() { DCHECK(footer.has_short_key_page_footer()); // _meta_mem_usage += body.get_size(); - _sk_index_decoder.reset(new ShortKeyIndexDecoder); + _sk_index_decoder = std::make_unique(); return _sk_index_decoder->parse(body, footer.short_key_page_footer()); } }); @@ -437,8 +432,8 @@ vectorized::DataTypePtr Segment::get_data_type_of(vectorized::PathInDataPtr path bool ignore_children) const { // Path has higher priority if (path != nullptr && !path->empty()) { - auto node = _sub_column_tree.find_leaf(*path); - auto sparse_node = _sparse_column_tree.find_exact(*path); + const auto* node = _sub_column_tree.find_leaf(*path); + const auto* sparse_node = _sparse_column_tree.find_exact(*path); if (node) { if (ignore_children || (node->children.empty() && sparse_node == nullptr)) { return node->data.file_column_type; @@ -466,7 +461,7 @@ Status Segment::_create_column_readers(const SegmentFooterPB& footer) { std::unordered_map column_path_to_footer_ordinal; for (uint32_t ordinal = 0; ordinal < footer.columns().size(); ++ordinal) { - auto& column_pb = footer.columns(ordinal); + const auto& column_pb = footer.columns(ordinal); // column path for accessing subcolumns of variant if (column_pb.has_column_path_info()) { vectorized::PathInData path; @@ -481,7 +476,7 @@ Status Segment::_create_column_readers(const SegmentFooterPB& footer) { } // init by unique_id for (uint32_t ordinal = 0; ordinal < _tablet_schema->num_columns(); ++ordinal) { - auto& column = _tablet_schema->column(ordinal); + const auto& column = _tablet_schema->column(ordinal); auto iter = column_id_to_footer_ordinal.find(column.unique_id()); if (iter == column_id_to_footer_ordinal.end()) { continue; @@ -498,7 +493,7 @@ Status Segment::_create_column_readers(const SegmentFooterPB& footer) { // init by column path for (uint32_t ordinal = 0; ordinal < _tablet_schema->num_columns(); ++ordinal) { - auto& column = _tablet_schema->column(ordinal); + const auto& column = _tablet_schema->column(ordinal); if (!column.has_path_info()) { continue; } @@ -521,7 +516,7 @@ Status Segment::_create_column_readers(const SegmentFooterPB& footer) { vectorized::DataTypeFactory::instance().create_data_type(column_pb)}); // init sparse columns paths and type info for (uint32_t ordinal = 0; ordinal < column_pb.sparse_columns().size(); ++ordinal) { - auto& spase_column_pb = column_pb.sparse_columns(ordinal); + const auto& spase_column_pb = column_pb.sparse_columns(ordinal); if (spase_column_pb.has_column_path_info()) { vectorized::PathInData path; path.from_protobuf(spase_column_pb.column_path_info()); @@ -541,7 +536,10 @@ Status Segment::_create_column_readers(const SegmentFooterPB& footer) { static Status new_default_iterator(const TabletColumn& tablet_column, std::unique_ptr* iter) { if (!tablet_column.has_default_value() && !tablet_column.is_nullable()) { - return Status::InternalError("invalid nonexistent column without default value."); + return Status::InternalError( + "invalid nonexistent column without default value. column_uid={}, column_name={}, " + "column_type={}", + tablet_column.unique_id(), tablet_column.name(), tablet_column.type()); } auto type_info = get_type_info(&tablet_column); std::unique_ptr default_value_iter(new DefaultValueColumnIterator( @@ -561,7 +559,7 @@ Status Segment::_new_iterator_with_variant_root(const TabletColumn& tablet_colum vectorized::DataTypePtr target_type_hint) { ColumnIterator* it; RETURN_IF_ERROR(root->data.reader->new_iterator(&it)); - auto stream_iter = new ExtractReader( + auto* stream_iter = new ExtractReader( tablet_column, std::make_unique(root->data.file_column_type->create_column(), std::unique_ptr(it), @@ -581,13 +579,14 @@ Status Segment::new_column_iterator_with_path(const TabletColumn& tablet_column, } else { root_path = vectorized::PathInData({tablet_column.path_info_ptr()->get_parts()[0]}); } - auto root = _sub_column_tree.find_leaf(root_path); - auto node = tablet_column.has_path_info() - ? _sub_column_tree.find_exact(*tablet_column.path_info_ptr()) - : nullptr; - auto sparse_node = tablet_column.has_path_info() - ? _sparse_column_tree.find_exact(*tablet_column.path_info_ptr()) + const auto* root = _sub_column_tree.find_leaf(root_path); + const auto* node = tablet_column.has_path_info() + ? _sub_column_tree.find_exact(*tablet_column.path_info_ptr()) : nullptr; + const auto* sparse_node = + tablet_column.has_path_info() + ? _sparse_column_tree.find_exact(*tablet_column.path_info_ptr()) + : nullptr; // Currently only compaction and checksum need to read flat leaves // They both use tablet_schema_with_merged_max_schema_version as read schema @@ -666,7 +665,7 @@ Status Segment::new_column_iterator(const TabletColumn& tablet_column, return new_column_iterator_with_path(tablet_column, iter, opt); } // init default iterator - if (_column_readers.count(tablet_column.unique_id()) < 1) { + if (!_column_readers.contains(tablet_column.unique_id())) { RETURN_IF_ERROR(new_default_iterator(tablet_column, iter)); return Status::OK(); } @@ -698,7 +697,7 @@ Status Segment::new_column_iterator(int32_t unique_id, std::unique_ptrdata.reader.get(); @@ -706,7 +705,7 @@ ColumnReader* Segment::_get_column_reader(const TabletColumn& col) { return nullptr; } auto col_unique_id = col.unique_id(); - if (_column_readers.count(col_unique_id) > 0) { + if (_column_readers.contains(col_unique_id)) { return _column_readers[col_unique_id].get(); } return nullptr; @@ -823,7 +822,7 @@ Status Segment::lookup_row_key(const Slice& key, bool with_seq_col, bool with_ro sought_key.get_data() + sought_key_without_seq.get_size() + seq_col_length + 1, rowid_length - 1); const auto* type_info = get_scalar_type_info(); - auto rowid_coder = get_key_coder(type_info->type()); + const auto* rowid_coder = get_key_coder(type_info->type()); RETURN_IF_ERROR(rowid_coder->decode_ascending(&rowid_slice, rowid_length, (uint8_t*)&row_location->row_id)); }