Skip to content

Commit

Permalink
cache: tiny tweaks to readShard
Browse files Browse the repository at this point in the history
- acquire a read lock instead of a write lock, when context is canceled.
- add another assertion.
  • Loading branch information
sumeerbhola committed Dec 17, 2024
1 parent e12d2c0 commit 42bb0f4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/cache/read_shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ func (e *readEntry) waitForReadPermissionOrHandle(
e.mu.Unlock()
select {
case <-ctx.Done():
e.mu.Lock()
errorDuration = unlockAndUnrefAndTryRemoveFromMap(false)
e.mu.RLock()
errorDuration = unlockAndUnrefAndTryRemoveFromMap(true)
return Handle{}, errorDuration, ctx.Err()
case _, ok := <-ch:
if !ok {
Expand Down Expand Up @@ -344,6 +344,9 @@ func (e *readEntry) setReadValue(v *Value) Handle {
e.mu.Lock()
// Acquire a ref for readEntry, since we are going to remember it in e.mu.v.
v.acquire()
if e.mu.v != nil {
panic("value already set")
}
e.mu.v = v
if !e.mu.isReading {
panic("isReading is false")
Expand Down

0 comments on commit 42bb0f4

Please sign in to comment.