Skip to content

Commit 1f31f29

Browse files
committed
Calculate PITR node priority based on DefaultScore
1 parent 99ebe43 commit 1f31f29

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

cmd/pbm-agent/backup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ func (a *Agent) deprioritizePITRNodes(
302302

303303
// Only set if not already present (preserve previous priorities)
304304
if _, exists := coefficients[pl.Node]; !exists {
305-
coefficients[pl.Node] = 0.6 // low priority, making it a last resort
305+
coefficients[pl.Node] = prio.DefaultScore - 0.1
306306
}
307307
}
308308

pbm/prio/priority.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
)
1010

1111
const (
12-
defaultScore = 1.0
13-
scoreForPrimary = defaultScore / 2
14-
scoreForHidden = defaultScore * 2
12+
DefaultScore = 1.0
13+
scoreForPrimary = DefaultScore / 2
14+
scoreForHidden = DefaultScore * 2
1515
scoreForExcluded = 0
1616
)
1717

@@ -114,23 +114,23 @@ func CalcPriorityForNode(node *topo.NodeInfo) float64 {
114114
return scoreForHidden
115115
}
116116

117-
return defaultScore
117+
return DefaultScore
118118
}
119119

120120
// implicitPrioCalc provides priority calculation based on topology rules.
121121
// Instead of using explicitly specified priority numbers, topology rules are
122122
// applied for primary, secondary and hidden member.
123123
func implicitPrioCalc(a *topo.AgentStat, rule map[string]float64) float64 {
124124
if coeff, ok := rule[a.Node]; ok && rule != nil {
125-
return defaultScore * coeff
125+
return DefaultScore * coeff
126126
} else if a.State == defs.NodeStatePrimary {
127127
return scoreForPrimary
128128
} else if a.DelaySecs > 0 {
129129
return scoreForExcluded
130130
} else if a.Hidden {
131131
return scoreForHidden
132132
}
133-
return defaultScore
133+
return DefaultScore
134134
}
135135

136136
// explicitPrioCalc uses priority numbers from configuration to calculate
@@ -139,7 +139,7 @@ func implicitPrioCalc(a *topo.AgentStat, rule map[string]float64) float64 {
139139
func explicitPrioCalc(a *topo.AgentStat, rule map[string]float64) float64 {
140140
sc, ok := rule[a.Node]
141141
if !ok || sc < 0 {
142-
return defaultScore
142+
return DefaultScore
143143
}
144144

145145
return sc

pbm/prio/priority_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ func TestCalcPriorityForNode(t *testing.T) {
396396
}
397397

398398
p := CalcPriorityForNode(nodeInfo)
399-
if p != defaultScore {
400-
t.Errorf("wrong priority for secondary: want=%v, got=%v", defaultScore, p)
399+
if p != DefaultScore {
400+
t.Errorf("wrong priority for secondary: want=%v, got=%v", DefaultScore, p)
401401
}
402402
})
403403

@@ -470,8 +470,8 @@ func TestImplicitPrioCalc(t *testing.T) {
470470

471471
p := implicitPrioCalc(agentStat, nil)
472472

473-
if p != defaultScore {
474-
t.Errorf("wrong priority for secondary: want=%v, got=%v", defaultScore, p)
473+
if p != DefaultScore {
474+
t.Errorf("wrong priority for secondary: want=%v, got=%v", DefaultScore, p)
475475
}
476476
})
477477

0 commit comments

Comments
 (0)