A log-shipping sidecar reads an ordered local stream and forwards bounded batches. It must not advance its checkpoint until the remote logging backend acknowledges a batch, otherwise a failed delivery silently loses logs.
Design a LogShippingSidecar class:
LogShippingSidecar(batchSize) creates an empty sidecar.append(logId) adds a new log id and returns false if that id has ever been appended to this object.flush(acknowledged) returns the next batch attempted.pending() returns every unacknowledged id in append order.checkpoint() returns the cumulative number of acknowledged records.
The next batch is the oldest unacknowledged prefix containing at most batchSize records. flush returns that batch whether delivery succeeds or fails. When acknowledged is true, advance past the returned records. When it is false, change nothing so the exact batch is retried later. Flushing an empty buffer returns an empty array.
Ids remain reserved after acknowledgement; a duplicate append never creates a second record.
Example 1:
Example 2:
Constraints
1 <= batchSize <= 10^5- Log ids contain
1 to 80 printable non-space characters. - At most
10^5 successful appends and 10^5 method calls exist per object.