-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suppose that a reader thread is trying to cache an object that it just read, while a writer thread is trying to cache an object that it just wrote. The writer thread definitionally has the latest version. The reader thread may be out of date. While we previously took some care to not replace a new version with an old version, this did not take into account evictions, and so the following bug was possible: READER WRITER read object_by_id_cache (miss) read dirty set (miss) write to dirty read db (old version) write to cache (while holding dirty lock) cache entry is evicted write to cache There is no way for the reader to tell that the value is is caching is out of date, because the update to date entry is already gone from the cache. We fix this by requiring reader threads to obtain a ticket before they read from the dirty set and/or db. Tickets are expired by writers. Then, the above case looks like this: READER WRITER get ticket read cache (miss) read dirty (miss) write dirty read db (old version) expire ticket write cache (while holding dirty lock) cache eviction no write to cache (ticket expired) Any interleaving of the above either results in the reader seeing a recent version, or else having an expired ticket.
- Loading branch information
1 parent
533043d
commit e8d07f3
Showing
4 changed files
with
216 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.