Skip to content

Commit

Permalink
Merge pull request #4651 from jayantjain93/debugging-snapshot-1
Browse files Browse the repository at this point in the history
CA: Debugging snapshotter locking optimisation for better transactions
  • Loading branch information
k8s-ci-robot authored Jan 27, 2022
2 parents b64d294 + a3db650 commit a393fe2
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions cluster-autoscaler/debuggingsnapshot/debugging_snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ func (d *DebuggingSnapshotterImpl) ResponseHandler(w http.ResponseWriter, r *htt
func (d *DebuggingSnapshotterImpl) IsDataCollectionAllowed() bool {
d.Mutex.Lock()
defer d.Mutex.Unlock()
return d.IsDataCollectionAllowedNoLock()
}

// IsDataCollectionAllowedNoLock encapsulated the check to know if data collection is currently active
// The need for NoLock implementation is for cases when the caller funcs have procured the lock
// for a single transactional execution
func (d *DebuggingSnapshotterImpl) IsDataCollectionAllowedNoLock() bool {
return *d.State == DATA_COLLECTED || *d.State == START_DATA_COLLECTION
}

Expand Down Expand Up @@ -211,36 +218,36 @@ func (d *DebuggingSnapshotterImpl) Flush() {
// SetClusterNodes is the setter for Node Group Info
// All filtering/prettifying of data should be done here.
func (d *DebuggingSnapshotterImpl) SetClusterNodes(nodeInfos []*framework.NodeInfo) {
if !d.IsDataCollectionAllowed() {
return
}
d.Mutex.Lock()
defer d.Mutex.Unlock()
if !d.IsDataCollectionAllowedNoLock() {
return
}
klog.V(4).Infof("NodeGroupInfo is being set for the debugging snapshot")
d.DebuggingSnapshot.SetClusterNodes(nodeInfos)
*d.State = DATA_COLLECTED
}

// SetUnscheduledPodsCanBeScheduled is the setter for UnscheduledPodsCanBeScheduled
func (d *DebuggingSnapshotterImpl) SetUnscheduledPodsCanBeScheduled(podList []*v1.Pod) {
if !d.IsDataCollectionAllowed() {
return
}
d.Mutex.Lock()
defer d.Mutex.Unlock()
if !d.IsDataCollectionAllowedNoLock() {
return
}
klog.V(4).Infof("UnscheduledPodsCanBeScheduled is being set for the debugging snapshot")
d.DebuggingSnapshot.SetUnscheduledPodsCanBeScheduled(podList)
*d.State = DATA_COLLECTED
}

// SetTemplateNodes is the setter for TemplateNodes
func (d *DebuggingSnapshotterImpl) SetTemplateNodes(templates map[string]*framework.NodeInfo) {
if !d.IsDataCollectionAllowed() {
d.Mutex.Lock()
defer d.Mutex.Unlock()
if !d.IsDataCollectionAllowedNoLock() {
return
}
klog.V(4).Infof("TemplateNodes is being set for the debugging snapshot")
d.Mutex.Lock()
defer d.Mutex.Unlock()
d.DebuggingSnapshot.SetTemplateNodes(templates)
}

Expand Down

0 comments on commit a393fe2

Please sign in to comment.