背景

从一条丢包的 AppendEntries 讲起……

线性一致读

ReadIndex

Lease Read

压测数据

结论


func (n *Node) readIndex(ctx context.Context) (uint64, error) {
    n.mu.Lock()
    if n.state != StateLeader {
        n.mu.Unlock()
        return 0, ErrNotLeader
    }
    commit := n.commitIndex
    n.mu.Unlock()

    select {
    case <-ctx.Done():
        return 0, ctx.Err()
    case <-n.applyCh:
        return commit, nil
    }
}