Skip to content

Commit

Permalink
Decouple needFullUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
wilwell committed Feb 5, 2025
1 parent 7cd5113 commit fa0e7ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
26 changes: 18 additions & 8 deletions controllers/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func canUpdateComponent(selectors []ytv1.ComponentUpdateSelector, component ytv1
case consts.ComponentGroupNothing:
return false
case consts.ComponentGroupStateful:
if component.Type == consts.DataNodeType || component.Type == consts.TabletNodeType {
if component.Type != consts.MasterType {
return true
}
case consts.ComponentGroupStateless:
Expand All @@ -52,8 +52,6 @@ func canUpdateComponent(selectors []ytv1.ComponentUpdateSelector, component ytv1
// If update is not blocked, updateMeta containing a chosen flow and the component names to update returned.
func chooseUpdatingComponents(spec ytv1.YtsaurusSpec, needUpdate []components.Component, allComponents []components.Component) (components []ytv1.Component, blockMsg string) {
configuredSelectors := getEffectiveSelectors(spec)
needFullUpdate := false

var canUpdate []ytv1.Component
var cannotUpdate []ytv1.Component

Expand All @@ -68,10 +66,6 @@ func chooseUpdatingComponents(spec ytv1.YtsaurusSpec, needUpdate []components.Co
} else {
cannotUpdate = append(cannotUpdate, component)
}
statelessCheck := canUpdateComponent([]ytv1.ComponentUpdateSelector{{ComponentGroup: consts.ComponentGroupStateless}}, component)
if !statelessCheck && component.Type != consts.DataNodeType {
needFullUpdate = true
}
}

if len(canUpdate) == 0 {
Expand All @@ -82,7 +76,8 @@ func chooseUpdatingComponents(spec ytv1.YtsaurusSpec, needUpdate []components.Co
}

if len(configuredSelectors) == 1 && configuredSelectors[0].ComponentGroup == consts.ComponentGroupEverything {
if needFullUpdate {
if needFullUpdate(needUpdate) {
// Here we update not only components that are not up-to-date, but all cluster.
return convertToComponent(allComponents), ""
} else {
return canUpdate, ""
Expand All @@ -91,6 +86,21 @@ func chooseUpdatingComponents(spec ytv1.YtsaurusSpec, needUpdate []components.Co
return canUpdate, ""
}

func needFullUpdate(needUpdate []components.Component) bool {
statelessSelector := []ytv1.ComponentUpdateSelector{{ComponentGroup: consts.ComponentGroupStateless}}
for _, comp := range needUpdate {
component := ytv1.Component{
Name: comp.GetName(),
Type: comp.GetType(),
}
isStateless := canUpdateComponent(statelessSelector, component)
if !isStateless && component.Type != consts.DataNodeType {
return true
}
}
return false
}

func getEffectiveSelectors(spec ytv1.YtsaurusSpec) []ytv1.ComponentUpdateSelector {
if len(spec.UpdateSelectors) != 0 {
return spec.UpdateSelectors
Expand Down
4 changes: 3 additions & 1 deletion pkg/consts/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const (
type ComponentGroup string

const (
ComponentGroupStateless ComponentGroup = "Stateless"
// ComponentGroupStateless group contains only stateless components (not master, data nodes, tablet nodes)
ComponentGroupStateless ComponentGroup = "Stateless"
// ComponentGroupStateful group contains every component except master
ComponentGroupStateful ComponentGroup = "Stateful"
ComponentGroupEverything ComponentGroup = "Everything"
ComponentGroupNothing ComponentGroup = "Nothing"
Expand Down

0 comments on commit fa0e7ca

Please sign in to comment.