A quorum read contacts a subset of replicas and resolves their responses to one value. In this model, a larger version is fresher. A fixed tie-break is required when two contacted replicas report the same version.
Design a QuorumReadResolver class:
QuorumReadResolver() creates a stateless resolver.int resolve(int[] versions, int[] values, int[] readSet) returns the value selected from the contacted replicas.
versions[i] and values[i] describe replica i. Consider only indices in readSet. Choose the contacted replica with the greatest version. If several contacted replicas have that version, choose the smallest replica index. Return the chosen replica's value.
Example 1:
Input:
Output:
Explanation: The read contacts replicas 0, 2, and 4 with versions 3, 2, and 1. Replica 0 has the freshest contacted version.
Example 2:
Input:
Output:
Explanation: Replicas 2 and 1 tie on version 5. The smaller replica index is 1, so the result is values[1].
Constraints
1 <= versions.length == values.length <= 10^51 <= readSet.length <= versions.length0 <= versions[i] <= 10^9-10^9 <= values[i] <= 10^9- Every
readSet[i] is a valid replica index. readSet contains no duplicate indices.- At most
100 calls are made to resolve.