Skip to content

perf(lease-read): make AppliedIndex lock-free atomic (deferred from #549) #553

@bootjp

Description

@bootjp

Issue

etcd.Engine.AppliedIndex() (internal/raftengine/etcd/engine.go:560-567) takes e.mu.RLock() on every call. Under high read concurrency this contends with the Raft Ready loop's refreshStatus write lock (~100 Hz at current tick interval). Performance reviewer flagged as HIGH on PR #549.

Fix

Mirror e.applied uint64 into an atomic.Uint64. AppliedIndex() returns the atomic load with no lock.

Acceptance

  • Hot-path LeaseRead benchmark: AppliedIndex cost drops from ~50 ns (RLock) to ~5 ns (atomic load).
  • No correctness regression: existing tests pass; Status().AppliedIndex may continue to use the locked path if needed for snapshot semantics.

References: PR #549 (deferred).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions