Skip to content

v0.10.1

Latest

Choose a tag to compare

@drmingdrmer drmingdrmer released this 19 Nov 13:46
· 87 commits to main since this release

Highlights

  • Deadline-driven elections and heartbeats. Openraft replaces the periodic ticker with separate timers for elections and leader heartbeats. Runtime switch changes wake RaftCore immediately. Applications can use Trigger::tick() to drive heartbeat checks for many Raft groups from one timer. (#2304)
  • Conditional batch writes. Raft::write_many() supports an optional responder per entry. Both batch write APIs accept WriteOption to require an expected leader. Openraft accepts or rejects the batch as a whole, but entries still commit individually: a leadership change can leave only a prefix committed. Raft::write() also accepts .with_option(). (#2321)
  • Opt-in relaxed leader reads. LinearizerOption::with_relaxed(true) waits for the leader's no-op to apply without also waiting for the committed log ID, reducing read latency when apply lags behind replication. The reduced barrier applies only on the issuing leader; follower reads still use the standard barrier. Before requesting relaxed reads, restart every node with Config::enable_relaxed_read set to Some(true) and ensure the state machine makes writes visible before acknowledging them. Enabling the setting can increase follower apply lag because followers wait for the leader to apply entries first. (#1267)
  • Faster state-machine apply and lower idle memory. The worker merges contiguous apply requests, reads the next batch while applying the current one, and publishes completed progress without waiting for the next read. Smaller initial queues and runtime futures reduce memory use for deployments with many mostly idle groups. (#2309, #2323, bc383014)

Other notable changes

  • RaftMetrics and RaftServerMetrics expose last_leader_contact on followers and learners. It indicates recent contact, not quorum health or log catch-up. The apply_batch metric now records one sample per completed state-machine apply() call rather than per queued command. (04cf76af, #2346)
  • ApplicationSuite lets storage implementers check that different apply batch boundaries produce the same state, progress, membership, and responses. (4ecc36a1)
  • declare_raft_types! now accepts overrides for Responder<T> and Batch<T>. (c5096d12)
  • Fixed cancellation of abandoned append streams, blocked heartbeat workers, and pending snapshot reads. (44dc16e7, 05043055, d5e9f334)
  • The RocksDB state-machine example validates snapshot metadata before install and preserves recovery data if publishing a snapshot fails. (afb04aa5)
  • The directory-transfer example reports failed final writes, refuses to overwrite existing target files, and rejects names that can escape the target directory on Windows. Binary formats can now encode chunks as byte strings, fixing failures with large MessagePack-encoded snapshot chunks. (6fe35205, e04b5df5, 9dcc21ed, c10111fb)
  • Openraft no longer depends on chrono. Displayed timestamps now use UTC; the SerdeInstant wire format is unchanged. (#2384)

Upgrade tips

The examples below show what to change in your source when upgrading from Openraft 0.10.0 to 0.10.1.

Pass write options to Raft::client_write_many()

The method now takes a WriteOption. Pass WriteOption::default() to keep writing without specifying an expected leader. (a8d0092b)

Before:

let responses = raft.client_write_many(entries).await?;

After:

use openraft::raft::WriteOption;

let responses = raft.client_write_many(entries, WriteOption::default()).await?;

Add the future type parameter to WriteRequest

WriteRequest carries an unboxed future. Direct calls such as raft.write(data).await are unchanged. If a helper names WriteRequest, make it generic over the future type. (b3d8c1b6)

Before:

use openraft::{RaftTypeConfig, errors::Fatal, raft::WriteRequest};

async fn submit<C>(request: WriteRequest<'_, C>) -> Result<(), Fatal<C>>
where
    C: RaftTypeConfig,
{
    request.await
}

After:

use std::future::Future;

use openraft::{RaftTypeConfig, errors::Fatal, raft::WriteRequest};

async fn submit<C, F>(request: WriteRequest<'_, C, F>) -> Result<(), Fatal<C>>
where
    C: RaftTypeConfig,
    F: Future<Output = Result<(), Fatal<C>>>,
{
    request.await
}

Preserve both log IDs when constructing a Linearizer

Linearizer::new() now takes the no-op log ID and the committed log ID separately. If you send read state to a follower, replace the single read_log_id field in your payload with noop_log_id and committed; take both from the leader's linearizer via noop_log_id() and committed(). (3b1f7fa4)

Before:

let linearizer = Linearizer::new(node_id, read_log_id, applied);

After:

let linearizer = Linearizer::new(node_id, noop_log_id, committed, applied);

Bind the owned ReadLogId before borrowing from it

read_log_id() now returns an owned ReadLogId instead of a reference. Keep that value in a local variable if you borrow its inner log ID. If you used .clone() to get an owned ReadLogId, remove it. (3b1f7fa4)

Before:

let log_id = linearizer.read_log_id().log_id();

After:

let read_log_id = linearizer.read_log_id();
let log_id = read_log_id.log_id();

Use try_peek() for nonblocking reads

PeekableReceiver::peek() now waits asynchronously. Its previous nonblocking behavior, including the Result return type, moved to try_peek(). (8175ca60)

Before:

let next = receiver.peek()?;

After:

let next = receiver.try_peek()?;

Add a fallback when matching label enums

ExternalCommandName, RaftMsgName, NotificationName, CommandName, SMCommandName, Operation, ErrorVerb, and RPCTypes are now #[non_exhaustive]. Downstream matches must handle unknown variants. (b55c4eac)

Before:

let label = match verb {
    ErrorVerb::Read => "read",
    ErrorVerb::Write => "write",
    ErrorVerb::Seek => "seek",
    ErrorVerb::Delete => "delete",
};

After:

let label = match verb {
    ErrorVerb::Read => "read",
    ErrorVerb::Write => "write",
    ErrorVerb::Seek => "seek",
    ErrorVerb::Delete => "delete",
    _ => "unknown",
};

Disable automatic elections explicitly

enable_tick: false and runtime_config().tick(false) now disable only the heartbeat timer. If you previously used either setting to suppress automatic elections as well, also set enable_elect: false in Config or call runtime_config().elect(false) at runtime. (#2304)

Before:

// At startup:
let config = Config { enable_tick: false, ..Config::default() };

// Or at runtime:
raft.runtime_config().tick(false);

After:

// At startup:
let config = Config {
    enable_tick: false,
    enable_elect: false,
    ..Config::default()
};

// Or at runtime:
raft.runtime_config().elect(false);
raft.runtime_config().tick(false);

Calculate quorum acknowledgement age from the timestamp

On an idle leader with heartbeats off, the deprecated millis_since_quorum_ack may stop updating. Use last_quorum_acked to calculate the age when you collect the metric. If no timestamp is available, the calculated age is None; the old field reported Some(0) for a leader that was its own quorum. (43643c46)

Before:

let age_ms = metrics.millis_since_quorum_ack;

After:

use openraft::Instant as _;

let age_ms = metrics.last_quorum_acked.map(|ts| ts.elapsed().as_millis() as u64);

Update exhaustive Config literals

Config has a new enable_relaxed_read field. Set it to None to preserve standard reads. No change is needed for literals that already use ..Config::default(). (#1267)

Before (unchanged fields omitted):

let config = Config {
    enable_local_lease_read: None,
    // Other existing fields.
};

After (unchanged fields omitted):

let config = Config {
    enable_local_lease_read: None,
    enable_relaxed_read: None,
    // Other existing fields.
};

Update manually constructed metrics

RaftMetrics and RaftServerMetrics have a new last_leader_contact field. Set it to None when constructing a value with no known leader contact, for example in a test fixture. Exhaustive destructuring patterns must also name the field or use ... (04cf76af)

Before:

let metrics = RaftServerMetrics::<C> {
    id,
    vote,
    state,
    current_leader,
    membership_config,
    committed_membership_config,
};

After:

let metrics = RaftServerMetrics::<C> {
    id,
    vote,
    state,
    current_leader,
    last_leader_contact: None,
    membership_config,
    committed_membership_config,
};

Zero-pad dates in #[since] attributes

The date parser now requires yyyy-mm-dd. Pad single-digit months and days. (#2384)

Before:

#[since(version = "1.0.0", date = "2026-1-5")]
pub struct Example;

After:

#[since(version = "1.0.0", date = "2026-01-05")]
pub struct Example;

Remove #[add_async_trait] from non-trait items

The attribute now rejects non-trait items in all builds. If a single-threaded build previously accepted one, remove the attribute from that item. (52d87629)

Before:

#[add_async_trait]
pub struct Example;

After:

pub struct Example;