Skip to content

Commit

Permalink
Updated AddPrefix to handle modeltopod and updating all related nodes…
Browse files Browse the repository at this point in the history
… together
  • Loading branch information
Gangmuk committed Feb 20, 2025
1 parent faf3b5d commit 4b768d6
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions pkg/plugins/gateway/prefixcacheindexer/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,28 @@ func (c *LPRadixCache) matchPrefixHelper(node *TreeNode, tokens []int) (*TreeNod
func (c *LPRadixCache) AddPrefix(tokens []int, model, podName string) (*TreeNode, []int, []int) {
c.mu.Lock()
defer c.mu.Unlock()

// Do insertion first
node, matchedTokens, unmatchedTokens := c.insertHelper(c.rootNode, tokens, tokens)
c.PrettyPrint()
if node != nil {
if node.ModelToPods == nil {
node.ModelToPods = make(map[string]map[string]time.Time)
}
if node.ModelToPods[model] == nil {
node.ModelToPods[model] = make(map[string]time.Time)
}
node.ModelToPods[model][podName] = time.Now()
current := node
for current.parent != nil {
if current.parent.ModelToPods == nil {
current.parent.ModelToPods = make(map[string]map[string]time.Time)
}
if current.parent.ModelToPods[model] == nil {
current.parent.ModelToPods[model] = make(map[string]time.Time)
}
current.parent.ModelToPods[model][podName] = time.Now()
current = current.parent
}
}
// c.PrettyPrint()
return node, matchedTokens, unmatchedTokens
}

Expand Down Expand Up @@ -352,7 +370,7 @@ func (c *LPRadixCache) Evict(now time.Time) []*TreeNode {
}
if len(nodesToEvict) > 0 {
klog.Infof("Evicted %d nodes", len(nodesToEvict))
c.PrettyPrint()
// c.PrettyPrint()
}
return nodesToEvict
}
Expand Down

0 comments on commit 4b768d6

Please sign in to comment.