Skip to content

Commit

Permalink
remove balance data job (#515)
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaByte875 authored Jul 25, 2024
1 parent b1de748 commit c6ae313
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 129 deletions.
1 change: 0 additions & 1 deletion apis/apps/v1alpha1/nebulacluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ type EmptyStruct struct{}
type FailureHost struct {
Host string `json:"host,omitempty"`
PVCSet map[types.UID]EmptyStruct `json:"pvcSet,omitempty"`
DataBalanced *bool `json:"dataBalanced,omitempty"`
PodRestarted bool `json:"podRestarted,omitempty"`
PodRebuilt bool `json:"podRebuilt,omitempty"`
NodeDown bool `json:"nodeDown,omitempty"`
Expand Down
5 changes: 0 additions & 5 deletions apis/apps/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions apis/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/vesoft-inc/nebula-go/v3 v3.6.0
k8s.io/api v0.27.10
k8s.io/apimachinery v0.27.10
k8s.io/client-go v0.27.10
k8s.io/utils v0.0.0-20230209194617-a36077c30491
sigs.k8s.io/controller-runtime v0.15.2
)
Expand All @@ -26,4 +27,5 @@ require (
k8s.io/klog/v2 v2.90.1 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
3 changes: 3 additions & 0 deletions apis/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ k8s.io/api v0.27.10 h1:VFvsFZxiG3qeKyMvSOlO6hzrB7CGk6CC0XI1hniBI28=
k8s.io/api v0.27.10/go.mod h1:cDmAF4GtSVRO0+5hOY/Vo3lLCQMOp6FfrXZ94/gQwC0=
k8s.io/apimachinery v0.27.10 h1:AlOhsgdtNPMYDMJyUDsj2HZDLKOf1qPfvbbo5O9m4jg=
k8s.io/apimachinery v0.27.10/go.mod h1:IHu2ovJ60RqxyPSLmTel7KDLdOCRbpOxwtUBmwBnT/E=
k8s.io/client-go v0.27.10 h1:ZOrDrfTSsw+66NIkFMmnamKZ9TTs8WUaV8WRc9NhtJA=
k8s.io/client-go v0.27.10/go.mod h1:PhrjLdIJNy7L8liOPEzm6wNlMjhIRJeVbfvksTxKNqI=
k8s.io/klog/v2 v2.90.1 h1:m4bYOKall2MmOiRaR1J+We67Do7vm9KiQVlT96lnHUw=
k8s.io/klog/v2 v2.90.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/utils v0.0.0-20230209194617-a36077c30491 h1:r0BAOLElQnnFhE/ApUsg3iHdVYYPBjNSSOMowRZxxsY=
Expand All @@ -114,3 +116,4 @@ sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h6
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE=
sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
6 changes: 0 additions & 6 deletions charts/nebula-operator/crds/nebulaclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11792,8 +11792,6 @@ spec:
creationTime:
format: date-time
type: string
dataBalanced:
type: boolean
deletionTime:
format: date-time
type: string
Expand Down Expand Up @@ -11881,8 +11879,6 @@ spec:
creationTime:
format: date-time
type: string
dataBalanced:
type: boolean
deletionTime:
format: date-time
type: string
Expand Down Expand Up @@ -11978,8 +11974,6 @@ spec:
creationTime:
format: date-time
type: string
dataBalanced:
type: boolean
deletionTime:
format: date-time
type: string
Expand Down
6 changes: 0 additions & 6 deletions config/crd/bases/apps.nebula-graph.io_nebulaclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11792,8 +11792,6 @@ spec:
creationTime:
format: date-time
type: string
dataBalanced:
type: boolean
deletionTime:
format: date-time
type: string
Expand Down Expand Up @@ -11881,8 +11879,6 @@ spec:
creationTime:
format: date-time
type: string
dataBalanced:
type: boolean
deletionTime:
format: date-time
type: string
Expand Down Expand Up @@ -11978,8 +11974,6 @@ spec:
creationTime:
format: date-time
type: string
dataBalanced:
type: boolean
deletionTime:
format: date-time
type: string
Expand Down
9 changes: 0 additions & 9 deletions pkg/controller/component/storaged_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,6 @@ func (c *storagedCluster) shouldRecover(nc *v1alpha1.NebulaCluster) (bool, []str
defer func() {
_ = metaClient.Disconnect()
}()
spaces, err := metaClient.ListSpaces()
if err != nil {
return false, nil, err
}

onlineHosts := make([]string, 0)
hostItems, err := metaClient.ListHosts(meta.ListHostType_STORAGE)
Expand All @@ -588,12 +584,7 @@ func (c *storagedCluster) shouldRecover(nc *v1alpha1.NebulaCluster) (bool, []str
thriftPort := nc.StoragedComponent().GetPort(v1alpha1.StoragedPortNameThrift)
for _, host := range hostItems {
podName, ok := m[host.HostAddr.Host]
fh, exists := nc.Status.Storaged.FailureHosts[podName]
balanced := pointer.BoolDeref(fh.DataBalanced, false)
if ok && host.Status == meta.HostStatus_ONLINE && host.HostAddr.Port == thriftPort {
if exists && len(spaces) > 0 && !balanced {
continue
}
onlineHosts = append(onlineHosts, podName)
}
}
Expand Down
101 changes: 0 additions & 101 deletions pkg/controller/component/storaged_failover.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/vesoft-inc/nebula-operator/apis/apps/v1alpha1"
"github.com/vesoft-inc/nebula-operator/apis/pkg/label"
"github.com/vesoft-inc/nebula-operator/pkg/kube"
"github.com/vesoft-inc/nebula-operator/pkg/nebula"
utilerrors "github.com/vesoft-inc/nebula-operator/pkg/util/errors"
)

Expand All @@ -51,37 +49,7 @@ func (s *storagedFailover) Failover(nc *v1alpha1.NebulaCluster) error {
if err != nil {
return err
}

if len(readyPods) > 0 {
options, err := nebula.ClientOptions(nc, nebula.SetIsMeta(true))
if err != nil {
return err
}
endpoints := []string{nc.GetMetadThriftConnAddress()}
metaClient, err := nebula.NewMetaClient(endpoints, options...)
if err != nil {
return err
}
defer func() {
err := metaClient.Disconnect()
if err != nil {
klog.Errorf("meta client disconnect failed: %v", err)
}
}()

spaces, err := metaClient.ListSpaces()
if err != nil {
return err
}
if len(spaces) > 0 {
for _, podName := range readyPods {
fh, ok := nc.Status.Storaged.FailureHosts[podName]
if ok {
fh.DataBalanced = pointer.Bool(true)
nc.Status.Storaged.FailureHosts[podName] = fh
}
}
}
return utilerrors.ReconcileErrorf("storaged pods [%v] are ready after restarted", readyPods)
}
if err := s.deleteFailurePodAndPVC(nc); err != nil {
Expand All @@ -90,9 +58,6 @@ func (s *storagedFailover) Failover(nc *v1alpha1.NebulaCluster) error {
if err := s.checkPendingPod(nc); err != nil {
return err
}
if err := s.balanceData(nc); err != nil {
return err
}
return nil
}

Expand Down Expand Up @@ -235,69 +200,3 @@ func (s *storagedFailover) checkPendingPod(nc *v1alpha1.NebulaCluster) error {
}
return nil
}

func (s *storagedFailover) balanceData(nc *v1alpha1.NebulaCluster) error {
podNames := make([]string, 0)
for podName, fh := range nc.Status.Storaged.FailureHosts {
if pointer.BoolDeref(fh.DataBalanced, false) {
continue
}
pod, err := s.clientSet.Pod().GetPod(nc.Namespace, podName)
if err != nil {
return err
}
if !isPodHealthy(pod) {
return utilerrors.ReconcileErrorf("rebuilt storaged pod [%s/%s] is not healthy", nc.Namespace, podName)
}
podNames = append(podNames, podName)
}
if len(podNames) == 0 {
return nil
}

options, err := nebula.ClientOptions(nc, nebula.SetIsMeta(true))
if err != nil {
return err
}
endpoints := []string{nc.GetMetadThriftConnAddress()}
metaClient, err := nebula.NewMetaClient(endpoints, options...)
if err != nil {
klog.Errorf("create meta client failed: %v", err)
return err
}
defer func() {
err := metaClient.Disconnect()
if err != nil {
klog.Errorf("disconnect meta client failed: %v", err)
}
}()

spaces, err := metaClient.ListSpaces()
if err != nil {
return err
}
if len(spaces) == 0 {
return utilerrors.ReconcileErrorf("storaged cluster [%s/%s] data balanced for recovery", nc.Namespace, nc.Name)
}

if nc.Status.Storaged.BalancedSpaces == nil {
nc.Status.Storaged.BalancedSpaces = make([]int32, 0, len(spaces))
}
for _, space := range spaces {
if contains(nc.Status.Storaged.BalancedSpaces, *space.Id.SpaceID) {
continue
}
if err := balanceSpace(s.clientSet, metaClient, nc, *space.Id.SpaceID); err != nil {
return err
}
}

for podName, fh := range nc.Status.Storaged.FailureHosts {
fh.DataBalanced = pointer.Bool(true)
nc.Status.Storaged.FailureHosts[podName] = fh
}

nc.Status.Storaged.BalancedSpaces = nil
nc.Status.Storaged.LastBalanceJob = nil
return utilerrors.ReconcileErrorf("storaged cluster [%s/%s] data balanced for recovery", nc.Namespace, nc.Name)
}
10 changes: 9 additions & 1 deletion pkg/nebula/meta_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ func NewMetaClient(hosts []string, options ...Option) (MetaInterface, error) {
if len(hosts) == 0 {
return nil, ErrNoAvailableMetadEndpoints
}
mc, err := newMetaConnection(hosts[0], options...)
var err error
var mc MetaInterface
for i := 0; i < len(hosts); i++ {
mc, err = newMetaConnection(hosts[i], options...)
if err != nil {
klog.Error(err)
continue
}
}
if err != nil {
return nil, err
}
Expand Down

0 comments on commit c6ae313

Please sign in to comment.