kamcheungting-db commented on code in PR #1167: URL: https://github.com/apache/iceberg-cpp/pull/1167#discussion_r4733637871
########## src/iceberg/data/arrow_batch_sizer.cc: ########## @@ -0,0 +1,364 @@ +/* + * 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 <cstddef> +#include <cstdint> +#include <limits> +#include <optional> +#include <string> +#include <string_view> +#include <utility> +#include <vector> + +#include <nanoarrow/nanoarrow.h> + +#include "iceberg/data/arrow_batch_sizer_internal.h" +#include "iceberg/util/macros.h" + +namespace iceberg::internal { + +namespace { + +constexpr int64_t kInt64Max = std::numeric_limits<int64_t>::max(); + +// The number of leading buffers a binary or string view array always has. +constexpr int64_t kBinaryViewFixedBuffers = 2; + +constexpr int64_t kVariadicSizeBytes = static_cast<int64_t>(sizeof(int64_t)); + +bool IsBinaryView(ArrowType type) { + return type == NANOARROW_TYPE_BINARY_VIEW || type == NANOARROW_TYPE_STRING_VIEW; +} + +std::optional<int64_t> CheckedAdd(int64_t lhs, int64_t rhs) { + if (lhs < 0 || rhs < 0 || lhs > kInt64Max - rhs) { + return std::nullopt; + } + return lhs + rhs; +} + +std::optional<int64_t> CheckedMultiply(int64_t lhs, int64_t rhs) { + if (lhs < 0 || rhs < 0) { + return std::nullopt; + } + if (lhs != 0 && rhs > kInt64Max / lhs) { + return std::nullopt; + } + return lhs * rhs; +} + +// Returns whether `bytes` can also be represented as a size_t, which nanoarrow and +// the allocator use for buffer sizes. +bool FitsSizeT(int64_t bytes) { + if constexpr (sizeof(size_t) >= sizeof(int64_t)) { + return bytes >= 0; + } else { + return bytes >= 0 && + static_cast<uint64_t>(bytes) <= std::numeric_limits<size_t>::max(); + } +} + +// The position of a nested array, e.g. "root.1.dictionary". Only formatted when an +// error is reported, so measuring a valid batch does not allocate strings. +class ArrayPath { + public: + static constexpr int64_t kDictionary = -1; + + // Appends a child index (or kDictionary) until the returned scope ends. + class Scope { + public: + Scope(ArrayPath& path, int64_t step) : path_(path) { path_.steps_.push_back(step); } + ~Scope() { path_.steps_.pop_back(); } + Scope(const Scope&) = delete; + Scope& operator=(const Scope&) = delete; + + private: + ArrayPath& path_; + }; + + std::string ToString() const { + std::string result = "root"; + for (int64_t step : steps_) { + result += step == kDictionary ? ".dictionary" : "." + std::to_string(step); + } + return result; + } + + private: + std::vector<int64_t> steps_; +}; + +// Returns the minimum byte size nanoarrow derives for fixed buffer `index` from the +// array's offset and length alone, or std::nullopt when the product overflows. +// Buffers whose size depends on data (for example string data) report zero here. +std::optional<int64_t> LayoutBufferBytes(const ArrowLayout& layout, int index, + int64_t offset_plus_length) { + const int64_t element_size_bits = layout.element_size_bits[index]; + const int64_t element_size_bytes = element_size_bits / 8; + switch (layout.buffer_type[index]) { + case NANOARROW_BUFFER_TYPE_VALIDITY: + return offset_plus_length / 8 + (offset_plus_length % 8 != 0 ? 1 : 0); + case NANOARROW_BUFFER_TYPE_DATA_OFFSET: { + if (offset_plus_length == 0) { + return 0; + } + auto offset_count = CheckedAdd(offset_plus_length, 1); + if (!offset_count.has_value()) { + return std::nullopt; + } + return CheckedMultiply(*offset_count, element_size_bytes); + } + case NANOARROW_BUFFER_TYPE_SIZE: + case NANOARROW_BUFFER_TYPE_VIEW_OFFSET: + case NANOARROW_BUFFER_TYPE_TYPE_ID: + case NANOARROW_BUFFER_TYPE_UNION_OFFSET: + return CheckedMultiply(offset_plus_length, element_size_bytes); + case NANOARROW_BUFFER_TYPE_DATA: { + auto bits = CheckedMultiply(offset_plus_length, element_size_bits); + if (!bits.has_value()) { + return std::nullopt; + } + auto rounded = CheckedAdd(*bits, 7); + if (!rounded.has_value()) { + return std::nullopt; + } + return *rounded / 8; + } + case NANOARROW_BUFFER_TYPE_NONE: + case NANOARROW_BUFFER_TYPE_VARIADIC_DATA: + case NANOARROW_BUFFER_TYPE_VARIADIC_SIZE: + return 0; + } + return std::nullopt; +} + +int FixedBufferCount(const ArrowArrayView& view) { + if (IsBinaryView(view.storage_type)) { + return static_cast<int>(kBinaryViewFixedBuffers); + } + int count = 0; + while (count < NANOARROW_MAX_FIXED_BUFFERS && + view.layout.buffer_type[count] != NANOARROW_BUFFER_TYPE_NONE) { + ++count; + } + return count; +} + +// Checks everything nanoarrow trusts before it sizes buffers: counts used to index +// array members, and every product that it computes without overflow checks. +Status Preflight(const ArrowArrayView& view, const ArrowArray& array, ArrayPath& path) { + switch (view.storage_type) { + case NANOARROW_TYPE_LIST_VIEW: + case NANOARROW_TYPE_LARGE_LIST_VIEW: + case NANOARROW_TYPE_RUN_END_ENCODED: + return NotSupported("Cannot size Arrow {} array at {}: unsupported layout", + ArrowTypeString(view.storage_type), path.ToString()); + default: + break; + } + + if (array.length < 0 || array.offset < 0) { + return InvalidArrowData("Arrow array at {} has negative offset {} or length {}", + path.ToString(), array.offset, array.length); + } + auto offset_plus_length = CheckedAdd(array.offset, array.length); + if (!offset_plus_length.has_value()) { + return InvalidArrowData("Arrow array at {} offset {} plus length {} overflows", + path.ToString(), array.offset, array.length); + } + + const int fixed_buffers = FixedBufferCount(view); + if (IsBinaryView(view.storage_type)) { + // Validity, views, zero or more variadic data buffers, then the size buffer. + if (array.n_buffers < kBinaryViewFixedBuffers + 1) { + return InvalidArrowData("Arrow {} array at {} has {} buffers; expected at least {}", + ArrowTypeString(view.storage_type), path.ToString(), + array.n_buffers, kBinaryViewFixedBuffers + 1); + } + const int64_t variadic_buffers = array.n_buffers - kBinaryViewFixedBuffers - 1; + if (variadic_buffers > std::numeric_limits<int32_t>::max()) { + return InvalidArrowData("Arrow array at {} has too many variadic buffers: {}", + path.ToString(), variadic_buffers); + } + auto size_buffer_bytes = CheckedMultiply(variadic_buffers, kVariadicSizeBytes); + if (!size_buffer_bytes.has_value() || !FitsSizeT(*size_buffer_bytes)) { + return InvalidArrowData("Arrow array at {} variadic size buffer overflows", + path.ToString()); + } + if (array.buffers == nullptr || + (variadic_buffers > 0 && array.buffers[array.n_buffers - 1] == nullptr)) { + return InvalidArrowData("Arrow array at {} is missing its variadic size buffer", + path.ToString()); + } + } else if (array.n_buffers != fixed_buffers) { + return InvalidArrowData("Arrow {} array at {} has {} buffers; expected {}", + ArrowTypeString(view.storage_type), path.ToString(), + array.n_buffers, fixed_buffers); + } + if (array.n_buffers > 0 && array.buffers == nullptr) { + return InvalidArrowData("Arrow array at {} has a null buffer list", path.ToString()); + } + + for (int index = 0; index < fixed_buffers; ++index) { + auto bytes = LayoutBufferBytes(view.layout, index, *offset_plus_length); + if (!bytes.has_value() || !FitsSizeT(*bytes)) { + return InvalidArrowData( + "Arrow {} array at {} buffer {} size overflows for offset {} and length {}", + ArrowTypeString(view.storage_type), path.ToString(), index, array.offset, + array.length); + } + } + + if (view.storage_type == NANOARROW_TYPE_FIXED_SIZE_LIST) { + auto child_length = + CheckedMultiply(*offset_plus_length, view.layout.child_size_elements); + if (!child_length.has_value()) { + return InvalidArrowData( + "Arrow fixed_size_list array at {} child length overflows for offset {}, " + "length {}, and list size {}", + path.ToString(), array.offset, array.length, view.layout.child_size_elements); + } + } + + if (array.n_children != view.n_children) { + return InvalidArrowData("Arrow array at {} has {} children; expected {}", + path.ToString(), array.n_children, view.n_children); + } + if (array.n_children > 0 && array.children == nullptr) { + return InvalidArrowData("Arrow array at {} has a null child list", path.ToString()); + } + for (int64_t index = 0; index < view.n_children; ++index) { + ArrayPath::Scope child(path, index); + if (array.children[index] == nullptr) { + return InvalidArrowData("Arrow array at {} is null", path.ToString()); + } + ICEBERG_RETURN_UNEXPECTED( + Preflight(*view.children[index], *array.children[index], path)); + } + + if ((view.dictionary == nullptr) != (array.dictionary == nullptr)) { + return InvalidArrowData("Arrow array at {} dictionary does not match its schema", + path.ToString()); + } + if (view.dictionary != nullptr) { + ArrayPath::Scope dictionary(path, ArrayPath::kDictionary); + ICEBERG_RETURN_UNEXPECTED(Preflight(*view.dictionary, *array.dictionary, path)); + } + return {}; +} + +// Sums the spans of the buffers that nanoarrow sized for `view`. +Result<int64_t> SumBufferSpans(const ArrowArrayView& view, ArrayPath& path) { + int64_t total = 0; + auto add = [&](int64_t bytes, std::string_view what) -> Status { + if (bytes < 0) { + return NotSupported("Cannot size Arrow {} array at {}: unknown {} size", + ArrowTypeString(view.storage_type), path.ToString(), what); + } + auto sum = CheckedAdd(total, bytes); + if (!sum.has_value() || !FitsSizeT(*sum)) { + return InvalidArrowData("Arrow array at {} buffer sizes overflow", path.ToString()); + } + total = *sum; + return {}; + }; + + const int fixed_buffers = FixedBufferCount(view); Review Comment: new test cases added to cover this part. ########## src/iceberg/data/parallel_scan_reader.cc: ########## @@ -0,0 +1,592 @@ +/* + * 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 "iceberg/data/parallel_scan_reader.h" + +#include <algorithm> +#include <chrono> +#include <condition_variable> +#include <cstdint> +#include <deque> +#include <exception> +#include <format> +#include <memory> +#include <mutex> +#include <optional> +#include <string> +#include <string_view> +#include <thread> +#include <utility> +#include <vector> + +#include <nanoarrow/nanoarrow.h> + +#include "iceberg/arrow_c_data_guard_internal.h" +#include "iceberg/arrow_c_data_util_internal.h" +#include "iceberg/data/arrow_batch_sizer_internal.h" +#include "iceberg/data/parallel_scan_reader_internal.h" +#include "iceberg/file_reader.h" +#include "iceberg/manifest/manifest_entry.h" +#include "iceberg/nanoarrow_status_internal.h" +#include "iceberg/schema.h" +#include "iceberg/schema_internal.h" +#include "iceberg/util/macros.h" + +namespace iceberg { + +namespace internal { + +ParallelScanMetricsSnapshot ParallelScanMetrics::Snapshot() const { + std::lock_guard lock(mutex_); + return snapshot_; +} + +namespace { + +// Names a task in error messages, e.g. "data file s3://b/f.parquet [0, 1024)". +std::string DescribeTask(const FileScanTask& task) { + const auto& data_file = task.data_file(); + if (data_file == nullptr) { + return "task without a data file"; + } + if (!task.is_split()) { + return std::format("data file {}", data_file->file_path); + } + return std::format("data file {} [{}, {})", data_file->file_path, task.start(), + task.start() + task.length()); +} + +Error WithContext(const Error& error, std::string_view context) { + return Error{.kind = error.kind, + .message = std::format("{}: {}", context, error.message)}; +} + +std::string_view NullSafe(const char* value) { + return value == nullptr ? std::string_view{} : std::string_view{value}; +} + +// Compares the physical layout of two Arrow schemas. Field names, formats, +// nullability, children, and dictionaries must match; metadata is ignored and the +// root name is not compared. +Status CheckSameLayout(const ArrowSchema& expected, const ArrowSchema& actual, + const std::string& path, bool compare_name) { + if (NullSafe(expected.format) != NullSafe(actual.format)) { + return InvalidSchema("Field {} has Arrow format '{}', expected '{}'", path, + NullSafe(actual.format), NullSafe(expected.format)); + } + if (compare_name && NullSafe(expected.name) != NullSafe(actual.name)) { + return InvalidSchema("Field {} is named '{}', expected '{}'", path, + NullSafe(actual.name), NullSafe(expected.name)); + } + if ((expected.flags & ARROW_FLAG_NULLABLE) != (actual.flags & ARROW_FLAG_NULLABLE)) { + return InvalidSchema("Field {} nullability differs from the projected schema", path); + } + if (expected.n_children != actual.n_children) { + return InvalidSchema("Field {} has {} children, expected {}", path, actual.n_children, + expected.n_children); + } + for (int64_t index = 0; index < expected.n_children; ++index) { + const ArrowSchema* expected_child = expected.children[index]; + const ArrowSchema* actual_child = actual.children[index]; + if (actual_child == nullptr || expected_child == nullptr) { + return InvalidSchema("Field {} has a null child", path); + } + std::string child_path = std::format("{}.{}", path, NullSafe(expected_child->name)); + ICEBERG_RETURN_UNEXPECTED( + CheckSameLayout(*expected_child, *actual_child, child_path, true)); + } + if ((expected.dictionary == nullptr) != (actual.dictionary == nullptr)) { + return InvalidSchema("Field {} dictionary encoding differs from the projected schema", + path); + } + if (expected.dictionary != nullptr) { + ICEBERG_RETURN_UNEXPECTED(CheckSameLayout(*expected.dictionary, *actual.dictionary, + path + ".dictionary", false)); + } + return {}; +} + +// Releases an ArrowArrayStream on scope exit. +class StreamGuard { + public: + explicit StreamGuard(ArrowArrayStream* stream) : stream_(stream) {} + ~StreamGuard() { + if (stream_->release != nullptr) { + stream_->release(stream_); + } + } + StreamGuard(const StreamGuard&) = delete; + StreamGuard& operator=(const StreamGuard&) = delete; + + private: + ArrowArrayStream* stream_; +}; + +void ReleaseArray(ArrowArray* array) { + if (array->release != nullptr) { + array->release(array); + } +} + +struct QueuedBatch { + ArrowArray array; + int64_t charge; +}; + +void ReleaseAll(std::deque<QueuedBatch>& batches) { + for (auto& batch : batches) { + ReleaseArray(&batch.array); + } + batches.clear(); +} + +// Shared state of one parallel read. All fields below `mutex_` are guarded by it. +// No planning or reader callback, Arrow release callback, thread join, or group +// stream destructor runs while `mutex_` is held. +class ParallelScan { + public: + ParallelScan(FileScanTaskGroupStreamPtr groups, ArrowSchema output_schema, + int64_t max_queued_batches, int64_t max_queued_bytes, + std::shared_ptr<ParallelScanMetrics> metrics) + : groups_(std::move(groups)), + output_schema_(output_schema), + max_queued_batches_(max_queued_batches), + max_queued_bytes_(max_queued_bytes), + metrics_(std::move(metrics)) {} + + ~ParallelScan() { + Shutdown(); + if (output_schema_.release != nullptr) { + output_schema_.release(&output_schema_); + } + } + + ParallelScan(const ParallelScan&) = delete; + ParallelScan& operator=(const ParallelScan&) = delete; + + Status Start(const FileScanTaskReader::Options& reader_options, int32_t worker_count) { + std::vector<std::unique_ptr<FileScanTaskReader>> readers; + std::vector<std::unique_ptr<ArrowBatchSizer>> sizers; + readers.reserve(static_cast<size_t>(worker_count)); + sizers.reserve(static_cast<size_t>(worker_count)); + for (int32_t index = 0; index < worker_count; ++index) { + ICEBERG_ASSIGN_OR_RAISE(auto reader, FileScanTaskReader::Make(reader_options)); + ICEBERG_ASSIGN_OR_RAISE(auto sizer, ArrowBatchSizer::Make(output_schema_)); + readers.push_back(std::move(reader)); + sizers.push_back(std::move(sizer)); + } + + { + std::lock_guard lock(mutex_); + active_workers_ = worker_count; + } + workers_.reserve(static_cast<size_t>(worker_count)); + for (int32_t index = 0; index < worker_count; ++index) { + try { + workers_.emplace_back([this, reader = std::move(readers[index]), + sizer = std::move(sizers[index])]() mutable { + WorkerMain(*reader, *sizer); + }); + } catch (const std::exception& e) { + // Threads that never started will not decrement the active count. + { + std::lock_guard lock(mutex_); + active_workers_ -= worker_count - index; + } + Shutdown(); + return UnknownError("Failed to start parallel scan worker: {}", e.what()); + } + } + return {}; + } + + // Consumer side of get_next. Not called concurrently with itself or Shutdown(). + Result<std::optional<ArrowArray>> Next() { + std::unique_lock lock(mutex_); + consumer_cv_.wait(lock, [this] { + return error_.has_value() || !queue_.empty() || active_workers_ == 0; + }); + if (error_.has_value()) { + return unexpected(*error_); + } + if (queue_.empty()) { + return std::nullopt; + } + QueuedBatch batch = queue_.front(); + queue_.pop_front(); + queued_bytes_ -= batch.charge; + lock.unlock(); + // Producers are admitted in ticket order, and a condition variable cannot wake + // one specific waiter, so wake them all and let the head ticket re-check. At + // most worker_count threads wait here. + producer_cv_.notify_all(); + return batch.array; + } + + Result<ArrowSchema> Schema() const { + ArrowSchema schema{}; + ICEBERG_NANOARROW_RETURN_UNEXPECTED(ArrowSchemaDeepCopy(&output_schema_, &schema)); + return schema; + } + + // Stops new work, joins workers, and releases every batch that was not returned. + // Idempotent. + void Shutdown() { + std::deque<QueuedBatch> drained; + { + std::lock_guard lock(mutex_); + stopped_ = true; + drained.swap(queue_); + queued_bytes_ = 0; + } + planning_cv_.notify_all(); + producer_cv_.notify_all(); + consumer_cv_.notify_all(); + ReleaseAll(drained); + + for (auto& worker : workers_) { + if (worker.joinable()) { + worker.join(); + } + } + workers_.clear(); + + // Workers have exited, so nothing else can enqueue or plan. + { + std::lock_guard lock(mutex_); + drained.swap(queue_); + } + ReleaseAll(drained); + groups_.reset(); + } + + private: + void WorkerMain(FileScanTaskReader& reader, ArrowBatchSizer& sizer) { + Status status; + try { + status = RunWorker(reader, sizer); + } catch (const std::exception& e) { + status = UnknownError("Parallel scan worker failed: {}", e.what()); + } catch (...) { + status = UnknownError("Parallel scan worker failed with an unknown exception"); + } + if (!status.has_value()) { + Fail(status.error()); + } + { + std::lock_guard lock(mutex_); + --active_workers_; + } + consumer_cv_.notify_all(); + } + + Status RunWorker(FileScanTaskReader& reader, ArrowBatchSizer& sizer) { + while (true) { + ICEBERG_ASSIGN_OR_RAISE(auto group, ClaimGroup()); + if (group == nullptr) { + return {}; + } + for (const auto& task : group->tasks()) { + if (IsStopped()) { + return {}; + } + if (task == nullptr) { + return InvalidArgument("Task group contains a null task"); + } + ICEBERG_RETURN_UNEXPECTED(ReadTask(reader, sizer, *task)); + } + } + } + + // Returns the next group, or nullptr when planning is exhausted or the read stopped. + // Only one worker calls the group stream at a time, outside all locks. + Result<std::shared_ptr<FileScanTaskGroup>> ClaimGroup() { + { + std::unique_lock lock(mutex_); + planning_cv_.wait(lock, [this] { return stopped_ || !planning_in_progress_; }); + if (stopped_ || planning_done_) { + return nullptr; + } + planning_in_progress_ = true; + } + + Result<std::optional<std::shared_ptr<FileScanTaskGroup>>> next = std::nullopt; + try { + next = groups_->Next(); + } catch (const std::exception& e) { + next = UnknownError("Planning task groups failed: {}", e.what()); + } catch (...) { + next = UnknownError("Planning task groups failed with an unknown exception"); + } + + const bool finished = !next.has_value() || !next.value().has_value(); + if (finished) { + // This worker still holds the planning token, so no other worker uses the + // stream. Destroy it now, outside locks, so metrics reporting runs at EOF. + groups_.reset(); + } + + { + std::lock_guard lock(mutex_); + planning_in_progress_ = false; + if (finished) { + planning_done_ = true; + } + } + planning_cv_.notify_all(); + + if (!next.has_value()) { + return unexpected(WithContext(next.error(), "Failed to plan task groups")); + } + if (!next.value().has_value()) { + return nullptr; + } + auto group = std::move(next.value().value()); + if (group == nullptr) { + return InvalidArgument("Task group stream returned a null group"); + } + if (metrics_ != nullptr) { + metrics_->Update([](auto& snapshot) { ++snapshot.groups_claimed; }); + } + return group; + } + + Status ReadTask(FileScanTaskReader& reader, ArrowBatchSizer& sizer, + const FileScanTask& task) { + const std::string context = DescribeTask(task); + auto opened = reader.Open(task); + if (!opened.has_value()) { + return unexpected(WithContext(opened.error(), "Failed to open " + context)); + } + ArrowArrayStream stream = std::move(opened.value()); + StreamGuard stream_guard(&stream); + if (metrics_ != nullptr) { + metrics_->Update([](auto& snapshot) { ++snapshot.tasks_opened; }); + } + + auto last_error = [&stream]() { + const char* message = stream.get_last_error(&stream); + return message == nullptr ? std::string("unknown error") : std::string(message); + }; + + ArrowSchema task_schema{}; + if (int code = stream.get_schema(&stream, &task_schema); code != 0) { + return IOError("Failed to read the schema of {} (code {}): {}", context, code, + last_error()); + } + internal::ArrowSchemaGuard task_schema_guard(&task_schema); + if (auto status = CheckSameLayout(output_schema_, task_schema, "root", false); + !status.has_value()) { + return unexpected(WithContext( + status.error(), + "Task stream schema does not match the projected schema for " + context)); + } + + // Enqueue() reports a stop, so no separate check is needed per batch. + while (true) { + ArrowArray batch{}; + if (int code = stream.get_next(&stream, &batch); code != 0) { + return IOError("Failed to read {} (code {}): {}", context, code, last_error()); + } + if (batch.release == nullptr) { + return {}; + } + auto charge = sizer.Measure(batch); + if (!charge.has_value()) { + ReleaseArray(&batch); + return unexpected( + WithContext(charge.error(), "Failed to size a batch of " + context)); + } + if (!Enqueue(batch, charge.value())) { + // Stopped while waiting; the array was not admitted. + ReleaseArray(&batch); + return {}; + } + } + } + + // Blocks until the batch is admitted in FIFO order or the read stops. Returns + // false when stopped, in which case the caller still owns `batch`. + bool Enqueue(const ArrowArray& batch, int64_t charge) { + const auto wait_start = std::chrono::steady_clock::now(); + std::unique_lock lock(mutex_); + const uint64_t ticket = next_ticket_++; + held_bytes_ += charge; + RecordMetrics([this](auto& snapshot) { + snapshot.peak_held_bytes = std::max(snapshot.peak_held_bytes, held_bytes_); + }); + + producer_cv_.wait(lock, [&] { Review Comment: new test cases added to cover this part. -- 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]
