Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix maintenance duration with delays #65

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/rolling/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rolling

import (
"fmt"
"math"
"time"

"github.com/spf13/pflag"
Expand Down Expand Up @@ -101,6 +102,11 @@ ydbops will try to figure out if you broke this rule by comparing before\after o
`Delay between two consecutive restarts. E.g. '60s', '2m'. The number of simultaneous restarts is limited by 'nodes-inflight'.`)
}

func (o *RestartOptions) GetRestartDuration() *durationpb.Duration {
return durationpb.New(time.Second * time.Duration(o.RestartDuration) * time.Duration(o.RestartRetryNumber))
func (o *RestartOptions) GetRestartDuration(nNodes int) *durationpb.Duration {
singleBatchRestartTime := time.Second * time.Duration(o.RestartDuration) * time.Duration(o.RestartRetryNumber)
singleBatchWithWait := singleBatchRestartTime + o.DelayBetweenRestarts
maximumTotalBatches := int(math.Ceil(float64(nNodes) / float64(o.NodesInflight)))

finalDuration := time.Duration(maximumTotalBatches) * singleBatchWithWait
return durationpb.New(finalDuration)
}
2 changes: 1 addition & 1 deletion pkg/rolling/rolling.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (r *Rolling) DoRestart() error {
taskParams := cms.MaintenanceTaskParams{
TaskUID: r.state.restartTaskUID,
AvailabilityMode: r.opts.GetAvailabilityMode(),
Duration: r.opts.GetRestartDuration(),
Duration: r.opts.GetRestartDuration(len(nodesToRestart)),
ScopeType: cms.NodeScope,
Nodes: nodesToRestart,
}
Expand Down
5 changes: 3 additions & 2 deletions tests/maintenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tests
import (
"fmt"
"path/filepath"
"time"

. "github.com/onsi/ginkgo/v2"
"github.com/ydb-platform/ydb-go-genproto/draft/protos/Ydb_Maintenance"
Expand Down Expand Up @@ -49,7 +50,7 @@ var _ = Describe("Test Maintenance", func() {
Description: "Rolling restart maintenance task",
AvailabilityMode: Ydb_Maintenance.AvailabilityMode_AVAILABILITY_MODE_STRONG,
},
ActionGroups: mock.MakeActionGroupsFromHostFQDNs("ydb-1.ydb.tech", "ydb-2.ydb.tech"),
ActionGroups: mock.MakeActionGroupsFromHostFQDNsFixedDuration(time.Second * 180, "ydb-1.ydb.tech", "ydb-2.ydb.tech"),
},
},
expectedOutputRegexps: []string{
Expand Down Expand Up @@ -237,7 +238,7 @@ var _ = Describe("Test Maintenance", func() {
Description: "Rolling restart maintenance task",
AvailabilityMode: Ydb_Maintenance.AvailabilityMode_AVAILABILITY_MODE_STRONG,
},
ActionGroups: mock.MakeActionGroupsFromNodeIds(1, 2),
ActionGroups: mock.MakeActionGroupsFromNodesIdsFixedDuration(time.Second * 180, 1, 2),
},
},
expectedOutputRegexps: []string{
Expand Down
64 changes: 62 additions & 2 deletions tests/mock/cms-nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,41 @@ func makeNode(nodeID uint32) *Ydb_Maintenance.Node {
}
}

func determineRestartDuration(nNodes int) time.Duration {
defaultRestartDuration := time.Second * 60
singleBatchRestartTime := defaultRestartDuration * 3

singleBatchWithWait := singleBatchRestartTime + 1*time.Second
maximumTotalBatches := nNodes

return time.Duration(maximumTotalBatches) * singleBatchWithWait
}

func MakeActionGroupsFromNodesIdsFixedDuration(duration time.Duration, nodeIDs ...uint32) []*Ydb_Maintenance.ActionGroup {
result := []*Ydb_Maintenance.ActionGroup{}
for _, nodeID := range nodeIDs {
result = append(result,
&Ydb_Maintenance.ActionGroup{
Actions: []*Ydb_Maintenance.Action{
{
Action: &Ydb_Maintenance.Action_LockAction{
LockAction: &Ydb_Maintenance.LockAction{
Scope: &Ydb_Maintenance.ActionScope{
Scope: &Ydb_Maintenance.ActionScope_NodeId{
NodeId: nodeID,
},
},
Duration: durationpb.New(duration),
},
},
},
},
},
)
}
return result
}

func MakeActionGroupsFromNodeIds(nodeIDs ...uint32) []*Ydb_Maintenance.ActionGroup {
result := []*Ydb_Maintenance.ActionGroup{}
for _, nodeID := range nodeIDs {
Expand All @@ -50,7 +85,32 @@ func MakeActionGroupsFromNodeIds(nodeIDs ...uint32) []*Ydb_Maintenance.ActionGro
NodeId: nodeID,
},
},
Duration: durationpb.New(180 * time.Second),
Duration: durationpb.New(determineRestartDuration(len(nodeIDs))),
},
},
},
},
},
)
}
return result
}

func MakeActionGroupsFromHostFQDNsFixedDuration(duration time.Duration, hostFQDNs ...string) []*Ydb_Maintenance.ActionGroup {
result := []*Ydb_Maintenance.ActionGroup{}
for _, hostFQDN := range hostFQDNs {
result = append(result,
&Ydb_Maintenance.ActionGroup{
Actions: []*Ydb_Maintenance.Action{
{
Action: &Ydb_Maintenance.Action_LockAction{
LockAction: &Ydb_Maintenance.LockAction{
Scope: &Ydb_Maintenance.ActionScope{
Scope: &Ydb_Maintenance.ActionScope_Host{
Host: hostFQDN,
},
},
Duration: durationpb.New(duration),
},
},
},
Expand All @@ -75,7 +135,7 @@ func MakeActionGroupsFromHostFQDNs(hostFQDNs ...string) []*Ydb_Maintenance.Actio
Host: hostFQDN,
},
},
Duration: durationpb.New(180 * time.Second),
Duration: durationpb.New(determineRestartDuration(len(hostFQDNs))),
},
},
},
Expand Down
Loading