Replicated systems can provide consistency guarantees for one client session without imposing a single global order on every client. Two useful guarantees are:
Design a SessionConsistencyChecker class:
SessionConsistencyChecker() creates a stateless checker.boolean isConsistent(int[][] operations) returns whether the chronological history satisfies both session guarantees.Every operation is [type, key, version]:
type = 0 records a write of version for key.type = 1 records a read of key that returned version.Track the highest version the session has observed for each key across both reads and writes. A read is invalid when its version is lower than that key's current highest observed version. Equal or newer reads are valid. Writes do not make a history invalid, but a lower-version write must not lower the remembered high-water mark.
Each call describes a separate session history. State from one call must not affect another call on the same checker.
Input:
Output:
Explanation: The session writes version 5 of key 1 and then reads version 5. The read sees the session's own write, so the history is consistent.
Input:
Output:
Explanation: The first read raises key 1's high-water mark to 3, and the write raises it to 5. The final read returns version 4, which is older than the session's own version 5, so the history violates read-your-writes.
0 <= operations.length <= 200operations[i].length == 3operations[i][0] is either 0 (write) or 1 (read).0 <= operations[i][1], operations[i][2] <= 10^9100 calls are made to isConsistent.| Call | Returns |
|---|---|
| new SessionConsistencyChecker() | null |
| isConsistent([[0,1,5],[1,1,5]]) | true |
The session writes version 5 of key 1 and then reads the same version, so read-your-writes is satisfied.
Run checks these cases. Submit also runs a larger hidden set.

