Skip to content

kvserver: sep-raft-log: make log application stand-alone #75729

@tbg

Description

@tbg

Is your feature request related to a problem? Please describe.

Today, there is no "library-style" way of crafting a CockroachDB log of commands.

We can in principle craft individual commands by evaluating requests (the
batcheval package), but below that you need a *Replica which strings
together the raft log, and the apply loop.

We have felt for a long time that abstractly we could benefit from better
modularization here, but now we are starting to see this come up in projects we
are working on, for example

// ReplicasStorage does interpret the raft state (all the unreplicated
// range-ID local key names prefixed by Raft), and the RangeTombstoneKey. This
// is necessary for it to be able to maintain invariants spanning the raft log
// and the state machine (related to raft log truncation, replica lifetime
// etc.), including reapplying raft log entries on restart, to the state
// machine. All accesses (read or write) to the raft log and RangeTombstoneKey
// must happen via ReplicasStorage. ReplicasStorage does not by itself apply
// committed raft log entries to the state machine in a running system -- this
// is because state machine application in a running system has complex
// data-structure side-effects that are outside the scope of ReplicasStorage.

and similarly Loss Of Quorum Recovery tools could benefit from tools to interpret the raft log at the right level of abstraction.

Describe the solution you'd like

Continue the work begun by #39254
and further extract the logic pertaining to entry application so that it can be
used to apply log entries outside of the context of a fully instantiated
Replica. I think most of the work will be to wean the apply code off the
many direct accesses to replica.mu and the associated fields.

As an acceptance criterion, we should be able to write a unit test that sets up
a test cluster, appends some commands to the log, stops the cluster and
subsequently re-applies the log entries to an empty state, arriving at an
identical state machine.

Ideally, we also get a testing win by allowing tests to be set up with bespoke
raft logs that exercise hand-crafted sequences of commands; this is very difficult
today and essentially doesn't happen for that very reason.

Note: inclusion of splits/merges will add complexity. We may not need this in
the first pass but should think about how this could work in the future.

Epic: CRDB-55218
Jira issue: CRDB-12807

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)T-kvKV Team

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions