Skip to content

Rename Shard tasks_to_run_next_round_ to low_priority_ready_tasks_#302

Merged
xiexiaoy merged 5 commits intomainfrom
low_pq
Jan 22, 2026
Merged

Rename Shard tasks_to_run_next_round_ to low_priority_ready_tasks_#302
xiexiaoy merged 5 commits intomainfrom
low_pq

Conversation

@xiexiaoy
Copy link
Collaborator

@xiexiaoy xiexiaoy commented Jan 20, 2026

By renaming Shard::tasks_to_run_next_round_ to Shard::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_writes is removed to allow concurrent batchwrite.

Summary by CodeRabbit

  • New Features

    • Added high-precision timing to improve task processing measurements.
  • Refactor

    • Background work now yields to a low-priority queue to reduce interference with foreground tasks.
    • Simplified write queuing by removing the configurable concurrent-write limit.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 20, 2026

Walkthrough

Renames 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

Cohort / File(s) Summary
Configuration & Options Removal
include/kv_options.h, src/kv_options.cpp
Removed uint32_t max_concurrent_writes from KvOptions; removed INI parsing and equality comparison logic for that field.
Task / Yield API
include/tasks/task.h, src/tasks/task.cpp
Renamed YieldToNextRound()YieldToLowPQ(); enqueue destination changed from tasks_to_run_next_round_ to low_priority_ready_tasks_.
Shard timing & queue management
include/storage/shard.h, src/storage/shard.cpp
Added TSC/CNTVCT timing helpers and static frequency state (InitializeTscFrequency(), ReadTimeMicroseconds(), DurationMicroseconds(), tsc_frequency_initialized_, tsc_cycles_per_microsecond_); renamed queue to low_priority_ready_tasks_; ExecuteReadyTasks() enforces a time budget.
Yield call-site updates
src/file_gc.cpp, src/storage/page_mapper.cpp, src/storage/root_meta.cpp, src/tasks/background_write.cpp, src/tasks/write_task.cpp
Replaced calls to YieldToNextRound() with YieldToLowPQ() across GC, mapping, compaction, and write paths.

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
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly Related PRs

Suggested Reviewers

  • thweetkomputer
  • eatbreads

Poem

🐇 I hopped from round to low-priority queues,
I traded ticks for tiny timed views,
I queued my task with a twitch and a bow,
The shard keeps time — I pause, then I plow,
A rabbit’s dance in code and muse.

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the main objectives but is missing required documentation from the template checklist. Most required sections are not addressed. Complete the PR description template by adding checkboxes for tests, documentation, issue references, RFC links, and confirming ctest passes.
Docstring Coverage ⚠️ Warning Docstring coverage is 8.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the primary structural change across the codebase: renaming the tasks queue and related method from YieldToNextRound to YieldToLowPQ, which is the main refactoring.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch low_pq

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@CLAassistant
Copy link

CLAassistant commented Jan 20, 2026

CLA assistant check
All committers have signed the CLA.

@xiexiaoy xiexiaoy force-pushed the low_pq branch 6 times, most recently from d701ac8 to 669176b Compare January 22, 2026 07:13
@xiexiaoy xiexiaoy marked this pull request as ready for review January 22, 2026 07:14
@xiexiaoy xiexiaoy requested a review from liunyl January 22, 2026 07:18
@xiexiaoy xiexiaoy linked an issue Jan 22, 2026 that may be closed by this pull request
{
KvTask *task = tasks_to_run_next_round_.Peek();
tasks_to_run_next_round_.Dequeue();
KvTask *task = low_priority_ready_tasks_.Peek();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is low prio tasks re-enqueued to ready tasks?

while (tasks_to_run_next_round_.Size() > 0)

uint64_t delta_us = DurationMicroseconds(start_us_fast);
while (delta_us < MAX_PROCESSING_TIME_MICROSECONDS &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should allow at least 1 low prio task to be executed per round.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make MAX_PROCESSING_TIME_MICROSECONDS a brpc flag

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Do not use namespace using-directives. Use using-declarations instead. [build/namespaces] [5]

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +793 to +806
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;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

@xiexiaoy xiexiaoy merged commit ce2cd44 into main Jan 22, 2026
4 checks passed
@xiexiaoy xiexiaoy deleted the low_pq branch January 22, 2026 09:56
@coderabbitai coderabbitai bot mentioned this pull request Feb 13, 2026
5 tasks
@coderabbitai coderabbitai bot mentioned this pull request Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Remove limitation of cloud task from write task

3 participants