Skip to content

refactor(core): slim down StateMachine trait — move non-protocol methods to server layer #400

Description

@JoshuaChi

The StateMachine trait in d-engine-core is the protocol-layer abstraction that Raft consensus depends on. Over time a few application-level methods have accumulated in the trait that Raft itself never calls. This makes it harder for external implementors to provide their own state machine, because they are forced to implement concepts (TTL cleanup, prefix scan, collection size) that have nothing to do with consensus.

Methods proposed for removal from the trait:

scan_prefix — application-level query, not needed by the Raft loop. Should live on the concrete server-layer types or behind a separate optional trait.

lease_background_cleanup — TTL expiry is a business concern. The default no-op implementation hints that this does not belong in the protocol contract.

len / is_empty — observability/debug helpers, not consensus requirements.

Out of scope for this ticket:

get stays for now — the current lease-read path in the Raft loop calls it directly. Once the ReadActor fast path (tracked separately) is complete, get can be revisited.

Impact:

External state machine implementors will have a smaller, cleaner surface to implement. No behaviour change for existing built-in implementations — the methods move, they do not disappear.

Metadata

Metadata

Assignees

No one assigned

    Labels

    component:raft-statemachineState machine semantics, apply pipeline, RocksDB/File state machine implementations.concern:correctnessLinearizability, serializability, consistency guarantees across replicas.concern:scalabilityBehavior under large cluster size, high entry count, or long-running deployments.

    Type

    Fields

    No fields configured for Task.

    Projects

    Status
    Backlog

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions