Skip to content

Commit 627f6f7

Browse files
authored
[Bugfix] Fix Agency satellite collections (#951)
1 parent 45f0e08 commit 627f6f7

File tree

7 files changed

+6972
-13
lines changed

7 files changed

+6972
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
44
- (Feature) Allow configuration for securityContext.runAsUser value
5+
- (Bugfix) Fix Satellite collections in Agency
56

67
## [1.2.9](https://github.com/arangodb/kube-arangodb/tree/1.2.9) (2022-03-30)
78
- (Feature) Improve Kubernetes clientsets management

pkg/deployment/agency/generator_collection_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type collectionGenerator struct {
3232
col string
3333

3434
wc *int
35-
rf *int
35+
rf *ReplicationFactor
3636
shards map[int]shardGenerator
3737
}
3838

@@ -59,6 +59,6 @@ func (c collectionGenerator) WithWriteConcern(wc int) CollectionGeneratorInterfa
5959
}
6060

6161
func (c collectionGenerator) WithReplicationFactor(rf int) CollectionGeneratorInterface {
62-
c.rf = &rf
62+
c.rf = (*ReplicationFactor)(&rf)
6363
return c
6464
}

pkg/deployment/agency/plan_collections.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ type StatePlanCollection struct {
5757
Shards Shards `json:"shards"`
5858
// deprecated
5959
// MinReplicationFactor is deprecated, but we have to support it for backward compatibility
60-
MinReplicationFactor *int `json:"minReplicationFactor,omitempty"`
61-
WriteConcern *int `json:"writeConcern,omitempty"`
62-
ReplicationFactor *int `json:"replicationFactor,omitempty"`
60+
MinReplicationFactor *int `json:"minReplicationFactor,omitempty"`
61+
WriteConcern *int `json:"writeConcern,omitempty"`
62+
ReplicationFactor *ReplicationFactor `json:"replicationFactor,omitempty"`
6363
}
6464

65-
func (a *StatePlanCollection) GetReplicationFactor(shard string) int {
65+
func (a *StatePlanCollection) GetReplicationFactor(shard string) ReplicationFactor {
6666
if a == nil {
6767
return 0
6868
}
6969

70-
l := len(a.Shards[shard])
70+
l := ReplicationFactor(len(a.Shards[shard]))
7171

7272
if z := a.ReplicationFactor; z == nil {
7373
return l

pkg/deployment/agency/rf.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package agency
22+
23+
import (
24+
"encoding/json"
25+
26+
"github.com/pkg/errors"
27+
"k8s.io/apimachinery/pkg/util/intstr"
28+
)
29+
30+
const (
31+
UnknownReplicationFactor ReplicationFactor = -1000
32+
SatelliteReplicationFactor ReplicationFactor = -100
33+
)
34+
35+
type ReplicationFactor int
36+
37+
func (r *ReplicationFactor) IsUnknown() bool {
38+
if r == nil {
39+
return false
40+
}
41+
42+
return *r == UnknownReplicationFactor
43+
}
44+
45+
func (r *ReplicationFactor) IsSatellite() bool {
46+
if r == nil {
47+
return false
48+
}
49+
50+
return *r == SatelliteReplicationFactor
51+
}
52+
53+
func (r *ReplicationFactor) UnmarshalJSON(bytes []byte) error {
54+
var i intstr.IntOrString
55+
56+
if err := json.Unmarshal(bytes, &i); err != nil {
57+
return err
58+
}
59+
60+
switch i.Type {
61+
case intstr.Int:
62+
*r = ReplicationFactor(i.IntVal)
63+
return nil
64+
case intstr.String:
65+
switch i.StrVal {
66+
case "satellite":
67+
*r = SatelliteReplicationFactor
68+
return nil
69+
default:
70+
*r = UnknownReplicationFactor
71+
return nil
72+
}
73+
}
74+
75+
return errors.Errorf("Unable to parse value")
76+
}

pkg/deployment/agency/state.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,21 @@ func FilterDBServerShardRestart(serverID string) StateShardFilter {
219219
return true
220220
}
221221

222-
// If WriteConcern equals replicationFactor then downtime is always there
223222
wc := plan.GetWriteConcern(1)
224-
if rf := plan.GetReplicationFactor(shard); wc >= rf {
223+
var rf int
224+
225+
if plan.ReplicationFactor.IsUnknown() {
226+
// We are on unknown
227+
rf = len(currentShard)
228+
} else if plan.ReplicationFactor.IsSatellite() {
229+
// We are on satellite
230+
rf = len(s.PlanServers())
231+
} else {
232+
rf = int(plan.GetReplicationFactor(shard))
233+
}
234+
235+
// If WriteConcern equals replicationFactor then downtime is always there
236+
if wc >= rf {
225237
wc = rf - 1
226238
}
227239

pkg/deployment/agency/state_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@ var agencyDump38 []byte
4040
//go:embed testdata/agency_dump.3.9.json
4141
var agencyDump39 []byte
4242

43+
//go:embed testdata/agency_dump.3.9.satellite.json
44+
var agencyDump39Satellite []byte
45+
4346
var (
4447
data = map[string][]byte{
45-
"3.6": agencyDump36,
46-
"3.7": agencyDump37,
47-
"3.8": agencyDump38,
48-
"3.9": agencyDump39,
48+
"3.6": agencyDump36,
49+
"3.7": agencyDump37,
50+
"3.8": agencyDump38,
51+
"3.9": agencyDump39,
52+
"3.9-satellite": agencyDump39Satellite,
4953
}
5054
)
5155

0 commit comments

Comments
 (0)