← 输入框|github.com|刷新
Skip to content

Minor code cleanup: store enums in Atomic<T> instead of integer atomics - #7920

Merged
blp merged 4 commits into
mainfrom
memory-pressure-atomic
Nov 11, 2026
Merged

blp merged 4 commits into
mainfrom
memory-pressure-atomic

Conversation

@blp

@blp blp commented Nov 10, 2026

Copy link
Copy Markdown
Member

Some enums were kept in integer atomics (AtomicU8, AtomicU64) and converted with as casts on store and try_from(...).unwrap() on load. This PR stores them in atomic::Atomic<T> with a NoUninit derive, as PipelineState and IcebergPhase already do. Each enum uses repr(u8), so the atomic is a lock-free AtomicU8.

Commit Enum Notes
[dbsp] MemoryPressure Removes the try_from(...).unwrap() on each load. dbsp now depends on atomic.
[connectors] DeltaPhase Removes 8 as u64 casts. dbsp_connectors now depends on bytemuck.
[connectors] NATS RetryState Derives Default (Healthy). The test snapshot now holds the enum.
[iceberg] IcebergPhase Already Atomic. Changes to repr(u8) and removes the stale "reserved" comment and #[allow(dead_code)] on Follow, which follow mode now uses.

The gauge values do not change. The help text of input_connector_iceberg_phase changes from "0=loading_snapshot, 2=completed (1 reserved for follow mode)" to "0=loading_snapshot, 1=follow, 2=completed". metrics.md has the same edit.

Describe Manual Test Plan

  • cargo check --tests for dbsp, dbsp_connectors (with with-nats) and feldera-iceberg.
  • cargo test -p dbsp_connectors --features with-nats --lib nats::input::metrics: 2 passed.

Checklist

  • Unit tests added/updated
  • Integration tests added/updated
  • Documentation updated
  • Changelog updated

Breaking Changes?

None. feldera-types only adds a NoUninit derive to MemoryPressure.

blp added 4 commits November 10, 2026 11:51
The runtime kept memory pressure in an AtomicU8 and converted it with
casts and try_from().unwrap(). Derive NoUninit for MemoryPressure and
store it in an atomic::Atomic instead. It is repr(u8), so the atomic is
still lock-free.

Signed-off-by: Ben Pfaff <blp@feldera.com>
The Delta input metrics kept the phase in an AtomicU64 and cast each
DeltaPhase to u64 on store. Derive NoUninit for DeltaPhase and store it
in an atomic::Atomic instead, as IcebergPhase does. Use repr(u8), since
the repr no longer has to match an AtomicU64.

Signed-off-by: Ben Pfaff <blp@feldera.com>
The NATS input metrics kept the retry state in an AtomicU64 and cast
each RetryState to u64 on store. Derive NoUninit and Default for
RetryState and store it in an atomic::Atomic instead, with repr(u8).
The test snapshot now carries the enum, so the tests compare variants
instead of casts.

Signed-off-by: Ben Pfaff <blp@feldera.com>
Follow mode sets IcebergPhase::Follow, but the enum still marked it as
reserved and dead code, and the phase gauge's help text still said
"1 reserved for follow mode". Drop the stale attribute and comment, and
make the help text and the metrics reference list 1=follow.

Also use repr(u8), as for DeltaPhase. The gauge values do not change.

Signed-off-by: Ben Pfaff <blp@feldera.com>
@blp
blp requested a review from swanandx November 10, 2026 20:04
@blp blp added DBSP core Related to the core DBSP library connectors Issues related to the adapters/connectors crate metrics Metrics about feldera pipelines rust Pull requests that update Rust code labels Nov 10, 2026
@blp blp self-assigned this Nov 10, 2026
@blp blp changed the title Store enums in Atomic<T> instead of integer atomics Minor code cleanup: store enums in Atomic<T> instead of integer atomics Nov 10, 2026
@blp
blp requested review from bestouff and removed request for swanandx November 10, 2026 20:05
@mythical-fred-oss

Copy link
Copy Markdown
Contributor

LGTM. This is a refactor with no behaviour change: the gauge encodings stay the same, and the only user-visible change is the Iceberg help text, which metrics.md already reflects.

Ran Result
cargo check --locked -p dbsp -p feldera-iceberg -p feldera-types ✅
cargo test --locked -p dbsp_connectors --features with-nats --lib nats::input::metrics ✅ 2 passed (this also builds the Delta changes)
  • atomic and bytemuck were already workspace deps (MIT/Apache), and bytemuck already has derive enabled, so this adds no new licence or crate surface.
  • Every enum is repr(u8) + NoUninit, so Atomic<T> maps to a lock-free AtomicU8.

@blp
blp added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit c7571e8 Nov 11, 2026
3 checks passed
@blp
blp deleted the memory-pressure-atomic branch November 11, 2026 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

connectors Issues related to the adapters/connectors crate DBSP core Related to the core DBSP library metrics Metrics about feldera pipelines rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants