Skip to content

Commit

Permalink
feat: max-static-node-id
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorres committed Jun 27, 2024
1 parent a41cd39 commit 06eba36
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
)

func NewRunCmd() *cobra.Command {
restartOpts := options.RestartOptionsInstance
rootOpts := options.RootOptionsInstance
restartOpts := options.RestartOptionsInstance
restarter := restarters.NewRunRestarter(options.Logger)

cmd := cli.SetDefaultsOn(&cobra.Command{
Expand Down
11 changes: 11 additions & 0 deletions pkg/options/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
DefaultRetryCount = 3
DefaultRestartDurationSeconds = 60
DefaultCMSQueryIntervalSeconds = 10
DefaultMaxStaticNodeId = 50000
)

var AvailabilityModes = []string{"strong", "weak", "force"}
Expand Down Expand Up @@ -62,6 +63,8 @@ type RestartOptions struct {

KubeconfigPath string
K8sNamespace string

MaxStaticNodeId int
}

var (
Expand All @@ -81,6 +84,10 @@ func (o *RestartOptions) Validate() error {
return fmt.Errorf("specified --kubeconfig, but not --k8s-namespace")
}

if o.MaxStaticNodeId < 0 {
return fmt.Errorf("specified invalid max-static-node-id: %d. Must be positive", o.MaxStaticNodeId)
}

if o.RestartDuration < 0 {
return fmt.Errorf("specified invalid restart duration seconds: %d. Must be positive", o.RestartDuration)
}
Expand Down Expand Up @@ -204,6 +211,10 @@ after that would be considered a regular cluster failure`)
for this invocation must be the same as for the previous invocation, and this can not be verified at runtime since
the ydbops utility is stateless. Use at your own risk.`)

fs.IntVar(&o.MaxStaticNodeId, "max-static-node-id", DefaultMaxStaticNodeId,
`This argument is used to help ydbops distinguish storage and dynamic nodes.
Nodes with this nodeId or less will be considered storage.`)

profile.PopulateFromProfileLater(
fs.StringVar, &o.KubeconfigPath, "kubeconfig",
"",
Expand Down
1 change: 1 addition & 0 deletions pkg/rolling/restarters/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ type FilterNodeParams struct {
SelectedTenants []string
SelectedNodeIds []uint32
SelectedHosts []string
MaxStaticNodeId uint32
}
4 changes: 2 additions & 2 deletions pkg/rolling/restarters/primitives.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
"github.com/ydb-platform/ydbops/pkg/options"
)

func FilterStorageNodes(nodes []*Ydb_Maintenance.Node) []*Ydb_Maintenance.Node {
func FilterStorageNodes(nodes []*Ydb_Maintenance.Node, maxStaticNodeId uint32) []*Ydb_Maintenance.Node {
return collections.FilterBy(nodes,
func(node *Ydb_Maintenance.Node) bool {
return node.GetStorage() != nil
return node.GetStorage() != nil && node.NodeId < maxStaticNodeId
},
)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/rolling/restarters/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (r *RunRestarter) Filter(spec FilterNodeParams, cluster ClusterNodesInfo) [
var runScopeNodes []*Ydb_Maintenance.Node

if r.storageOnly {
storageNodes := FilterStorageNodes(cluster.AllNodes)
storageNodes := FilterStorageNodes(cluster.AllNodes, spec.MaxStaticNodeId)
runScopeNodes = PopulateByCommonFields(storageNodes, spec)
} else if r.dynnodeOnly {
tenantNodes := FilterTenantNodes(cluster.AllNodes)
Expand Down
2 changes: 1 addition & 1 deletion pkg/rolling/restarters/storage_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (r *StorageK8sRestarter) Filter(

r.prepareK8sState(r.Opts.kubeconfigPath, storageLabelSelector, r.Opts.namespace)

allStorageNodes := FilterStorageNodes(cluster.AllNodes)
allStorageNodes := FilterStorageNodes(cluster.AllNodes, spec.MaxStaticNodeId)

selectedNodes := populateWithK8sRules(allStorageNodes, spec, r.FQDNToPodName)

Expand Down
2 changes: 1 addition & 1 deletion pkg/rolling/restarters/storage_ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (r StorageSSHRestarter) Filter(
spec FilterNodeParams,
cluster ClusterNodesInfo,
) []*Ydb_Maintenance.Node {
storageNodes := FilterStorageNodes(cluster.AllNodes)
storageNodes := FilterStorageNodes(cluster.AllNodes, spec.MaxStaticNodeId)

preSelectedNodes := PopulateByCommonFields(storageNodes, spec)

Expand Down
1 change: 1 addition & 0 deletions pkg/rolling/rolling.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (r *Rolling) DoRestart() error {
StartedTime: r.opts.StartedTime,
Version: r.opts.VersionSpec,
ExcludeHosts: r.opts.ExcludeHosts,
MaxStaticNodeId: uint32(r.opts.MaxStaticNodeId),
},
restarters.ClusterNodesInfo{
TenantToNodeIds: r.state.tenantNameToNodeIds,
Expand Down
6 changes: 4 additions & 2 deletions tests/filtering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var _ = Describe("Test storage Filter", func() {
nodes := mock.CreateNodesFromShortConfig(nodeGroups, nodeInfoMap)

filterSpec := restarters.FilterNodeParams{
MaxStaticNodeId: options.DefaultMaxStaticNodeId,
StartedTime: &options.StartedTime{
Direction: '<',
Timestamp: fiveMinutesAgoTimestamp,
Expand Down Expand Up @@ -89,8 +90,9 @@ var _ = Describe("Test storage Filter", func() {

nodes := mock.CreateNodesFromShortConfig(nodeGroups, nodeInfoMap)

// empty params equivalent to no arguments
filterSpec := restarters.FilterNodeParams{}
filterSpec := restarters.FilterNodeParams{
MaxStaticNodeId: options.DefaultMaxStaticNodeId,
}

clusterInfo := restarters.ClusterNodesInfo{
AllNodes: nodes,
Expand Down
1 change: 0 additions & 1 deletion tests/run_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func RunTestCase(tc TestCase) {
),
)
maintenanceTaskId = uuidOnlyRegexp.FindString(output)
fmt.Printf("DETERMINED taskId %s\n", maintenanceTaskId)
}

r := regexp.MustCompile(expectedOutputRegexp)
Expand Down

0 comments on commit 06eba36

Please sign in to comment.