Spot the bug
Workers write reports to storage. Which line lets a stale leader overwrite newer data?
class Storage:def __init__(self) -> None:self.highest = 0self.data = ""def write(self, token: int, value: str) -> None:self.highest = max(self.highest, token)self.data = values = Storage()s.write(34, "from new leader")s.write(33, "from paused old leader")print(s.data)
Hint 1 of 1
Which line should depend on the token?
Choose an answer, then open Show answer below to check it.
Show answer
- Answer: line 8
self.data = value
The write is accepted no matter the token. It should reject token < self.highest before writing, so the old leader's write with token 33 fails.