Skip to content

Refactor EntryContext

Raft-rs library provides 2 types of raft log entries: normal & conf-change. We use normal entries for global schema, topology and miscelanious configuration. Raft-rs allows the entries to be configurable via raw binary context. We use enum EntryContext serialized into msgpack as context for raft log entries, this is basically the logical payload of the entries.

Currently this enum (https://git.picodata.io/picodata/picodata/picodata/-/blob/1ffcc22a1f05df71113a665ce3a5c8251ae460b2/src/traft/mod.rs#L142) consists of 2 variants, equivalent to the following

enum EntryContext {
    Normal {
        lc: LogicalClock,
        op: traft::Op,
    },
    ConfChange {
        instances: Vec<Instance>, 
    },
}
  1. I have just realized while writing this that EntryContext::ConfChange is never used, it's basically just dead code and should be removed altogether.
  2. EntryContext::Normal::lc is only ever used for read states, because raft-rs forces the users to provide a unique identifier for the read state request, but the read state request is not a raft log entry. This basically means that we store a logical clock value in every raft log entry, but we never use it. Moreover logical clock within a raft log entry is entirely redundant, as it's purpose it to be a unique identifier of an entry, but raft entries already have unique identifiers -- (term, index) pairs (or as I like to call them raft entry ids). See !678 (comment 44751)
  3. We have a notifications system for awaiting of read states & proposed entries to be applied. As mentioned above, it's not needed for raft entries, as those already have unique identifiers and we can wait for them to be applied by means of tracking the current applied index (see events::RaftEntryApplied). So we can simplify the code by only using the notifications for read states, for which it's unfortunately still required.
  4. As a result of all of the above, the EntryContext can be simplified into a Option<traft::Op>
Edited by Yaroslav Dynnikov
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information