github-actions[bot] commented on code in PR #69761: URL: https://github.com/apache/doris/pull/69761#discussion_r4598841093
########## be/src/storage/segment/variant/v2/variant_values_index_writer.cpp: ########## @@ -0,0 +1,94 @@ +// 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. + +#include "storage/segment/variant/v2/variant_values_index_writer.h" + +#include "common/cast_set.h" +#include "common/exception.h" +#include "core/value/variant/variant_leaf_visitor.h" +#include "storage/index/inverted/snii/snii_index_writer.h" +#include "storage/tablet/tablet_schema.h" + +namespace doris::segment_v2 { + +VariantValuesIndexWriter::VariantValuesIndexWriter(IndexFileWriter* index_file_writer, + const TabletIndex* index_meta, + bool is_direct_load) + : _index_file_writer(index_file_writer), + _index_meta(index_meta), + _is_direct_load(is_direct_load) {} + +VariantValuesIndexWriter::~VariantValuesIndexWriter() { + close_on_error(); +} + +Status VariantValuesIndexWriter::init() { + DORIS_CHECK(_index_file_writer != nullptr); + DORIS_CHECK(_index_meta != nullptr); + DORIS_CHECK(_index_meta->is_variant_values_index()); + _writer = std::make_unique<SniiIndexColumnWriter>(_index_file_writer, _index_meta, + FieldType::OLAP_FIELD_TYPE_VARCHAR); + RETURN_IF_ERROR(_writer->init()); + _writer->set_direct_load(_is_direct_load); + return Status::OK(); +} + +Status VariantValuesIndexWriter::append(const ColumnVariantV2::ReadView& view, size_t begin, + size_t length, std::span<const uint8_t> outer_nulls) { + DORIS_CHECK(_writer != nullptr); + DORIS_CHECK(!view.is_typed()); + DORIS_CHECK_LE(begin + length, view.size()); + DORIS_CHECK(outer_nulls.empty() || outer_nulls.size() == length); + std::vector<Slice> values; + for (size_t row = 0; row < length; ++row) { + _texts.clear(); + values.clear(); + const uint8_t is_null = outer_nulls.empty() ? 0 : outer_nulls[row]; + if (!is_null) { + RETURN_IF_ERROR(for_each_variant_leaf_text(view.value_at(begin + row), + [&](std::string_view text) { + _texts.emplace_back(text); Review Comment: [P2] Account for the values writer's leaf staging buffers A supported VARIANT row containing a million small scalar leaves first copies all of them into `_texts`, then allocates a `Slice` array before SNII consumes any tokens. These standard containers add tens of MiB of headers/slices plus copied string payloads outside Doris memory accounting: the current `jemalloc_hook.cpp` only forwards allocations, and neither this wrapper nor `VariantV2ColumnWriter::estimate_buffer_size()` charges these buffers. `_texts.clear()` also retains the largest vector capacity until segment teardown. Large rows or concurrent flush/compaction writers can therefore exceed their accounted memory while the SNII budget cannot see this staging space. Use tracked storage or explicit capacity reservation/accounting for both containers and owned string bytes, with balanced release on success and error paths. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
