Skip to content

Allow manual confirmation of topic reader partition sessions - #951

Merged
vgvoleg merged 3 commits into
ydb-platform:mainfrom
nshestakov:topic-reader-manual-partition-start
Dec 3, 2026
Merged

vgvoleg merged 3 commits into
ydb-platform:mainfrom
nshestakov:topic-reader-manual-partition-start

Conversation

@nshestakov

Copy link
Copy Markdown
Contributor

Pull request type

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

The topic reader answers every StartPartitionSessionRequest by itself. An application can only pass a start offset from on_partition_get_start_offset, and the whole read loop waits while that hook runs. There is no way to set commit_offset, to delay the confirmation, or to learn that a partition was stopped.

The C++ SDK lets the application call TStartPartitionSessionEvent::Confirm(readOffset, commitOffset) when it is ready. Clients migrating from the legacy PersQueue SDK rely on this to start reading from offsets stored in their own database.

Issue Number: N/A

What is the new behavior?

  • EventHandler.on_partition_session_start(event) receives OnPartitionSessionStart with topic, partition_id, committed_offset, read_offset and end_offset. No data is read from the partition until event.confirm(read_offset=None, commit_offset=None) is called. The call may happen after the handler returns and from any thread.
  • A second confirm() raises ValueError. A confirm for a partition session that was already stopped, or for a closed stream, is ignored.
  • EventHandler.on_partition_session_stop(event) receives OnPartitionSessionStop with topic, partition_id, committed_offset and graceful. It is a notification: the reader still answers the server itself.
  • Backward compatible: without an event handler the reader confirms immediately as before. The default on_partition_session_start calls on_partition_get_start_offset and confirms with its result, so existing handlers keep working.

Other information

  • Unit tests in ydb/_topic_reader/topic_reader_asyncio_test.py cover the default confirm, the legacy start-offset hook, manual confirm, confirm from another thread, and confirm after stop.
  • black, style, mypy and unit tests pass locally. Integration tests were not run.

Add EventHandler.on_partition_session_start with OnPartitionSessionStart.confirm(read_offset, commit_offset), similar to Confirm in the C++ SDK, and EventHandler.on_partition_session_stop notification. The default handler keeps confirming automatically with on_partition_get_start_offset.

Co-authored-by: Cursor <cursoragent@cursor.com>
@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.15789% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.66%. Comparing base (631d6d4) to head (df2fa1d).

Files with missing lines Patch % Lines
ydb/_topic_reader/topic_reader_asyncio.py 80.64% 4 Missing and 2 partials ⚠️
ydb/_topic_reader/events.py 93.33% 1 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #951      +/-   ##
==========================================
+ Coverage   84.53%   84.66%   +0.12%     
==========================================
  Files         102      102              
  Lines       14137    14200      +63     
  Branches     1489     1499      +10     
==========================================
+ Hits        11951    12022      +71     
+ Misses       1739     1731       -8     
  Partials      447      447              
Flag Coverage Δ
integration 79.85% <59.21%> (-0.09%) ⬇️
unit 57.52% <88.15%> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
ydb/topic.py 89.88% <ø> (ø)
ydb/_topic_reader/events.py 77.31% <93.33%> (+23.61%) ⬆️
ydb/_topic_reader/topic_reader_asyncio.py 87.53% <80.64%> (+0.56%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nshestakov
nshestakov marked this pull request as ready for review December 3, 2026 12:42
@vgvoleg vgvoleg added the SLO label Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

🌋 SLO Test Results

🟡 6 workload(s) tested — 1 workload(s) exceeded warning thresholds

Commit: 802427f · View run

Workload Thresholds Duration Report
sync-topic-multiwriter 🟢 OK 10m 7s 📄 Report
sync-table 🟢 OK 10m 2s 📄 Report
sync-query 🟢 OK 10m 10s 📄 Report
async-topic 🟢 OK 10m 3s 📄 Report
sync-topic 🟢 OK 10m 7s 📄 Report
async-query 🟡 Warning 10m 3s 📄 Report

Threshold violations:

async-query:

  • read_retry_attempts: ▲ 35.5% (≥ 20% warn)

Generated by ydb-slo-action

@vgvoleg
vgvoleg merged commit 44d2d96 into ydb-platform:main Dec 3, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants