Repository navigation
[feature](lance) Extend WARM UP SELECT with index prewarm (branch-4.2) #69277
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: branch-4.2
Are you sure you want to change the base?
Changes from all commits
9b13343
7a861e1
d594a05
90ed9b4
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 |
|---|---|---|
|
|
@@ -215,6 +215,12 @@ Status LanceSessionManager::_initialize() { | |
|
|
||
| Status LanceSessionManager::open_dataset(const char* uri, const char* const* storage_options, | ||
| uint64_t version, LanceDataset** dataset) { | ||
| return _open_dataset(uri, storage_options, version, dataset, false); | ||
| } | ||
|
|
||
| Status LanceSessionManager::_open_dataset(const char* uri, const char* const* storage_options, | ||
| uint64_t version, LanceDataset** dataset, | ||
| bool redact_errors) { | ||
| if (uri == nullptr || dataset == nullptr) { | ||
| return Status::InvalidArgument("Lance dataset URI and output must not be null"); | ||
| } | ||
|
|
@@ -231,9 +237,46 @@ Status LanceSessionManager::open_dataset(const char* uri, const char* const* sto | |
|
|
||
| *dataset = lance_dataset_open_with_session(uri, storage_options, version, _session); | ||
| if (*dataset == nullptr) { | ||
| // Constructing an SDK error Status can itself log the provider message. Redact before | ||
| // that construction, not only when returning the prewarm RPC response. | ||
| if (redact_errors) { | ||
| return Status::InternalError( | ||
| "Unable to open the pinned Lance snapshot for index prewarm"); | ||
| } | ||
| return lance_error("open Lance dataset with shared session"); | ||
| } | ||
| return Status::OK(); | ||
| } | ||
|
|
||
| Status LanceSessionManager::prewarm_index(const char* uri, const char* const* storage_options, | ||
| uint64_t version, const char* index_name) { | ||
| if (uri == nullptr || *uri == '\0' || version == 0 || index_name == nullptr || | ||
| *index_name == '\0') { | ||
| return Status::InvalidArgument( | ||
| "Lance index prewarm requires URI, index name and a fixed version"); | ||
| } | ||
| // Bound concurrent SDK prewarm IO per BE without blocking all RPC workers behind a mutex. | ||
| // A failed or timed-out caller may retry after the existing SDK operation finishes. | ||
| std::unique_lock lock(_prewarm_mutex, std::try_to_lock); | ||
| if (!lock.owns_lock()) { | ||
| return Status::Cancelled("Another Lance index prewarm is running on this backend"); | ||
| } | ||
| LanceDataset* raw_dataset = nullptr; | ||
| auto status = _open_dataset(uri, storage_options, version, &raw_dataset, true); | ||
| std::unique_ptr<LanceDataset, decltype(&lance_dataset_close)> dataset(raw_dataset, | ||
| lance_dataset_close); | ||
| if (!status.ok()) { | ||
| // SDK storage errors can include credentials or signed URLs. Return operation context only. | ||
| return Status::InternalError("Unable to open the pinned Lance snapshot for index prewarm"); | ||
| } | ||
| if (lance_dataset_version(dataset.get()) != version) { | ||
| return Status::InternalError("Lance index prewarm opened an unexpected snapshot"); | ||
| } | ||
| if (lance_dataset_prewarm_index(dataset.get(), index_name) != 0) { | ||
|
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. [P2] Resolve legacy scalar fields before SDK prewarm On a cold BE, a Lance v0.18.0 BTREE on |
||
| return Status::InternalError( | ||
| "Lance index prewarm failed: index unavailable, unsupported, or storage IO failed"); | ||
| } | ||
| return Status::OK(); | ||
| } | ||
|
|
||
| } // namespace doris::format::lance | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| // 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 <gtest/gtest.h> | ||
|
|
||
| #include <chrono> | ||
| #include <future> | ||
| #include <utility> | ||
|
|
||
| #include "common/config.h" | ||
| #include "load/channel/load_stream_mgr.h" | ||
| #include "runtime/exec_env.h" | ||
| #include "service/internal_service.h" | ||
|
|
||
| namespace doris { | ||
| namespace { | ||
|
|
||
| class PrewarmClosure : public google::protobuf::Closure { | ||
| public: | ||
| void Run() override { completed.set_value(); } | ||
| std::promise<void> completed; | ||
| }; | ||
|
|
||
| class LanceIndexPrewarmServiceTest : public testing::Test { | ||
| protected: | ||
| void SetUp() override { | ||
| auto heavy = std::exchange(config::brpc_heavy_work_pool_threads, 1); | ||
| auto light = std::exchange(config::brpc_light_work_pool_threads, 1); | ||
| auto peer = std::exchange(config::brpc_peer_fetch_pool_threads, 1); | ||
| auto flight = std::exchange(config::brpc_arrow_flight_work_pool_threads, 1); | ||
| auto* env = ExecEnv::GetInstance(); | ||
| previous_load_mgr = std::move(env->_load_stream_mgr); | ||
| env->_load_stream_mgr = std::make_unique<LoadStreamMgr>(1); | ||
| service = std::make_unique<PInternalService>(env); | ||
| config::brpc_heavy_work_pool_threads = heavy; | ||
| config::brpc_light_work_pool_threads = light; | ||
| config::brpc_peer_fetch_pool_threads = peer; | ||
| config::brpc_arrow_flight_work_pool_threads = flight; | ||
| } | ||
|
|
||
| void TearDown() override { | ||
| service.reset(); | ||
| ExecEnv::GetInstance()->_load_stream_mgr = std::move(previous_load_mgr); | ||
| } | ||
|
|
||
| std::unique_ptr<PInternalService> service; | ||
| std::unique_ptr<LoadStreamMgr> previous_load_mgr; | ||
| }; | ||
|
|
||
| TEST_F(LanceIndexPrewarmServiceTest, PrewarmDoesNotUseTheSharedHeavyWorker) { | ||
| std::promise<void> entered; | ||
| std::promise<void> release; | ||
| auto released = release.get_future().share(); | ||
| service->_heavy_work_pool.try_offer([&, released] { | ||
| entered.set_value(); | ||
| released.wait(); | ||
| }); | ||
| entered.get_future().wait(); | ||
| PLanceIndexPrewarmRequest request; | ||
| request.set_timeout_ms(0); | ||
| PLanceIndexPrewarmResponse response; | ||
| PrewarmClosure done; | ||
| auto completed = done.completed.get_future(); | ||
| service->prewarm_lance_index(nullptr, &request, &response, &done); | ||
| auto result = completed.wait_for(std::chrono::seconds(2)); | ||
| release.set_value(); | ||
| completed.wait(); | ||
| EXPECT_EQ(std::future_status::ready, result); | ||
| EXPECT_FALSE(Status::create(response.status()).ok()); | ||
| } | ||
|
|
||
| TEST_F(LanceIndexPrewarmServiceTest, StalledPrewarmHasBoundedAdmissionAndExpiredQueueIsRejected) { | ||
| std::promise<void> entered; | ||
| std::promise<void> release; | ||
| auto released = release.get_future().share(); | ||
| service->_lance_index_prewarm_pool.try_offer([&, released] { | ||
| entered.set_value(); | ||
| released.wait(); | ||
| }); | ||
| entered.get_future().wait(); | ||
| PLanceIndexPrewarmRequest request; | ||
| request.set_timeout_ms(0); | ||
| PLanceIndexPrewarmResponse queued_response; | ||
| PLanceIndexPrewarmResponse rejected_response; | ||
| PrewarmClosure queued_done; | ||
| PrewarmClosure rejected_done; | ||
| auto queued = queued_done.completed.get_future(); | ||
| auto rejected = rejected_done.completed.get_future(); | ||
| service->prewarm_lance_index(nullptr, &request, &queued_response, &queued_done); | ||
| service->prewarm_lance_index(nullptr, &request, &rejected_response, &rejected_done); | ||
| auto rejection = rejected.wait_for(std::chrono::seconds(2)); | ||
|
|
||
| // Stalled native work must not occupy the shared RPC worker or create more prewarm workers. | ||
| std::promise<void> heavy_done; | ||
| service->_heavy_work_pool.try_offer([&] { heavy_done.set_value(); }); | ||
| auto heavy_future = heavy_done.get_future(); | ||
| auto heavy = heavy_future.wait_for(std::chrono::seconds(2)); | ||
| release.set_value(); | ||
| queued.wait(); | ||
| rejected.wait(); | ||
| heavy_future.wait(); | ||
| EXPECT_EQ(std::future_status::ready, rejection); | ||
| EXPECT_EQ(std::future_status::ready, heavy); | ||
| EXPECT_FALSE(Status::create(rejected_response.status()).ok()); | ||
| EXPECT_TRUE(Status::create(queued_response.status()).is<ErrorCode::TIMEOUT>()); | ||
| } | ||
|
|
||
| } // namespace | ||
| } // namespace doris |
Uh oh!
There was an error while loading. Please reload this page.