Skip to content

DRAFT: Convert upsert IO pattern from sender-receiver to fiber based#2019

Draft
kkuehlz wants to merge 3 commits intomainfrom
kkuehler/fiberize_upsert
Draft

DRAFT: Convert upsert IO pattern from sender-receiver to fiber based#2019
kkuehlz wants to merge 3 commits intomainfrom
kkuehler/fiberize_upsert

Conversation

@kkuehlz
Copy link
Contributor

@kkuehlz kkuehlz commented Jan 14, 2026

No description provided.

kkuehlz and others added 3 commits January 14, 2026 10:46
Introduces a Boost.Fiber scheduler that integrates with AsyncIO's
io_uring polling. This enables fibers to yield while waiting for
io_uring completions and be resumed when the operation completes.

Key components:
- CompletionToken: A struct with a magic number that distinguishes
  fiber completions from sender-receiver operations in the CQE
- UringFiberScheduler: A fiber scheduler that polls io_uring during
  suspend_until, enabling cooperative multitasking with IO
- poll_uring_ extension: Detects fiber completions via magic number
  and schedules the waiting fiber for resumption

The scheduler is installed in the rwdb worker thread, preparing the
infrastructure for fiberizing the upsert path.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Convert the upsert and copy_trie code paths from callback-based async IO
to fiber-based synchronous-style IO. This eliminates the complex
`node_receiver_t` callback machinery and sender-receiver node writers in
favor of simpler `fiber_read_node()` and `FiberWriteBuffer` patterns.

Key changes:
- Add `submit_fiber_read` and `submit_fiber_write` to AsyncIO with proper
  inflight tracking for poll_uring_ to find completions
- Add `is_write` field to CompletionToken to track operation type for
  correct inflight counter decrement on completion
- Add `FiberWriteBuffer` class that accumulates writes and yields on flush
- Replace `node_writer_fast`/`node_writer_slow` sender-receivers with
  `fiber_write_buffer_`/`fiber_write_buffer_slow_`
- Replace `async_read` callbacks with `fiber_read_node` synchronous calls
- Remove `node_receiver_t` template and callback reentrancy handling
- Rename `reset_node_writers()` to `init_disk_growth_tracking()`

The fiber approach allows stack-based continuation instead of callbacks,
making the control flow much easier to follow and maintain.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add fiber context tracking to the buffer pool. When a fiber goes to
sleep waiting for memory, track it in a `waiter_` queue. Once a buffer
is released, notify the first entry in the queue.

The current approach, which is to yield when no memory could be
accessed, is not fiber friendly. Yield will starve the scheduler. We
need to detach the context for that fiber to be removed from the ready
queue.
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.

1 participant