Function: get in read-repair/read_repair.py

Date: 2026-05-29

Time: 13:38

Replica.get — Versioned Key-Value Lookup

Purpose

get is the read path for a single replica node in a leaderless replication system. It retrieves the current value and its version number for a given key. This method is the low-level building block that higher-level quorum reads (ReadRepairStore.get) and anti-entropy repair (antientropyrepair) call repeatedly across multiple replicas to compare versions and detect staleness.

Contract

Parameters

| Parameter | Type | Description |

|-----------|------|-------------|

| key | str | The lookup key. No validation — any string is accepted, including empty strings. |

Return Value

Every caller in this file unpacks the result with a None guard first:


result = r.get(key)
if result is not None:
    val, ver = result

The caller must handle None before attempting to destructure — there is no sentinel tuple.

Algorithm

1. Check if key exists in the _store dictionary via in.

2. If present, return the stored (value, version) tuple directly (no copy).

3. If absent, return None.

This is a direct dictionary lookup — O(1) average case. No version filtering, no tombstone handling, no conflict resolution. All of that complexity lives in ReadRepairStore.

Side Effects

None. This is a pure read with no mutations, no I/O, and no logging. It does not check self.available — availability filtering is the caller's responsibility (ReadRepairStore.available_replicas()).

Error Handling

No exceptions are raised or caught. The method relies on Python's dict._contains and dict.getitem_, neither of which can fail for a valid key type. If a non-hashable key were passed, Python would raise TypeError from the dict lookup — this is not caught.

Usage Patterns

get is never called in isolation by external code. It's always called by ReadRepairStore methods in one of three patterns:

1. Version discovery during writes (ReadRepairStore.put): reads from *all* replicas (including unavailable ones) to find the max version before incrementing.

2. Quorum reads (ReadRepairStore.get): reads from R available replicas, compares versions, and triggers repair on stale ones.

3. Anti-entropy / state inspection (antientropyrepair, getreplicastates): reads from available replicas to find and fix divergence.

Dependencies

Beliefs