mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
[Bugfix] Always recreate dbservers if they have a leader on it (#1083)
This commit is contained in:
parent
ef4c3c6161
commit
f86b88a8c3
4 changed files with 133 additions and 0 deletions
|
@ -16,6 +16,7 @@
|
||||||
- (QA) Member maintenance feature
|
- (QA) Member maintenance feature
|
||||||
- (Feature) Extract Pod Details
|
- (Feature) Extract Pod Details
|
||||||
- (Feature) Add Timezone management
|
- (Feature) Add Timezone management
|
||||||
|
- (Bugfix) Always recreate DBServers if they have a leader on it.
|
||||||
|
|
||||||
## [1.2.15](https://github.com/arangodb/kube-arangodb/tree/1.2.15) (2022-07-20)
|
## [1.2.15](https://github.com/arangodb/kube-arangodb/tree/1.2.15) (2022-07-20)
|
||||||
- (Bugfix) Ensure pod names not too long
|
- (Bugfix) Ensure pod names not too long
|
||||||
|
|
91
pkg/deployment/agency/leader_test.go
Normal file
91
pkg/deployment/agency/leader_test.go
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
//
|
||||||
|
// DISCLAIMER
|
||||||
|
//
|
||||||
|
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
||||||
|
//
|
||||||
|
|
||||||
|
package agency
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_LeaderCheck_DBServerIsLeader(t *testing.T) {
|
||||||
|
t.Run("Empty collection", func(t *testing.T) {
|
||||||
|
p := StatePlanCollections{}
|
||||||
|
|
||||||
|
require.False(t, p.IsDBServerLeader("A"))
|
||||||
|
})
|
||||||
|
t.Run("Empty shards", func(t *testing.T) {
|
||||||
|
p := StatePlanCollections{
|
||||||
|
"a": {
|
||||||
|
"a": {
|
||||||
|
Shards: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
require.False(t, p.IsDBServerLeader("A"))
|
||||||
|
})
|
||||||
|
t.Run("Empty shard list", func(t *testing.T) {
|
||||||
|
p := StatePlanCollections{
|
||||||
|
"a": {
|
||||||
|
"a": {
|
||||||
|
Shards: Shards{
|
||||||
|
"a": {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
require.False(t, p.IsDBServerLeader("A"))
|
||||||
|
})
|
||||||
|
t.Run("Follower", func(t *testing.T) {
|
||||||
|
p := StatePlanCollections{
|
||||||
|
"a": {
|
||||||
|
"a": {
|
||||||
|
Shards: Shards{
|
||||||
|
"a": {
|
||||||
|
"B",
|
||||||
|
"A",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
require.False(t, p.IsDBServerLeader("A"))
|
||||||
|
})
|
||||||
|
t.Run("Leader", func(t *testing.T) {
|
||||||
|
p := StatePlanCollections{
|
||||||
|
"a": {
|
||||||
|
"a": {
|
||||||
|
Shards: Shards{
|
||||||
|
"a": {
|
||||||
|
"A",
|
||||||
|
"B",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
require.True(t, p.IsDBServerLeader("A"))
|
||||||
|
})
|
||||||
|
}
|
|
@ -31,6 +31,15 @@ func (a StatePlanCollections) IsDBServerPresent(name Server) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a StatePlanCollections) IsDBServerLeader(name Server) bool {
|
||||||
|
for _, collections := range a {
|
||||||
|
if collections.IsDBServerLeaderInCollections(name) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
type StatePlanDBCollections map[string]StatePlanCollection
|
type StatePlanDBCollections map[string]StatePlanCollection
|
||||||
|
|
||||||
func (a StatePlanDBCollections) IsDBServerInCollections(name Server) bool {
|
func (a StatePlanDBCollections) IsDBServerInCollections(name Server) bool {
|
||||||
|
@ -42,6 +51,15 @@ func (a StatePlanDBCollections) IsDBServerInCollections(name Server) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a StatePlanDBCollections) IsDBServerLeaderInCollections(name Server) bool {
|
||||||
|
for _, collection := range a {
|
||||||
|
if collection.IsDBServerLeader(name) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (a StatePlanDBCollections) CountShards() int {
|
func (a StatePlanDBCollections) CountShards() int {
|
||||||
count := 0
|
count := 0
|
||||||
|
|
||||||
|
@ -121,3 +139,19 @@ func (a *StatePlanCollection) IsDBServerInShards(name Server) bool {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *StatePlanCollection) IsDBServerLeader(name Server) bool {
|
||||||
|
if a == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, servers := range a.Shards {
|
||||||
|
if len(servers) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if servers[0] == name {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
|
@ -80,6 +80,13 @@ func (r *Reconciler) createMemberFailedRestoreInternal(_ context.Context, _ k8su
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if agencyState.Plan.Collections.IsDBServerLeader(agency.Server(m.ID)) {
|
||||||
|
memberLog.Info("Recreating leader DBServer - it cannot be removed gracefully")
|
||||||
|
plan = append(plan, actions.NewAction(api.ActionTypeRecreateMember, group, m))
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if c := spec.DBServers.GetCount(); c <= len(members)-failed {
|
if c := spec.DBServers.GetCount(); c <= len(members)-failed {
|
||||||
// There are more or equal alive members than current count. A member should not be recreated.
|
// There are more or equal alive members than current count. A member should not be recreated.
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue