stream: include the namespace in the snap cache key

Otherwise the wrong snapshot could be returned when the same key is used in different namespaces
This commit is contained in:
Daniel Nephin 2020-10-21 16:33:46 -04:00
parent c42fe5ae43
commit 0ad2406d7c
1 changed files with 7 additions and 3 deletions

View File

@ -267,7 +267,7 @@ func (e *EventPublisher) getCachedSnapshotLocked(req *SubscribeRequest) *eventSn
e.snapCache[req.Topic] = topicSnaps
}
snap, ok := topicSnaps[req.Key]
snap, ok := topicSnaps[snapCacheKey(req)]
if ok && snap.err() == nil {
return snap
}
@ -279,12 +279,16 @@ func (e *EventPublisher) setCachedSnapshotLocked(req *SubscribeRequest, snap *ev
if e.snapCacheTTL == 0 {
return
}
e.snapCache[req.Topic][req.Key] = snap
e.snapCache[req.Topic][snapCacheKey(req)] = snap
// Setup a cache eviction
time.AfterFunc(e.snapCacheTTL, func() {
e.lock.Lock()
defer e.lock.Unlock()
delete(e.snapCache[req.Topic], req.Key)
delete(e.snapCache[req.Topic], snapCacheKey(req))
})
}
func snapCacheKey(req *SubscribeRequest) string {
return fmt.Sprintf(req.Namespace + "/" + req.Key)
}