Consumers can process records from one partition concurrently, so acknowledgments may arrive out of order. Committing past a gap is unsafe: after a restart, the missing record would appear complete and might never be delivered again.
Design a PartitionOffsetTracker class:
PartitionOffsetTracker(int partitions) creates partitions numbered 0 through partitions - 1. Every committed offset starts at -1.int ack(int partition, int offset) records a successful acknowledgment and returns that partition's committed offset.
The committed offset is the greatest c for which every offset from 0 through c has been acknowledged. Acknowledgments may arrive in any order and may be repeated. State is independent across partitions, and committed offsets never decrease.
Example 1:
Input:
Output:
Explanation: Offset 1 waits for 0. Later, offset 3 waits for 2. Partition 1 advances independently.
Example 2:
Input:
Output:
Explanation: The repeated acknowledgment of offset 0 is harmless.
Constraints
1 <= partitions <= 1000 <= partition < partitions0 <= offset <= 10^9- At most
10^5 calls are made to ack.