Skip to content

[rust][c++] Add automatic offset commits and group administration - #5343

Open
naivedogger wants to merge 5 commits into
apache:mainfrom
naivedogger:codex/consumer-offset-complete
Open

naivedogger wants to merge 5 commits into
apache:mainfrom
naivedogger:codex/consumer-offset-complete

Conversation

@naivedogger

@naivedogger naivedogger commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Closes #5341 (part of #5198). Add periodic commits and offset reset policies to the existing single-table Rust and C++ scanners, and manage stored group offsets through Admin. Multi-table scanning is tracked separately in #5492 / #5493.

Brief change log

  • Poll enqueues a commit when the interval expires without waiting for the acknowledgment. Missing offsets follow the configured earliest, latest, or error policy. A final explicit synchronous commit confirms processed positions before shutdown.
  • List groups and saved offsets, reset or remove selected offsets, or delete a group and its offsets. Admin can manage buckets across tables without creating a scanner. Ambiguous deletions are not automatically replayed.

Tests

Rust core and C++ bridge unit suites, six Rust consumer-offset integration tests and the native C++ single-table restore/automatic commit/Admin test passed locally. Rust formatting and targeted Clippy passed.

API and Format

Extends Rust group options and adds C++ scanner factory overloads taking ConsumerOffsetOptions. Rust group scans enable periodic commits by default (5s); existing C++ scanner factories remain manual by default. Adds five Admin methods in each SDK. No wire or storage format changes.

Documentation

Updated the main site's Rust and C++ API references.

  • Yes — OpenAI Codex assisted with implementation, tests, and documentation.

Add poll-driven commits, multi-table scanners, and consumer group administration. Keep explicit commits for the existing C++ scanners.

Co-Authored-By: Codex <noreply@openai.com>
AI-Model: GPT-6
AI-Contributed/Feature: 1476/1476
AI-Contributed/UT: 476/476
@naivedogger
naivedogger force-pushed the codex/consumer-offset-complete branch from 812557f to c524186 Compare December 3, 2026 10:26
@naivedogger
naivedogger marked this pull request as ready for review December 3, 2026 11:23
Co-Authored-By: Codex <noreply@openai.com>
AI-Model: GPT-6
AI-Contributed/Feature: 784/784
AI-Contributed/UT: 106/106
@naivedogger naivedogger changed the title [rust] Complete consumer offset scanning and administration [rust][c++] Complete consumer offset scanning and administration Dec 3, 2026
… commits

Co-Authored-By: Codex <noreply@openai.com>
AI-Model: GPT-6
AI-Contributed/Feature: 112/112
AI-Contributed/UT: 65/65
@naivedogger

Copy link
Copy Markdown
Contributor Author

@loserwang1024 @fresh-borzoni Appreciate a review here, thanks! 🙏

Co-Authored-By: Codex <noreply@openai.com>
AI-Model: GPT-6
AI-Contributed/Feature: 919/919
AI-Contributed/UT: 359/359
@naivedogger naivedogger changed the title [rust][c++] Complete consumer offset scanning and administration [rust][c++] Add automatic offset commits and group administration Dec 4, 2026
@loserwang1024
loserwang1024 requested a balanced review from Copilot December 4, 2026 06:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

After a bucket-count change, latest-reset-only scanners can repeatedly fail because InvalidBucketRouting bypasses the metadata refresh and request rebuild needed to clear stale routing. Separately, Rust group scanners now commit periodically during polling by default; the release upgrade notes need to explain this behavior change and the auto_commit_enabled = false opt-out.

2 open issues
What changed in this PR

Adds automatic offset commits and consumer-group administration to Rust and C++ single-table scanners. Multi-table scanning remains separate.

Changes:

  • Adds poll-driven commits and earliest/latest/error reset policies, preserving manual defaults for existing C++ factories.
  • Adds Admin APIs to list, reset, and delete saved offsets and groups.
  • Updates tests and API documentation.
