A write-ahead log records database activity before modified data pages are persisted. After a crash, recovery distinguishes winners, which committed, from losers, whose partial effects must be undone.
Design a WALRecoveryPlanner class:
WALRecoveryPlanner() creates a stateless planner.int[] transactionsToUndo(int[][] records) returns the loser transaction IDs in ascending order.
Each record is [transactionId, type]:
type = 0: begintype = 1: updatetype = 2: commit
A transaction is a winner if any record for it has type 2. Every transaction that appears but has no commit record is a loser.
Example 1:
Input:
Output:
Explanation: Transaction 1 commits and is a winner. Transaction 2 is still in flight at the crash and must be undone.
Example 2:
Input:
Output:
Explanation: No transaction has a commit record, so every transaction is a loser. The returned IDs are sorted.
Constraints
0 <= records.length <= 10^5records[i].length == 21 <= records[i][0] <= 10^90 <= records[i][1] <= 2- At most
100 calls are made to transactionsToUndo.