Multi-version concurrency control keeps old row versions so readers can use a stable snapshot without blocking writers. Each version records the transaction that created it and, when applicable, the transaction that deleted it.
Design an MVCCVisibilityChecker class:
MVCCVisibilityChecker() creates a stateless checker.boolean isVisible(int xmin, int xmax, int snapshotXid, int[] activeXids) returns whether one row version appears in the snapshot.
For this exercise, a transaction ID t is committed and visible to the reader exactly when:
The row version is visible only when its creator xmin is committed and visible, and it has not been deleted from this snapshot. xmax = 0 means there is no deleting transaction. Otherwise, a visible deleting transaction hides the row.
Example 1:
Input:
Output:
Explanation: Transaction 5 committed before the snapshot. Transaction 8 is still active, so the snapshot cannot see its delete and the row remains visible.
Example 2:
Input:
Output:
Explanation: Both transaction 5 and transaction 6 committed before the snapshot. Because the delete is visible, the version is not.
Constraints
1 <= xmin, snapshotXid <= 10^90 <= xmax <= 10^90 <= activeXids.length <= 10^5- Every value in
activeXids is unique. xmax = 0 means the version was never deleted.- At most
100 calls are made to isVisible.