Change Data Capture replays inserts, updates, and deletes from a durable log into a queryable view. Retries are safe only when the same log offset cannot change the view twice.
Design a CdcMaterializedView class:
boolean apply(int offset, String operation, int key, int value) applies a previously unseen offset and returns true; repeated offsets return false without changing state.int get(int key) returns the current value or -1 when absent.int size() returns the number of present keys.
operation is "upsert" or "delete". Upsert inserts or replaces. Delete removes the key and ignores value. Even deletion of an absent key consumes its new offset.
Example 1:
Example 2:
Constraints
0 <= offset, key <= 10^90 <= value <= 10^9; therefore -1 is reserved for absence.- At most
10^4 method calls are made per object. - Offsets uniquely identify log records.
- New offsets are supplied in the intended log application order; retries may repeat an earlier call.