Skip to content

Commit 3599c3e

Browse files
committed
addressed review comments: namings, import ordering and minor refactoring
Signed-off-by: Maroon Ayoub <[email protected]>
1 parent b1a572b commit 3599c3e

File tree

9 files changed

+9
-13
lines changed

9 files changed

+9
-13
lines changed

examples/kv-cache-aware-scorer/kvcache-aware-scorer.go renamed to examples/kv-cache-aware-scorer/kvcache_aware_scorer.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ import (
2323
"fmt"
2424
"os"
2525

26-
"github.com/llm-d/llm-d-kv-cache-manager/pkg/kvcache"
27-
2826
"sigs.k8s.io/controller-runtime/pkg/log"
2927
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins"
3028
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/types"
31-
3229
logutil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/logging"
30+
31+
"github.com/llm-d/llm-d-kv-cache-manager/pkg/kvcache"
3332
)
3433

3534
const (

examples/kv-cache-index/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import (
2121
"os"
2222
"time"
2323

24-
"github.com/llm-d/llm-d-kv-cache-manager/pkg/kvcache"
25-
2624
"k8s.io/klog/v2"
25+
26+
"github.com/llm-d/llm-d-kv-cache-manager/pkg/kvcache"
2727
)
2828

2929
/*

pkg/kvcache/kvblock/in-memory.go renamed to pkg/kvcache/kvblock/in_memory.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package kvblock
1919
import (
2020
"context"
2121
"fmt"
22-
"time"
2322

2423
lru "github.com/hashicorp/golang-lru/v2"
2524
"k8s.io/apimachinery/pkg/util/sets"
@@ -80,7 +79,7 @@ var _ Index = &InMemoryIndex{}
8079
type PodCache struct {
8180
// cache is an LRU cache that maps PodEntry to their last access time.
8281
// thread-safe.
83-
cache *lru.Cache[PodEntry, time.Time]
82+
cache *lru.Cache[PodEntry, struct{}]
8483
}
8584

8685
// Lookup receives a list of keys and a set of pod identifiers,
@@ -148,22 +147,20 @@ func (m *InMemoryIndex) Add(ctx context.Context, keys []Key, entries []PodEntry)
148147
for _, key := range keys {
149148
podCache, found := m.data.Get(key) // bumps LRU timestamp if found
150149
if !found {
151-
cache, err := lru.New[PodEntry, time.Time](m.podCacheSize)
150+
cache, err := lru.New[PodEntry, struct{}](m.podCacheSize)
152151
if err != nil {
153152
return fmt.Errorf("failed to create pod cache for key %s: %w", key.String(), err)
154153
}
155154

156155
podCache = &PodCache{
157156
cache: cache,
158157
}
159-
}
160158

161-
for _, entry := range entries {
162-
podCache.cache.Add(entry, time.Now()) // TODO: can this be batched to avoid multiple locks?
159+
m.data.ContainsOrAdd(key, podCache)
163160
}
164161

165-
if !found {
166-
m.data.Add(key, podCache) // TODO: conflicts here can lead to lost updates, fix locking
162+
for _, entry := range entries {
163+
podCache.cache.Add(entry, struct{}{}) // TODO: can this be batched to avoid multiple locks?
167164
}
168165

169166
traceLogger.Info("added pods to key", "key", key, "pods", entries)
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)