Design a Distributed Cache (Memcache), stage 4 of 9: break it
Write the lease-aware read
The cache's get now returns one of three things: a value, a lease token (you should refill), or "wait" (someone else is refilling). setWithLease returns false if the token was invalidated. Write the web server's read helper.
System so far· 5 parts
Select a component to see what it is responsible for and which state it owns.
- 1Users → Web servers: Page request
- 2Web servers → mcrouter: get / multiget, delete
- 3mcrouter → memcached pool: Keys by consistent hash
- 4Web servers → MySQL: Query on miss; writes
What you need to know
0 of 2 checks done
A lease-aware
getreturns one of three results, and the client has a branch for each:Result Meaning Client does hit the value return it lease you should refill load from the database, set with the token wait someone else is refilling sleep briefly, ask again Check
The client loads the value and its setWithLease returns false (a delete invalidated the token). What should it return to its caller?Think first
The web server holding the lease crashes before refilling. What happens to the clients told to 'wait'?