Skip to content

Commit 0cd5a2a

Browse files
authored
GT-457 [Feature] Rebalancer V2 (#1345)
1 parent a7b5e47 commit 0cd5a2a

25 files changed

+938
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- (Feature) Agency Improvements
77
- (Bugfix) Fix agency timeout
88
- (Improvement) Extract Agency Timeout
9+
- (Feature) Rebalancer V2
910

1011
## [1.2.30](https://github.com/arangodb/kube-arangodb/tree/1.2.30) (2023-06-16)
1112
- (Feature) AgencyCache Interface

docs/generated/actions.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@
4545
| PVCResized | no | 15m0s | no | Community & Enterprise | Waits for PVC resize to be completed |
4646
| PlaceHolder | no | 10m0s | no | Community & Enterprise | Empty placeholder action |
4747
| RebalancerCheck | no | 10m0s | no | Enterprise Only | Check Rebalancer job progress |
48+
| RebalancerCheckV2 | no | 10m0s | no | Community & Enterprise | Check Rebalancer job progress |
4849
| RebalancerClean | no | 10m0s | no | Enterprise Only | Cleans Rebalancer jobs |
50+
| RebalancerCleanV2 | no | 10m0s | no | Community & Enterprise | Cleans Rebalancer jobs |
4951
| RebalancerGenerate | yes | 10m0s | no | Enterprise Only | Generates the Rebalancer plan |
52+
| RebalancerGenerateV2 | yes | 10m0s | no | Community & Enterprise | Generates the Rebalancer plan |
5053
| RebuildOutSyncedShards | no | 24h0m0s | no | Community & Enterprise | Run Rebuild Out Synced Shards procedure for DBServers |
5154
| RecreateMember | no | 15m0s | no | Community & Enterprise | Recreate member with same ID and Data |
5255
| RefreshTLSKeyfileCertificate | no | 30m0s | no | Enterprise Only | Recreate Server TLS Certificate secret |
@@ -134,8 +137,11 @@ spec:
134137
PVCResized: 15m0s
135138
PlaceHolder: 10m0s
136139
RebalancerCheck: 10m0s
140+
RebalancerCheckV2: 10m0s
137141
RebalancerClean: 10m0s
142+
RebalancerCleanV2: 10m0s
138143
RebalancerGenerate: 10m0s
144+
RebalancerGenerateV2: 10m0s
139145
RebuildOutSyncedShards: 24h0m0s
140146
RecreateMember: 15m0s
141147
RefreshTLSKeyfileCertificate: 30m0s

internal/actions.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@ actions:
232232
RebalancerClean:
233233
enterprise: true
234234
description: Cleans Rebalancer jobs
235+
RebalancerGenerateV2:
236+
description: Generates the Rebalancer plan
237+
isInternal: true
238+
RebalancerCheckV2:
239+
description: Check Rebalancer job progress
240+
RebalancerCleanV2:
241+
description: Cleans Rebalancer jobs
235242
ResourceSync:
236243
description: Runs the Resource sync
237244
TimezoneSecretSet:

pkg/apis/deployment/v1/actions.generated.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,16 @@ const (
105105
ActionPlaceHolderDefaultTimeout time.Duration = ActionsDefaultTimeout
106106
// ActionRebalancerCheckDefaultTimeout define default timeout for action ActionRebalancerCheck
107107
ActionRebalancerCheckDefaultTimeout time.Duration = ActionsDefaultTimeout
108+
// ActionRebalancerCheckV2DefaultTimeout define default timeout for action ActionRebalancerCheckV2
109+
ActionRebalancerCheckV2DefaultTimeout time.Duration = ActionsDefaultTimeout
108110
// ActionRebalancerCleanDefaultTimeout define default timeout for action ActionRebalancerClean
109111
ActionRebalancerCleanDefaultTimeout time.Duration = ActionsDefaultTimeout
112+
// ActionRebalancerCleanV2DefaultTimeout define default timeout for action ActionRebalancerCleanV2
113+
ActionRebalancerCleanV2DefaultTimeout time.Duration = ActionsDefaultTimeout
110114
// ActionRebalancerGenerateDefaultTimeout define default timeout for action ActionRebalancerGenerate
111115
ActionRebalancerGenerateDefaultTimeout time.Duration = ActionsDefaultTimeout
116+
// ActionRebalancerGenerateV2DefaultTimeout define default timeout for action ActionRebalancerGenerateV2
117+
ActionRebalancerGenerateV2DefaultTimeout time.Duration = ActionsDefaultTimeout
112118
// ActionRebuildOutSyncedShardsDefaultTimeout define default timeout for action ActionRebuildOutSyncedShards
113119
ActionRebuildOutSyncedShardsDefaultTimeout time.Duration = 86400 * time.Second // 24h0m0s
114120
// ActionRecreateMemberDefaultTimeout define default timeout for action ActionRecreateMember
@@ -266,10 +272,16 @@ const (
266272
ActionTypePlaceHolder ActionType = "PlaceHolder"
267273
// ActionTypeRebalancerCheck in scopes Normal. Check Rebalancer job progress
268274
ActionTypeRebalancerCheck ActionType = "RebalancerCheck"
275+
// ActionTypeRebalancerCheckV2 in scopes Normal. Check Rebalancer job progress
276+
ActionTypeRebalancerCheckV2 ActionType = "RebalancerCheckV2"
269277
// ActionTypeRebalancerClean in scopes Normal. Cleans Rebalancer jobs
270278
ActionTypeRebalancerClean ActionType = "RebalancerClean"
279+
// ActionTypeRebalancerCleanV2 in scopes Normal. Cleans Rebalancer jobs
280+
ActionTypeRebalancerCleanV2 ActionType = "RebalancerCleanV2"
271281
// ActionTypeRebalancerGenerate in scopes Normal. Generates the Rebalancer plan
272282
ActionTypeRebalancerGenerate ActionType = "RebalancerGenerate"
283+
// ActionTypeRebalancerGenerateV2 in scopes Normal. Generates the Rebalancer plan
284+
ActionTypeRebalancerGenerateV2 ActionType = "RebalancerGenerateV2"
273285
// ActionTypeRebuildOutSyncedShards in scopes High. Run Rebuild Out Synced Shards procedure for DBServers
274286
ActionTypeRebuildOutSyncedShards ActionType = "RebuildOutSyncedShards"
275287
// ActionTypeRecreateMember in scopes Normal. Recreate member with same ID and Data
@@ -428,10 +440,16 @@ func (a ActionType) DefaultTimeout() time.Duration {
428440
return ActionPlaceHolderDefaultTimeout
429441
case ActionTypeRebalancerCheck:
430442
return ActionRebalancerCheckDefaultTimeout
443+
case ActionTypeRebalancerCheckV2:
444+
return ActionRebalancerCheckV2DefaultTimeout
431445
case ActionTypeRebalancerClean:
432446
return ActionRebalancerCleanDefaultTimeout
447+
case ActionTypeRebalancerCleanV2:
448+
return ActionRebalancerCleanV2DefaultTimeout
433449
case ActionTypeRebalancerGenerate:
434450
return ActionRebalancerGenerateDefaultTimeout
451+
case ActionTypeRebalancerGenerateV2:
452+
return ActionRebalancerGenerateV2DefaultTimeout
435453
case ActionTypeRebuildOutSyncedShards:
436454
return ActionRebuildOutSyncedShardsDefaultTimeout
437455
case ActionTypeRecreateMember:
@@ -594,10 +612,16 @@ func (a ActionType) Priority() ActionPriority {
594612
return ActionPriorityNormal
595613
case ActionTypeRebalancerCheck:
596614
return ActionPriorityNormal
615+
case ActionTypeRebalancerCheckV2:
616+
return ActionPriorityNormal
597617
case ActionTypeRebalancerClean:
598618
return ActionPriorityNormal
619+
case ActionTypeRebalancerCleanV2:
620+
return ActionPriorityNormal
599621
case ActionTypeRebalancerGenerate:
600622
return ActionPriorityNormal
623+
case ActionTypeRebalancerGenerateV2:
624+
return ActionPriorityNormal
601625
case ActionTypeRebuildOutSyncedShards:
602626
return ActionPriorityHigh
603627
case ActionTypeRecreateMember:
@@ -682,6 +706,8 @@ func (a ActionType) Internal() bool {
682706
switch a {
683707
case ActionTypeRebalancerGenerate:
684708
return true
709+
case ActionTypeRebalancerGenerateV2:
710+
return true
685711
default:
686712
return false
687713
}
@@ -770,10 +796,16 @@ func (a ActionType) Optional() bool {
770796
return false
771797
case ActionTypeRebalancerCheck:
772798
return false
799+
case ActionTypeRebalancerCheckV2:
800+
return false
773801
case ActionTypeRebalancerClean:
774802
return false
803+
case ActionTypeRebalancerCleanV2:
804+
return false
775805
case ActionTypeRebalancerGenerate:
776806
return false
807+
case ActionTypeRebalancerGenerateV2:
808+
return false
777809
case ActionTypeRebuildOutSyncedShards:
778810
return false
779811
case ActionTypeRecreateMember:

pkg/apis/deployment/v1/rebalancer_spec.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@
2020

2121
package v1
2222

23+
const ArangoDeploymentRebalancerDefaultParallelMoves = 32
24+
2325
type ArangoDeploymentRebalancerSpec struct {
2426
Enabled *bool `json:"enabled"`
2527

@@ -42,19 +44,21 @@ func (a *ArangoDeploymentRebalancerSpec) IsEnabled() bool {
4244
return *a.Enabled
4345
}
4446

45-
func (a *ArangoDeploymentRebalancerSpec) GetParallelMoves(d int) int {
47+
func (a *ArangoDeploymentRebalancerSpec) GetParallelMoves() int {
4648
if !a.IsEnabled() {
47-
return d
49+
return ArangoDeploymentRebalancerDefaultParallelMoves
4850
}
4951

5052
if a == nil || a.ParallelMoves == nil {
51-
return d
53+
return ArangoDeploymentRebalancerDefaultParallelMoves
5254
}
5355

5456
return *a.ParallelMoves
5557
}
5658

5759
type ArangoDeploymentRebalancerReadersSpec struct {
60+
// deprecated does not work in Rebalancer V2
61+
// Count Enable Shard Count machanism
5862
Count *bool `json:"count,omitempty"`
5963
}
6064

pkg/apis/deployment/v2alpha1/actions.generated.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,16 @@ const (
105105
ActionPlaceHolderDefaultTimeout time.Duration = ActionsDefaultTimeout
106106
// ActionRebalancerCheckDefaultTimeout define default timeout for action ActionRebalancerCheck
107107
ActionRebalancerCheckDefaultTimeout time.Duration = ActionsDefaultTimeout
108+
// ActionRebalancerCheckV2DefaultTimeout define default timeout for action ActionRebalancerCheckV2
109+
ActionRebalancerCheckV2DefaultTimeout time.Duration = ActionsDefaultTimeout
108110
// ActionRebalancerCleanDefaultTimeout define default timeout for action ActionRebalancerClean
109111
ActionRebalancerCleanDefaultTimeout time.Duration = ActionsDefaultTimeout
112+
// ActionRebalancerCleanV2DefaultTimeout define default timeout for action ActionRebalancerCleanV2
113+
ActionRebalancerCleanV2DefaultTimeout time.Duration = ActionsDefaultTimeout
110114
// ActionRebalancerGenerateDefaultTimeout define default timeout for action ActionRebalancerGenerate
111115
ActionRebalancerGenerateDefaultTimeout time.Duration = ActionsDefaultTimeout
116+
// ActionRebalancerGenerateV2DefaultTimeout define default timeout for action ActionRebalancerGenerateV2
117+
ActionRebalancerGenerateV2DefaultTimeout time.Duration = ActionsDefaultTimeout
112118
// ActionRebuildOutSyncedShardsDefaultTimeout define default timeout for action ActionRebuildOutSyncedShards
113119
ActionRebuildOutSyncedShardsDefaultTimeout time.Duration = 86400 * time.Second // 24h0m0s
114120
// ActionRecreateMemberDefaultTimeout define default timeout for action ActionRecreateMember
@@ -266,10 +272,16 @@ const (
266272
ActionTypePlaceHolder ActionType = "PlaceHolder"
267273
// ActionTypeRebalancerCheck in scopes Normal. Check Rebalancer job progress
268274
ActionTypeRebalancerCheck ActionType = "RebalancerCheck"
275+
// ActionTypeRebalancerCheckV2 in scopes Normal. Check Rebalancer job progress
276+
ActionTypeRebalancerCheckV2 ActionType = "RebalancerCheckV2"
269277
// ActionTypeRebalancerClean in scopes Normal. Cleans Rebalancer jobs
270278
ActionTypeRebalancerClean ActionType = "RebalancerClean"
279+
// ActionTypeRebalancerCleanV2 in scopes Normal. Cleans Rebalancer jobs
280+
ActionTypeRebalancerCleanV2 ActionType = "RebalancerCleanV2"
271281
// ActionTypeRebalancerGenerate in scopes Normal. Generates the Rebalancer plan
272282
ActionTypeRebalancerGenerate ActionType = "RebalancerGenerate"
283+
// ActionTypeRebalancerGenerateV2 in scopes Normal. Generates the Rebalancer plan
284+
ActionTypeRebalancerGenerateV2 ActionType = "RebalancerGenerateV2"
273285
// ActionTypeRebuildOutSyncedShards in scopes High. Run Rebuild Out Synced Shards procedure for DBServers
274286
ActionTypeRebuildOutSyncedShards ActionType = "RebuildOutSyncedShards"
275287
// ActionTypeRecreateMember in scopes Normal. Recreate member with same ID and Data
@@ -428,10 +440,16 @@ func (a ActionType) DefaultTimeout() time.Duration {
428440
return ActionPlaceHolderDefaultTimeout
429441
case ActionTypeRebalancerCheck:
430442
return ActionRebalancerCheckDefaultTimeout
443+
case ActionTypeRebalancerCheckV2:
444+
return ActionRebalancerCheckV2DefaultTimeout
431445
case ActionTypeRebalancerClean:
432446
return ActionRebalancerCleanDefaultTimeout
447+
case ActionTypeRebalancerCleanV2:
448+
return ActionRebalancerCleanV2DefaultTimeout
433449
case ActionTypeRebalancerGenerate:
434450
return ActionRebalancerGenerateDefaultTimeout
451+
case ActionTypeRebalancerGenerateV2:
452+
return ActionRebalancerGenerateV2DefaultTimeout
435453
case ActionTypeRebuildOutSyncedShards:
436454
return ActionRebuildOutSyncedShardsDefaultTimeout
437455
case ActionTypeRecreateMember:
@@ -594,10 +612,16 @@ func (a ActionType) Priority() ActionPriority {
594612
return ActionPriorityNormal
595613
case ActionTypeRebalancerCheck:
596614
return ActionPriorityNormal
615+
case ActionTypeRebalancerCheckV2:
616+
return ActionPriorityNormal
597617
case ActionTypeRebalancerClean:
598618
return ActionPriorityNormal
619+
case ActionTypeRebalancerCleanV2:
620+
return ActionPriorityNormal
599621
case ActionTypeRebalancerGenerate:
600622
return ActionPriorityNormal
623+
case ActionTypeRebalancerGenerateV2:
624+
return ActionPriorityNormal
601625
case ActionTypeRebuildOutSyncedShards:
602626
return ActionPriorityHigh
603627
case ActionTypeRecreateMember:
@@ -682,6 +706,8 @@ func (a ActionType) Internal() bool {
682706
switch a {
683707
case ActionTypeRebalancerGenerate:
684708
return true
709+
case ActionTypeRebalancerGenerateV2:
710+
return true
685711
default:
686712
return false
687713
}
@@ -770,10 +796,16 @@ func (a ActionType) Optional() bool {
770796
return false
771797
case ActionTypeRebalancerCheck:
772798
return false
799+
case ActionTypeRebalancerCheckV2:
800+
return false
773801
case ActionTypeRebalancerClean:
774802
return false
803+
case ActionTypeRebalancerCleanV2:
804+
return false
775805
case ActionTypeRebalancerGenerate:
776806
return false
807+
case ActionTypeRebalancerGenerateV2:
808+
return false
777809
case ActionTypeRebuildOutSyncedShards:
778810
return false
779811
case ActionTypeRecreateMember:

pkg/apis/deployment/v2alpha1/rebalancer_spec.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@
2020

2121
package v2alpha1
2222

23+
const ArangoDeploymentRebalancerDefaultParallelMoves = 32
24+
2325
type ArangoDeploymentRebalancerSpec struct {
2426
Enabled *bool `json:"enabled"`
2527

@@ -42,19 +44,21 @@ func (a *ArangoDeploymentRebalancerSpec) IsEnabled() bool {
4244
return *a.Enabled
4345
}
4446

45-
func (a *ArangoDeploymentRebalancerSpec) GetParallelMoves(d int) int {
47+
func (a *ArangoDeploymentRebalancerSpec) GetParallelMoves() int {
4648
if !a.IsEnabled() {
47-
return d
49+
return ArangoDeploymentRebalancerDefaultParallelMoves
4850
}
4951

5052
if a == nil || a.ParallelMoves == nil {
51-
return d
53+
return ArangoDeploymentRebalancerDefaultParallelMoves
5254
}
5355

5456
return *a.ParallelMoves
5557
}
5658

5759
type ArangoDeploymentRebalancerReadersSpec struct {
60+
// deprecated does not work in Rebalancer V2
61+
// Count Enable Shard Count machanism
5862
Count *bool `json:"count,omitempty"`
5963
}
6064

pkg/apis/deployment/v2alpha1/sync_external_access_spec.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -63,8 +63,15 @@ func (s SyncExternalAccessSpec) Validate() error {
6363
return errors.WithStack(err)
6464
}
6565
for _, ep := range s.MasterEndpoint {
66-
if _, err := url.Parse(ep); err != nil {
66+
if u, err := url.Parse(ep); err != nil {
6767
return errors.WithStack(errors.Newf("Failed to parse master endpoint '%s': %s", ep, err))
68+
} else {
69+
if u.Scheme != "http" && u.Scheme != "https" {
70+
return errors.WithStack(errors.Newf("Invalid scheme '%s' in master endpoint '%s'", u.Scheme, ep))
71+
}
72+
if u.Host == "" {
73+
return errors.WithStack(errors.Newf("Missing host in master endpoint '%s'", ep))
74+
}
6875
}
6976
}
7077
for _, name := range s.AccessPackageSecretNames {

pkg/apis/deployment/v2alpha1/sync_spec_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,37 @@ func TestSyncSpecResetImmutableFields(t *testing.T) {
102102
assert.Equal(t, test.Expected, test.Target)
103103
}
104104
}
105+
106+
func TestSyncSpecMasterEndpointValidate(t *testing.T) {
107+
auth := SyncAuthenticationSpec{
108+
JWTSecretName: util.NewType[string]("foo"),
109+
ClientCASecretName: util.NewType[string]("foo-client"),
110+
}
111+
tls := TLSSpec{
112+
CASecretName: util.NewType[string]("None"),
113+
}
114+
t.Run("Valid MasterEndpoint", func(t *testing.T) {
115+
err := SyncSpec{
116+
Authentication: auth,
117+
TLS: tls,
118+
ExternalAccess: SyncExternalAccessSpec{
119+
MasterEndpoint: []string{"https://arangodb.xyz:8629"},
120+
},
121+
Enabled: util.NewType[bool](true),
122+
}.Validate(DeploymentModeCluster)
123+
assert.Nil(t, err)
124+
})
125+
126+
t.Run("Invalid MasterEndpoint without protocol", func(t *testing.T) {
127+
err := SyncSpec{
128+
Authentication: auth,
129+
TLS: tls,
130+
ExternalAccess: SyncExternalAccessSpec{
131+
MasterEndpoint: []string{"example.com:8629"},
132+
},
133+
Enabled: util.NewType[bool](true),
134+
}.Validate(DeploymentModeCluster)
135+
assert.Error(t, err)
136+
assert.Equal(t, "Invalid scheme 'example.com' in master endpoint 'example.com:8629'", err.Error())
137+
})
138+
}

pkg/deployment/agency/state/state.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,14 @@ func FilterDBServerShardsNotInSync(serverID Server) ShardFilter {
355355
return true
356356
})
357357
}
358+
359+
// GetCollectionDatabaseByID find Database name by Collection ID
360+
func (s State) GetCollectionDatabaseByID(id string) (string, bool) {
361+
for db, cols := range s.Current.Collections {
362+
if _, ok := cols[id]; ok {
363+
return db, true
364+
}
365+
}
366+
367+
return "", false
368+
}

0 commit comments

Comments
 (0)