WAL Log Enrichment
EasyData Processing · Netflix
A service replays its write-ahead log (WAL) to rebuild an analytics table. Because of retries, the same log sequence number (LSN) can be delivered more than once, and entries can arrive out of order.
entriesis a list of[lsn, user_id, action]rows in arrival order (lsnis an integer;user_idandactionare strings).profilesis a list of[user_id, tier]rows. If a user appears more than once, the last row for that user is the current tier.
Build the cleaned log:
- For each
lsn, keep only the first entry that arrived with it; later entries with the samelsnare discarded, even if their contents differ. - Append the user's tier to each kept entry, giving
[lsn, user_id, action, tier]. Use the string"unknown"if the user has no profile. - Return the rows sorted by increasing
lsn.
Example 1
- Input:
- entries = [[12, "u7", "play"], [10, "u2", "pause"], [12, "u9", "seek"], [11, "u7", "stop"]], profiles = [["u7", "basic"], ["u2", "premium"], ["u7", "standard"]]
- Output:
- [[10, "u2", "pause", "premium"], [11, "u7", "stop", "standard"], [12, "u7", "play", "standard"]]
- Explanation
- LSN 12 arrives twice; the first copy (
u7,play) is kept and theseekcopy is discarded.u7has two profile rows, and the later one,standard, wins. The kept rows are then ordered 10, 11, 12.
Example 2
- Input:
- entries = [[3, "u1", "play"], [1, "u5", "play"]], profiles = [["u1", "premium"]]
- Output:
- [[1, "u5", "play", "unknown"], [3, "u1", "play", "premium"]]
- Explanation
u5has no profile, so its tier is"unknown". The output is sorted by LSN even though LSN 3 arrived first.
Constraints
- 0 ≤ entries.length, profiles.length ≤ 2 * 105
- 0 ≤ lsn ≤ 1012
- All ids, actions and tiers are strings.