Skip to content

Commit 9b52531

Browse files
committed
fix: DList timeout=0 means wait indefinitely
When timeout is 0, treat it as no timeout (wait forever) instead of using a deadline that has already passed. This allows callers to distinguish between "wait with timeout" and "wait without timeout". Signed-off-by: Shawn Wang <shawn.wang@zilliz.com>
1 parent 310bd55 commit 9b52531

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

include/cachinglayer/lrucache/DList.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ class DList : public std::enable_shared_from_this<DList> {
106106
IsEmpty() const;
107107

108108
// Reserve loading resource with timeout, called before loading a cell.
109+
// When timeout > 0, the request will fail after the specified duration.
110+
// When timeout == 0, the request will wait indefinitely (no timeout).
111+
// Note: timeout=0 requests use time_point::max() as their deadline, which
112+
// means they sort after all finite-deadline requests in the waiting queue.
109113
folly::SemiFuture<bool>
110114
ReserveLoadingResourceWithTimeout(const ResourceUsage& size, std::chrono::milliseconds timeout,
111115
OpContext* ctx = nullptr);

src/cachinglayer/lrucache/DList.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ DList::ReserveLoadingResourceWithTimeout(const ResourceUsage& original_size, std
5858
// If immediate reservation fails, add to waiting queue
5959
std::unique_lock<std::mutex> lock(list_mtx_);
6060

61-
auto deadline = std::chrono::steady_clock::now() + timeout;
61+
auto deadline =
62+
timeout.count() > 0 ? std::chrono::steady_clock::now() + timeout : std::chrono::steady_clock::time_point::max();
6263
auto [promise, future] = folly::makePromiseContract<bool>();
6364

6465
uint64_t request_id = next_request_id_.fetch_add(1);

0 commit comments

Comments
 (0)