Repository navigation
[feature](be) Admit JNI scanners by the JVM heap their ranges declare, when a session asks #68713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
a59cc4d
8339a3e
1eda26d
8c706e7
2ddaecb
809a410
9f571b3
7bbb3f7
b546e09
45308af
31e97f4
021b1ab
0dcfd28
2cfd3a1
ba7d23b
208e775
863628e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| #include <ctime> | ||
| #include <memory> | ||
| #include <mutex> | ||
| #include <optional> | ||
| #include <ostream> | ||
| #include <shared_mutex> | ||
| #include <tuple> | ||
|
|
@@ -362,6 +363,61 @@ void ScannerContext::push_completed_scan_task(std::shared_ptr<ScanTask> scan_tas | |
| _dependency->set_ready(); | ||
| } | ||
|
|
||
| void ScannerContext::park_scan_task(std::shared_ptr<ScanTask> scan_task, | ||
| SharedListenableFuture<Void> waiting_for) { | ||
| { | ||
| std::unique_lock<std::mutex> l(_transfer_lock); | ||
| scan_task->set_state(ScanTask::State::PARKED); | ||
| _in_flight_tasks_num--; | ||
| ++_parked_tasks_num; | ||
| // The slot it held may now admit a pending scanner - one whose block the operator consumed | ||
| // while this context had no slot to spare, holding what this task waits for, among them. | ||
| // Nothing else would look: a parked task never completes a scan attempt to make the operator | ||
| // schedule again. | ||
| if (!done()) { | ||
| Status status = _scanner_scheduler->schedule_scan_task(shared_from_this(), nullptr, l); | ||
| if (!status.ok()) { | ||
| set_context_failure(status, l); | ||
| } | ||
| } | ||
| } | ||
| std::weak_ptr<ScannerContext> weak_ctx = shared_from_this(); | ||
| // Runs on the thread that completes the future, or right here if it is done already. | ||
| waiting_for.add_callback([weak_ctx, scan_task](const Void&, const Status&) { | ||
| if (auto ctx = weak_ctx.lock()) { | ||
| ctx->_resume_parked_task(scan_task); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| void ScannerContext::_resume_parked_task(const std::shared_ptr<ScanTask>& scan_task) { | ||
| auto task_execution_lock = task_exec_ctx(); | ||
| if (task_execution_lock == nullptr) { | ||
| // The query has finished; nothing will read this task again. | ||
| return; | ||
| } | ||
| #ifndef BE_TEST | ||
| // Scheduling allocates for the query, not for the gate's thread that completed the future. A | ||
| // future done before park_scan_task() added this callback runs it on the worker that parked | ||
| // the task, which is attached to this query already and must stay so. | ||
| std::optional<AttachTask> attach; | ||
| if (!thread_context()->is_attach_task()) { | ||
| attach.emplace(_state); | ||
| } | ||
| #endif | ||
| std::unique_lock<std::mutex> l(_transfer_lock); | ||
| --_parked_tasks_num; | ||
| if (done()) { | ||
| return; | ||
| } | ||
| // Like a task whose block the operator just consumed: it may run again. | ||
| scan_task->set_state(ScanTask::State::PENDING); | ||
| Status status = _scanner_scheduler->schedule_scan_task(shared_from_this(), scan_task, l); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P1] Finish the current scan invocation before resubmitting this parked task. The gate can complete its future before
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not changing this one in this PR. Resubmitting a task before the worker that handed it over has returned is the contract the scan scheduler already has, and the one unsynchronized access in that tail belongs to The handoff. The read.
So I don't see a P1 here, nor anything specific to parking. The fix, |
||
| if (!status.ok()) { | ||
| set_context_failure(status, l); | ||
| } | ||
| } | ||
|
|
||
| Status ScannerContext::get_block_from_queue(RuntimeState* state, Block* block, bool* eos, int id) { | ||
| if (state->is_cancelled()) { | ||
| _set_scanner_done(); | ||
|
|
@@ -553,13 +609,14 @@ std::string ScannerContext::debug_string() { | |
| return fmt::format( | ||
| "_query_id: {}, id: {}, total scanners: {}, pending tasks: {}, completed tasks: {}," | ||
| " _should_stop: {}, _is_finished: {}, free blocks: {}," | ||
| " limit: {}, _in_flight_tasks_num: {}, _is_context_queued: {}, " | ||
| " limit: {}, _in_flight_tasks_num: {}, _parked_tasks_num: {}, _is_context_queued: {}, " | ||
| "_num_finished_scanners: {}, _max_scan_concurrency: {}, expected_scanners: {}," | ||
| " _max_bytes_in_queue: {}, _ins_idx: {}, _enable_adaptive_scanners: {}, " | ||
| "_mem_share_arb: {}, _scanner_mem_limiter: {}", | ||
| print_id(_query_id), ctx_id, _all_scanners.size(), _pending_tasks.size(), | ||
| _completed_tasks.size(), _should_stop, _is_finished, _free_blocks.size_approx(), limit, | ||
| _in_flight_tasks_num, _is_context_queued, _num_finished_scanners, _max_scan_concurrency, | ||
| _in_flight_tasks_num, _parked_tasks_num, _is_context_queued, _num_finished_scanners, | ||
| _max_scan_concurrency, | ||
| _enable_adaptive_scanners ? _adaptive_processor->expected_scanners : -1, | ||
| _max_bytes_in_queue, _ins_idx, _enable_adaptive_scanners, | ||
| _enable_adaptive_scanners ? _mem_share_arb->debug_string() : "NULL", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Validate the heap-gate settings before publishing them. These mutable fields have no validator, and config::strtox accepts values such as
nan,-1, and2. A NaN ratio reaches the floating-to-int64 conversion injvm_heap_budget()(undefined behavior); a ratio above 1 admits more declared bytes than the JVM heap; and a negative or overflowingjni_scanner_heap_max_wait_msmakes_poll()admit waiters immediately or after a wrapped deadline. Require a finite ratio in the intended range and a non-negative wait bounded before nanosecond conversion, then cover invalid dynamic updates.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 863628e. Both configs now have a
DEFINE_Validator, likeinverted_index_candidate_pushdown_ratioandlookup_connection_cache_block_pool_size, whose atomic copies these two already follow:jni_scanner_heap_budget_ratiotakes a finite number from 0 to 1.jvm_heap_budget()no longer sees NaN or infinity, and the budget can no longer exceed the heap. At 0 the declaring readers open one at a time, unless they wait out the limit.jni_scanner_heap_max_wait_mstakes 0 toINT64_MAX / 10^6ms, the most_poll()can count in nanoseconds, soms * 1000 * 1000cannot overflow._poll()compares the time already waited (now - start) with that limit and computes no deadline, so nothing else can wrap.set_config()runs a validator before it persists the value or calls the update callback, so a refused value puts the old one back and never reaches the copy the gate reads. A refused value in be.conf failsconfig::init(), as for every other validated config.JniScanHeapGateTest.SettingsTheGateCannotUseAreRefusedsets both ends of each range, then hasset_config()refusenan,inf,-0.1and1.5for the ratio and-1and9223372036855for the wait, and checks that the gate still reads the last values taken.