Skip to content

Fix async writer - #151

Merged
asuiu merged 5 commits into
masterfrom
fix-async-writer
Aug 23, 2025
Merged

Fix async writer#151
asuiu merged 5 commits into
masterfrom
fix-async-writer

Conversation

@asuiu

@asuiu asuiu commented Aug 23, 2025

Copy link
Copy Markdown
Member

No description provided.

ASU added 4 commits August 22, 2025 22:08
@asuiu
asuiu requested a review from amaximciuc August 23, 2025 11:04
@coderabbitai

coderabbitai Bot commented Aug 23, 2025

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added asynchronous, thread-safe streaming writes with optional timeouts via open_write, improving reliability under slow consumers and propagating errors clearly.
  • Refactor

    • Standardized open_write to accept an optional timeout across implementations.
    • MemoryBucket now provides open_write_sync for fast, in-process writes.
    • MinIO: removed open_write; use direct streaming (put_object_stream) for uploads.
  • Tests

    • Expanded coverage for streaming, timeouts, and concurrency scenarios.
  • Chores

    • Bumped version to 1.4.3.

Walkthrough

Introduces a new cross-thread binary I/O module and rewires bucket write APIs to stream via an asynchronous writer using a background thread. Updates IBucket and synchronized wrappers to accept an optional timeout. Removes MinIO’s old queue-based writer. Adjusts FS/Memory buckets accordingly. Expands tests for streaming, timeouts, and queue utilities. Bumps version.

Changes

Cohort / File(s) Summary
Queue binary I/O primitives
python/bucketbase/_queue_binary_io.py
Adds thread-safe producer/consumer binary stream: BytesQueue, QueueBinaryReadable (read-only, EOF/error propagation, timeouts), QueueBinaryWritable (feeds readable, close sends EOF, waits for completion).
Bucket interface async write
python/bucketbase/ibucket.py
Introduces AsyncObjectWriter using QueueBinaryReadable/Writable; IBucket.open_write now returns AsyncObjectWriter and accepts timeout_sec; synchronized wrapper propagates timeout to base bucket and streams via put_object_stream in a background thread.
Filesystem bucket API
python/bucketbase/fs_bucket.py
Extends FSBucket.open_write signature with timeout_sec (currently unused in body).
Memory bucket sync write rename
python/bucketbase/memory_bucket.py
Renames open_write to open_write_sync with same implementation; docstring added.
MinIO bucket streaming removal
python/bucketbase/minio_bucket.py
Removes previous queue-based open_write path and helper classes/functions; relies on put_object_stream for streaming uploads; deletes open_write API from MinioBucket.
Project metadata
python/pyproject.toml
Version bump 1.4.2 → 1.4.3.
Core tests for IBucket writer behavior
python/tests/bucket_tester.py, python/tests/test_ibucket.py, python/tests/test_memory_bucket.py, python/tests/test_minio_bucket.py
Adds timeout-focused tests; refactors existing test usage to explicit writer object; simulates slow consumer and asserts TimeoutError; integrates tests across IBucket, MemoryBucket, MinIO.
Append-only FS bucket tests
python/tests/test_append_only_fs_bucket.py
Adds nominal and multi-threaded open_write tests ensuring lock/content semantics.
Queue IO unit tests
python/tests/test_queue_binary_io.py
Comprehensive tests for BytesQueue and QueueBinaryReadable: reads, readinto, EOF, timeouts, exceptions, lifecycle, large data.
Remove obsolete MinIO queue tests
python/tests/test_minio_queue_components.py
Deletes tests for removed _QueueWriter/_QueueReader components.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant IBucket
  participant AsyncWriter
  participant Producer as QueueBinaryWritable
  participant Consumer as QueueBinaryReadable
  participant Bucket as BaseBucket
  participant Storage as put_object_stream

  Caller->>IBucket: open_write(name, timeout_sec)
  IBucket-->>Caller: AsyncObjectWriter (context manager)

  Caller->>AsyncWriter: __enter__()
  AsyncWriter-->>Caller: BinaryIO (Producer)
  AsyncWriter->>AsyncWriter: Start background Thread(_write_to_bucket)

  par Producer writes
    loop write()
      Caller->>Producer: write(bytes)
      Producer->>Consumer: feed(bytes, timeout)
    end
    Caller->>AsyncWriter: __exit__(exc?)
    alt no exception
      AsyncWriter->>Consumer: send_eof(timeout)
    else exception in caller
      AsyncWriter->>Consumer: send_exception_to_reader(exc)
    end
  and Background upload
    AsyncWriter->>Bucket: put_object_stream(name, Consumer)
    Bucket->>Storage: stream read() until EOF
    alt upload success
      Bucket-->>AsyncWriter: success
      AsyncWriter->>Consumer: notify_upload_success()
    else upload error
      Bucket-->>AsyncWriter: error
      AsyncWriter->>Consumer: on_consumer_fail(error)
    end
  end

  AsyncWriter->>Consumer: wait_finish(timeout)
  AsyncWriter-->>Caller: exit (propagate TimeoutError/chain errors if any)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • Added IBucket.open_write()  #148 — Prior work on streaming open_write and queue-backed upload path; closely related to replacing/removing MinIO’s queue writer and adding centralized queue I/O.

Suggested reviewers

  • amaximciuc

Poem

Packets queue, like stars in flight,
Bytes stream on through day and night.
Writer hums, a silent thread,
Reader waits for EOF ahead.
Timeouts blink, exceptions glide—
Version up; we rocket-ride. 🚀

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 30e2a90 and e7b1061.

⛔ Files ignored due to path filters (1)
  • python/poetry.lock is excluded by !**/*.lock
📒 Files selected for processing (13)
  • python/bucketbase/_queue_binary_io.py (1 hunks)
  • python/bucketbase/fs_bucket.py (1 hunks)
  • python/bucketbase/ibucket.py (7 hunks)
  • python/bucketbase/memory_bucket.py (1 hunks)
  • python/bucketbase/minio_bucket.py (1 hunks)
  • python/pyproject.toml (1 hunks)
  • python/tests/bucket_tester.py (3 hunks)
  • python/tests/test_append_only_fs_bucket.py (2 hunks)
  • python/tests/test_ibucket.py (1 hunks)
  • python/tests/test_memory_bucket.py (1 hunks)
  • python/tests/test_minio_bucket.py (1 hunks)
  • python/tests/test_minio_queue_components.py (0 hunks)
  • python/tests/test_queue_binary_io.py (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-async-writer

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@asuiu
asuiu merged commit d7eaf62 into master Aug 23, 2025
@asuiu
asuiu deleted the fix-async-writer branch August 23, 2025 11:07
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