Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions pkg/epp/scheduling/framework/plugins/multi/prefix/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ func (i *indexer) Get(hash BlockHash) podSet {
i.mu.RLock()
defer i.mu.RUnlock()

res := podSet{}
pods, ok := i.hashToPods[hash]
if !ok {
return res
pods := i.hashToPods[hash]
res := make(podSet, len(pods))
for pod := range pods {
// Deep copy to avoid race condition.
res[pod] = struct{}{}
}

return pods
return res
}

// makeEvictionFn returns a per-pod LRU eviction callback that removes the pod from hashToPods on eviction.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ func TestIndexer_AddAndGet(t *testing.T) {
// Add another entry to the cache, which should evict the first one due to max size.
i.Add([]BlockHash{BlockHash(3)}, server)
assert.Equal(t, 2, i.podToLRU[server].Len(), "Cache size should still be 2 after adding an entry")

servers = i.Get(BlockHash(4))
assert.Empty(t, servers, "Cache should not contain non-existent hash")
}