Skip to content

Instantly share code, notes, and snippets.

@arriqaaq
Last active June 6, 2024 08:27
Show Gist options
  • Save arriqaaq/9605df8ee9129c4a53ed4ea9ac62eaaf to your computer and use it in GitHub Desktop.
Save arriqaaq/9605df8ee9129c4a53ed4ea9ac62eaaf to your computer and use it in GitHub Desktop.
graph TD
    A[Start of a Transaction] --> B[Assign Read TS]
    B --> C[Reading from a Snapshot]
    C --> D[Perform Read Operation]
    D --> E{TS <= Read TS?}
    E -- Yes --> F[Return Committed Data]
    E -- No --> G[Ignore Uncommitted Data]
    A --> H[Writing with Snapshot Isolation]
    H --> I[Check Memtable for Conflicts]
    I --> J{Newer Version Exists?}
    J -- Yes --> K[Abort Transaction]
    J -- No --> L[Commit Write Set]
    L --> M[Add to Memtable]
    F --> N[Multiple Readers, Consistent View]
    M --> O[Garbage Collection]
    O --> P[Periodic Cleaning of Older Records]
    P --> Q[Reclaim Space]
Loading
sequenceDiagram
    participant Client
    participant Transaction Manager
    participant Memtable
    participant Raft Store

    Client->>Transaction Manager: Start Transaction
    Transaction Manager->>Transaction Manager: Assign read ts (timestamp)

    loop For each read operation
        Client->>Transaction Manager: Read(key)
        Transaction Manager->>Raft Store: Get(key, read ts)
        Raft Store-->>Transaction Manager: Return value (≤ read ts)
        Transaction Manager-->>Client: Return value
    end

    Client->>Transaction Manager: Write(key, value)

    Client->>Transaction Manager: Commit Transaction
    loop For each key in write set
        Transaction Manager->>Memtable: Get(key, read ts)
        Memtable-->>Transaction Manager: Return latest ts for key
        alt ts > read ts
            Transaction Manager-->>Client: Abort Transaction
        else ts ≤ read ts
            Transaction Manager->>Memtable: Add to write set
        end
    end

    Transaction Manager->>Memtable: Commit write set
    Memtable->>Raft Store: Persist committed data

    note over Memtable: Periodic Garbage Collection
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment