Skip to content

Commit 2cfbff6

Browse files
committed
refactor: Allow export prefix SchedulingContextState for use across plugins
Signed-off-by: Kfir Toledo <kfir.toledo@ibm.com>
1 parent fe5dea3 commit 2cfbff6

File tree

1 file changed

+9
-9
lines changed
  • pkg/epp/scheduling/framework/plugins/multi/prefix

1 file changed

+9
-9
lines changed

pkg/epp/scheduling/framework/plugins/multi/prefix/plugin.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,25 @@ func (s ServerID) String() string {
9090
}
9191

9292
// compile-time type validation
93-
var _ types.StateData = &schedulingContextState{}
93+
var _ types.StateData = &SchedulingContextState{}
9494

95-
// This is the state of this plugin to be used during a scheduling cycle.
96-
type schedulingContextState struct {
95+
// SchedulingContextState is the state of this plugin to be used during a scheduling cycle.
96+
type SchedulingContextState struct {
9797
// PrefixHashes is a list of prefix hashes of the request prompt broken into blocks.
9898
PrefixHashes []BlockHash
9999
// A map of server to its longest prefix cache match length.
100100
PrefixCacheServers map[ServerID]int
101101
}
102102

103-
func (s *schedulingContextState) Clone() types.StateData {
103+
func (s *SchedulingContextState) Clone() types.StateData {
104104
prefixHashes := make([]BlockHash, len(s.PrefixHashes))
105105
copy(prefixHashes, s.PrefixHashes)
106106
prefixCacheServers := make(map[ServerID]int, len(s.PrefixCacheServers))
107107
for key, value := range s.PrefixCacheServers {
108108
prefixCacheServers[key] = value
109109
}
110110

111-
return &schedulingContextState{
111+
return &SchedulingContextState{
112112
PrefixHashes: prefixHashes,
113113
PrefixCacheServers: prefixCacheServers,
114114
}
@@ -171,7 +171,7 @@ func (m *Plugin) Score(ctx context.Context, cycleState *types.CycleState, reques
171171
loggerTrace := log.FromContext(ctx).V(logutil.TRACE)
172172
// pre score step, hashing prompt and find longest prefix match.
173173
hashes := hashPrompt(ctx, request, m.HashBlockSize, m.MaxPrefixBlocksToMatch)
174-
state := &schedulingContextState{
174+
state := &SchedulingContextState{
175175
PrefixHashes: hashes,
176176
PrefixCacheServers: m.matchLongestPrefix(ctx, hashes),
177177
}
@@ -235,15 +235,15 @@ func (m *Plugin) matchLongestPrefix(ctx context.Context, hashes []BlockHash) map
235235
return res
236236
}
237237

238-
// getPrefixState returns the cycle state as a schedulingContextState.
239-
func (m *Plugin) getPrefixState(cycleState *types.CycleState) (*schedulingContextState, error) {
238+
// getPrefixState returns the cycle state as a SchedulingContextState.
239+
func (m *Plugin) getPrefixState(cycleState *types.CycleState) (*SchedulingContextState, error) {
240240
prefixStateKey := types.StateKey(m.Type())
241241
state, err := cycleState.Read(prefixStateKey)
242242
if err != nil {
243243
return nil, fmt.Errorf("failed reading %q from CycleState: %w", prefixStateKey, err)
244244
}
245245

246-
prefixSchedulingState, ok := state.(*schedulingContextState)
246+
prefixSchedulingState, ok := state.(*SchedulingContextState)
247247
if !ok {
248248
return nil, fmt.Errorf("invalid Prefix state, got type %T", state)
249249
}

0 commit comments

Comments
 (0)