Module ranked_register

Module ranked_register 

Source
Expand description

Ranked register recipe for Paxos-style ballot fencing

§Ranked Register for FoundationDB

A shared memory abstraction that encapsulates Paxos ballots, based on Chockler & Malkhi’s “Active Disk Paxos with infinitely many processes” (PODC 2002). A ranked register is a mutable register with conflict detection via ranks, supporting unbounded processes with finite storage.

§Operations

OperationWhoEffect
read(rank)LeaderUpdates max_read_rank (installs fence), returns current value
write(rank, value)LeaderCommits only if rank is high enough
value()FollowersPlain read, no fence installed

§Composing with Leader Election

The ranked register is designed to work with the leader election recipe. The leader election’s ballot serves as the rank for register operations, providing automatic fencing against stale leaders.

use foundationdb::recipes::leader_election::LeaderElection;
use foundationdb::recipes::ranked_register::{RankedRegister, Rank};
use foundationdb::tuple::Subspace;

let election = LeaderElection::new(Subspace::all().subspace(&"my-election"));
let register = RankedRegister::new(Subspace::all().subspace(&"my-state"));

// In the leader's main loop:
// db.run(|txn, _| async move {
//     let result = election.run_election_cycle(&txn, process_id, priority, now).await?;
//     match result {
//         ElectionResult::Leader(state) => {
//             let rank = Rank::from(state.ballot);
//             // Read current state (installs fence at this ballot)
//             let current = register.read(&txn, rank).await?;
//             // Mutate and write back
//             register.write(&txn, rank, b"new_value").await?;
//         }
//         ElectionResult::Follower(_) => {
//             // Safe read — doesn't interfere with leader's writes
//             let current = register.value(&txn).await?;
//         }
//     }
//     Ok(())
// }).await?;

§Why This Works

  • Leader election’s ballot is monotonically increasing
  • A deposed leader has a lower ballot than the new leader
  • read(rank) installs a fence at the ballot value
  • Any write with a lower rank is automatically rejected
  • value() is safe for followers — it never installs a fence

Structs§

Rank
A rank value for ordering register operations
RankedRegister
A ranked register backed by FoundationDB
ReadResult
Result of a ranked read operation
RegisterState
Internal state of the ranked register as stored in FoundationDB

Enums§

RankedRegisterError
Ranked register specific errors
WriteResult
Result of a ranked write operation

Type Aliases§

Result
Result type for ranked register operations