Skip to content

feat(lease): implement lease/TTL subsystem#105

Merged
slow2342 merged 1 commit into
mainfrom
feat/lease-ttl
Jun 10, 2026
Merged

feat(lease): implement lease/TTL subsystem#105
slow2342 merged 1 commit into
mainfrom
feat/lease-ttl

Conversation

@slow2342

Copy link
Copy Markdown
Owner

Summary

  • Add lease management with Grant, Revoke, KeepAlive, and TimeToLive operations routed through Raft for cross-node consistency.
  • Persist lease data in a dedicated RocksDB column family with atomic WriteBatch for lease + counter.
  • Background expiry task detects expired leases and proposes automatic revoke.
  • Enforce persist-first invariant to prevent in-memory state divergence on persistence failure.

Changes

  • proto/lease.proto — Add AetherLease service definition (Grant, Revoke, KeepAlive, TimeToLive, Leases).
  • src/lease/lease.rs — Lease and LeaseInfo structs with TTL/expiry semantics.
  • src/lease/mod.rs — LeaseManager with in-memory state, expiry ordering, and restore from persistent storage. Load-before-clear pattern prevents partial state corruption.
  • src/lease/store.rs — LeaseStore persistence layer with multi_get_cf batch optimization.
  • src/api/lease.rs — gRPC LeaseService implementing AetherLease trait.
  • src/raft/state_machine.rs — Apply handlers for LeaseGrant, LeaseRevoke, LeaseKeepAlive. Persist-first invariant with atomic WriteBatch for lease + counter. In-memory detach after successful batch write in Delete paths.
  • src/raft/raftrs_handle.rs — Switch to std::sync::RwLock for members list with documented rationale.
  • src/main.rs — Lease expiry background task, improved error logging.
  • src/config.rs — Lease configuration (max_leases, max_ttl).
  • src/storage/rocksdb.rs — Add lease_cf, key_lease_cf, lease_keys_cf column families.
  • build.rs — Compile lease.proto.

Testing

  • 29 unit tests pass covering lease grant/revoke/keep_alive, put with lease attach, revoke deletes attached keys, watch events.
  • cargo clippy -- -D warnings passes with zero warnings.
  • cargo fmt -- --check passes.

Related issues

Refs #79

Add lease management with Grant, Revoke, KeepAlive, and TimeToLive
operations routed through Raft for consistency. Lease data is persisted
in a dedicated RocksDB column family with an atomic WriteBatch for lease
and counter. Expired leases are detected by a background task and
proposed for automatic revoke. Enforce persist-first invariant to
prevent in-memory state divergence on persistence failure. Use
multi_get_cf for batch lease cleanup. Move lease data loads before
clear() in restore() to prevent partial state corruption.
@slow2342
slow2342 merged commit 793d116 into main Jun 10, 2026
6 of 8 checks passed
@slow2342
slow2342 deleted the feat/lease-ttl branch June 10, 2026 11:52
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