File Description
website/​docs/​apis/​rust/​api-reference.md Documents offset management and commit contracts.
website/​docs/​apis/​cpp/​api-reference.md Documents automatic commits and Admin APIs.
fluss-rust/​crates/​fluss/​tests/​integration/​consumer_offsets.rs Tests restore policies and cross-table administration.
fluss-rust/​crates/​fluss/​src/​rpc/​message/​list_offsets.rs Makes offset specifications comparable.
fluss-rust/​crates/​fluss/​src/​rpc/​message/​consumer_offsets.rs Adds group-management request wrappers.
fluss-rust/​crates/​fluss/​src/​rpc/​api_key.rs Registers group-management API keys.
fluss-rust/​crates/​fluss/​src/​client/​table/​scanner/​latest_resets.rs Resolves latest offsets during polling.
fluss-rust/​crates/​fluss/​src/​client/​table/​scanner/​consumer_group.rs Schedules automatic commits and shutdown draining.
fluss-rust/​crates/​fluss/​src/​client/​table/​scanner.rs Integrates commits and latest-offset resolution.
fluss-rust/​crates/​fluss/​src/​client/​table/​mod.rs Exposes the latest-offset constant.
fluss-rust/​crates/​fluss/​src/​client/​mod.rs Exports new offset-management types.
fluss-rust/​crates/​fluss/​src/​client/​consumer_offsets/​tests.rs Tests mutation outcomes and commit draining.
fluss-rust/​crates/​fluss/​src/​client/​consumer_offsets.rs Implements reset policies and administrative mutations.
fluss-rust/​crates/​fluss/​src/​client/​admin.rs Adds five group-management methods.
fluss-rust/​bindings/​cpp/​test/​test_log_table.cpp Tests periodic commits and offset administration.
fluss-rust/​bindings/​cpp/​src/​table.cpp Implements C++ factories and Admin methods.
fluss-rust/​bindings/​cpp/​src/​lib.rs Extends bridge options and operations.
fluss-rust/​bindings/​cpp/​src/​ffi_converter.hpp Converts scanner offset options.
fluss-rust/​bindings/​cpp/​src/​consumer_offsets.rs Bridges administrative calls and outcomes.
fluss-rust/​bindings/​cpp/​include/​fluss.hpp Declares public C++ options and APIs.

