Skip to content

Commit 5e1e26b

Browse files
authored
Bug fix: Fix LearnedParameters race condition (#943)
* Add shuynh2017 to the OWNERS list * Bug fix: fix LearnedParameters race condition
1 parent b745c47 commit 5e1e26b

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ vet: ## Run go vet against code.
9191

9292
.PHONY: test
9393
test: manifests generate fmt vet setup-envtest helm ## Run tests.
94-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" PATH=$(LOCALBIN):$(PATH) go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
94+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" PATH="$(LOCALBIN):$(PATH)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
9595

9696
# Creates a multi-node Kind cluster
9797
# Adds emulated GPU labels and capacities per node

internal/engines/analyzers/queueingmodel/parameters.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,52 @@ type LearnedParameters struct {
2424
LastUpdated time.Time
2525
}
2626

27+
// DeepCopy creates a deep copy of LearnedParameters
28+
func (lp *LearnedParameters) deepCopy() *LearnedParameters {
29+
if lp == nil {
30+
return nil
31+
}
32+
33+
copied := &LearnedParameters{
34+
Alpha: lp.Alpha,
35+
Beta: lp.Beta,
36+
Gamma: lp.Gamma,
37+
NIS: lp.NIS,
38+
LastUpdated: lp.LastUpdated,
39+
}
40+
41+
// Deep copy the Covariance matrix
42+
if lp.Covariance != nil {
43+
copied.Covariance = make([][]float64, len(lp.Covariance))
44+
for i := range lp.Covariance {
45+
if lp.Covariance[i] != nil {
46+
copied.Covariance[i] = make([]float64, len(lp.Covariance[i]))
47+
copy(copied.Covariance[i], lp.Covariance[i])
48+
}
49+
}
50+
}
51+
52+
return copied
53+
}
54+
2755
// NewParameterStore creates a new parameter store
2856
func NewParameterStore() *ParameterStore {
2957
return &ParameterStore{
3058
params: make(map[string]*LearnedParameters),
3159
}
3260
}
3361

34-
// Get retrieves parameters for a variant (nil if does not exist)
62+
// Get retrieves a deep copy of parameters for a variant (nil if does not exist)
3563
func (s *ParameterStore) Get(namespace, variantName string) *LearnedParameters {
3664
s.mu.RLock()
3765
defer s.mu.RUnlock()
3866
key := makeVariantKey(namespace, variantName)
39-
return s.params[key]
67+
params := s.params[key]
68+
if params == nil {
69+
return nil
70+
}
71+
// Return a deep copy to avoid race conditions on Covariance slice
72+
return params.deepCopy()
4073
}
4174

4275
// Set stores parameters for a variant (overrides any earlier parameters)

0 commit comments

Comments
 (0)