Conversation
WalkthroughRenames task yield API to YieldToLowPQ and routes yields to a low-priority queue; removes KvOptions::max_concurrent_writes (INI load and equality checks); and adds Shard TSC/CNTVCT-based timing plus time-bounded processing for low-priority tasks. Changes
Sequence Diagram(s)sequenceDiagram
participant Task as KvTask
participant Shard as Shard
participant Clock as TSC/Clock
participant Queue as low_priority_ready_tasks_
Note over Task,Shard: Yielding and time-bounded resume flow
Task->>Shard: YieldToLowPQ() (enqueue self)
Shard->>Queue: Enqueue(KvTask)
Shard->>Clock: ReadTimeMicroseconds()
Clock-->>Shard: current_us
Shard->>Shard: ExecuteReadyTasks(start_us=current_us)
loop while DurationMicroseconds(start_us) < max_processing_time_microseconds
Shard->>Queue: Dequeue() -> KvTask
Shard-->>Task: Resume task
Shard->>Clock: ReadTimeMicroseconds()
Clock-->>Shard: current_us
end
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly Related PRs
Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
d701ac8 to
669176b
Compare
src/storage/shard.cpp
Outdated
| { | ||
| KvTask *task = tasks_to_run_next_round_.Peek(); | ||
| tasks_to_run_next_round_.Dequeue(); | ||
| KvTask *task = low_priority_ready_tasks_.Peek(); |
There was a problem hiding this comment.
why is low prio tasks re-enqueued to ready tasks?
src/storage/shard.cpp
Outdated
| while (tasks_to_run_next_round_.Size() > 0) | ||
|
|
||
| uint64_t delta_us = DurationMicroseconds(start_us_fast); | ||
| while (delta_us < MAX_PROCESSING_TIME_MICROSECONDS && |
There was a problem hiding this comment.
we should allow at least 1 low prio task to be executed per round.
There was a problem hiding this comment.
Make MAX_PROCESSING_TIME_MICROSECONDS a brpc flag
There was a problem hiding this comment.
we should allow at least 1 low prio task to be executed per round.
Fixed
| return ticks / cycles_per_us; | ||
| #else | ||
| // Fallback to std::chrono (slower but portable and precise) | ||
| using namespace std::chrono; |
There was a problem hiding this comment.
[cpplint] reported by reviewdog 🐶
Do not use namespace using-directives. Use using-declarations instead. [build/namespaces] [5]
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/storage/shard.cpp`:
- Around line 793-806: The DurationMicroseconds implementation misclassifies
end_us == start_us as wraparound; update Shard::DurationMicroseconds to treat
equal timestamps as zero elapsed by changing the comparison to use >= (i.e., if
end_us >= start_us return end_us - start_us) and only return
FLAGS_max_processing_time_microseconds when end_us < start_us (actual
wraparound) so low‑priority work isn't cut prematurely.
| uint64_t Shard::DurationMicroseconds(uint64_t start_us) | ||
| { | ||
| // Check elapsed time (returns microseconds directly) | ||
| uint64_t end_us = ReadTimeMicroseconds(); | ||
| // Handle potential wraparound (unlikely but safe) | ||
| if (end_us > start_us) | ||
| { | ||
| return end_us - start_us; | ||
| } | ||
| else | ||
| { | ||
| // Wraparound detected, use max value to break loop | ||
| return FLAGS_max_processing_time_microseconds; | ||
| } |
There was a problem hiding this comment.
Fix zero‑delta handling in DurationMicroseconds.
When end_us == start_us, the current > check treats it as wraparound, returning the max and prematurely cutting low‑priority work.
🛠️ Proposed fix
- if (end_us > start_us)
+ if (end_us >= start_us)
{
return end_us - start_us;
}🤖 Prompt for AI Agents
In `@src/storage/shard.cpp` around lines 793 - 806, The DurationMicroseconds
implementation misclassifies end_us == start_us as wraparound; update
Shard::DurationMicroseconds to treat equal timestamps as zero elapsed by
changing the comparison to use >= (i.e., if end_us >= start_us return end_us -
start_us) and only return FLAGS_max_processing_time_microseconds when end_us <
start_us (actual wraparound) so low‑priority work isn't cut prematurely.
By renaming
Shard::tasks_to_run_next_round_toShard::low_priority_ready_tasks_and timing for CPU-heavy tasks, eloqstore yields brpc worker to other modules.It should execute at least one CPU-heavy task.
max_concurrent_writesis removed to allow concurrent batchwrite.Summary by CodeRabbit
New Features
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.