Review effort: Balanced

};
match tokio::time::timeout(Duration::from_secs(30), call).await {
Ok(Ok(offsets)) => return Ok(Some(offsets)),
Ok(Err(err)) if !err.is_retriable() => return Err(err),
Self {
group_id: group_id.into(),
timeout: Duration::from_secs(30),
auto_commit_enabled: true,

@loserwang1024 loserwang1024 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please keep the Rust implementation easy to map to the Java client: use corresponding component and public API names, configuration names/defaults, and failure semantics. Tokio and Rust-specific ownership are appropriate implementation choices, but behavioral differences should be deliberate and covered by tests.

I am requesting changes for the mixed-bucket latest-offset handling and the Admin mutation deadline issue described inline. I also agree with the existing InvalidBucketRouting finding: Java explicitly handles stale routing in OffsetFetcher, and Rust needs the corresponding metadata refresh and request rebuild.

For the new Admin APIs, please follow Java's public terminology: list_consumer_group_offsets, alter_consumer_group_offsets, and delete_consumer_group_offsets. These correspond to the Java Admin methods. This request concerns the APIs introduced here; it does not require an unrelated rename of existing APIs.

The other inline comments cover configuration consistency, component naming, aggregate result semantics, explicit reset state, and deterministic tests. The current Rust defaults (auto-commit enabled, five-second interval, earliest reset) and poll-driven/close-if-due behavior already match Java and should be preserved. The mixed-bucket case was identified by tracing the response handling; please add a regression test for that scenario.

if let Some(node) = node {
let call = async {
let conn = connections.get_connection(&node).await?;
conn.request(request).await?.offsets()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Preserve successful bucket offsets when another bucket needs a retry.

ListOffsetsResponse::offsets() returns one error for the whole response if any bucket fails. The reset completion path then requeues every bucket, discarding successful results. For example, if A returns latest=100 and B returns NotLeaderOrFollower, A is queried again after metadata refresh. If A's end advances to 120 during that retry, its starting position moves forward and records 100–119 are skipped compared with Java's behavior.

Java's OffsetFetcher.handleLatestOffsets() applies each successful bucket independently and retries only failed buckets. Please preserve that behavior here and add a mixed-success response test; a failure for B should neither block A's resolved position nor cause A's latest offset to be resolved again.

use std::task::Poll;

#[derive(Default)]
pub(super) struct LatestResets {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please name this module offset_fetcher.rs and the component OffsetFetcher, matching Java's OffsetFetcher. Likewise, reset_positions_if_needed() would correspond directly to Java's resetPositionsIfNeeded().

Keeping this logic in a separate module makes sense: it owns asynchronous offset lookup, retries, and invalidation of obsolete requests. Using the existing Java terminology will make those responsibilities easier to recognize when maintaining both clients.

{
let mut request = resets.requests.swap_remove(i);
let buckets = std::mem::take(&mut request.buckets);
let values = match result.map_err(|e| invalid(&e.to_string())).and_then(|v| v) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we represent reset outcomes explicitly? Currently Ok(None) means “refresh/retry”, it is then converted to an empty map, and the empty map means “nothing to apply”. The other arm also combines retry and error handling.

An explicit result describing resolved offsets and buckets to retry would make the state transitions clearer and support preserving partial successes. Errors can remain errors instead of sharing the same control-flow encoding. This would make the Rust path easier to compare with Java's separate complete/fail reset handling.

Err(error) => return Err(OffsetCommitError::Rejected(error)),
};
match connection
.request_with_send_status(make_request(), sent, None)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Pass the operation deadline through to the send path.

The outer timeout does not prevent a new write from starting after the deadline. If this request is waiting for the connection's write lock and the lock becomes available after expiry, polling the inner future can start the cancellation-safe write before the timeout is observed. An alter/delete operation can therefore be dispatched after its deadline and subsequently report an unknown timeout outcome.

Please compute one absolute deadline, use timeout_at(deadline, ...), and pass Some(deadline) here, as the scanner commit path already does. The send layer checks that deadline after acquiring the write lock and before starting the write. A regression test should hold the write lock past the deadline and verify that the expired mutation never reaches the server.

Small simplification in the same helper: all callers pass &mut false and do not consume the state, so sent can be local to mutate().

/// Interval between periodic commits; ignored when disabled.
pub auto_commit_interval: Duration,
/// Starting position for a bucket without a saved offset.
pub offset_reset: ConsumerOffsetReset,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please align the configuration terminology with Java: auto_offset_reset for client.consumer.auto-offset-reset, and request_timeout for the timeout option. Keep the operation deadline semantics explicit, including queueing, discovery, and retries.

This should include the configuration plumbing, not just the field names. The new latest-offset lookup independently hard-codes 30 seconds, list_consumer_groups() hard-codes another 30 seconds, and the other Admin methods construct default group options internally. Changing the scanner's timeout therefore does not configure its latest-offset lookup, and callers cannot configure these new Admin deadlines. Please provide a consistent timeout source and document its scope. The 30-second default itself already matches Java; the mismatch is configurability and scope.

inner_request: request.clone(),
})
.await?;
decode_commit(response, &offsets).map_err(OffsetCommitError::Unknown)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

API consistency suggestion: please provide an explicit aggregate-success contract for Admin mutations.

This returns Ok(outcomes) even when an individual bucket was rejected or has an unknown outcome. In contrast, scanner commits use the same Result<OffsetCommitResult, OffsetCommitError> shape but return Err(BucketFailures(...)) if any bucket fails. Consequently, .await? has different success semantics for two operations with the same result type.

The documentation does mention inspecting each Admin result, so this is an API design concern rather than an undocumented implementation failure. Could we either use the same aggregate failure semantics or expose a distinct result type with an explicit all-success check? Java provides both per-bucket results and all(), which avoids making every caller implement that aggregation.

.insert(bucket.clone(), OffsetAndMetadata::new(0));
scanner.consumer_group = Some(group);
scanner.auto_commit = consumer_group::AutoCommit::from_options(&ConsumerGroupOptions {
auto_commit_interval: Duration::from_nanos(1),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please make the auto-commit timing tests deterministic and verify that the commit path was actually exercised. Setting the interval to one nanosecond and asserting that poll returns data does not itself establish that an automatic commit was admitted; the test could also pass if auto-commit were never triggered.

Use paused Tokio time with explicit advancement, and a controllable pending commit response, to verify that poll enqueues a due commit without waiting for its ACK. Please also cover disabled auto-commit, just before/at the interval boundary, elapsed time without another poll, and close before/after the interval. Java's ManualClock-based tests provide a useful behavioral reference.

Keep resolved offsets on mixed ListOffsets replies and refresh stale routing before rebuilding the failed lookup. Carry the Admin mutation deadline through the write lock and retain item outcomes when a batch fails.

Align the new Admin names and timeout options, document automatic commits on upgrade, and cover the poll and close boundaries with a controlled clock and acknowledgment.

Co-Authored-By: Codex <noreply@openai.com>
AI-Model: GPT-6
AI-Contributed/Feature: 1030/1030
AI-Contributed/UT: 147/147
@naivedogger

Copy link
Copy Markdown
Contributor Author

@loserwang1024 I’ve addressed your feedback. Could you take another look?

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.

[rust][c++] Complete single-table offset scanning and group administration

3 participants