From 079e7c794bf7267a19dce2bb9ca98099cf8beccc Mon Sep 17 00:00:00 2001 From: "pengwei.song" <90180021+pengweisong@users.noreply.github.com> Date: Wed, 9 Feb 2022 10:30:38 +0800 Subject: [PATCH] Fix after restore failed (#28) * fix the cluster when restore failed * check alive before fix * fix role convert * fix: use restore backup suffix && remove target data folder when fix * tidy log && add verify --- Makefile | 2 +- cmd/backup.go | 10 +- cmd/restore.go | 14 ++- cmd/show.go | 2 +- cmd/version.go | 2 +- go.mod | 4 +- go.sum | 17 ++- pkg/backup/backup.go | 37 ++++--- pkg/cleanup/cleanup.go | 13 ++- pkg/clients/agent.go | 3 +- pkg/clients/meta.go | 10 +- pkg/clients/utils.go | 23 +++- pkg/config/backup.go | 2 +- pkg/config/cleanup.go | 2 +- pkg/config/restore.go | 2 +- pkg/log/log.go | 2 +- pkg/restore/fix.go | 237 ++++++++++++++++++++++++++++++++++++++++ pkg/restore/restore.go | 46 ++++---- pkg/show/show.go | 21 ++-- pkg/storage/flags.go | 5 +- pkg/utils/hosts.go | 25 ++++- pkg/utils/hosts_test.go | 4 +- pkg/utils/stringify.go | 6 +- pkg/utils/utils.go | 17 ++- pkg/utils/utils_test.go | 3 +- 25 files changed, 407 insertions(+), 102 deletions(-) create mode 100644 pkg/restore/fix.go diff --git a/Makefile b/Makefile index 85723a7..0fc35a3 100644 --- a/Makefile +++ b/Makefile @@ -21,5 +21,5 @@ test: $(GO) test -v $(PKG) -short fmt: - $(GO) mod tidy && find . -path vendor -prune -o -type f -iname '*.go' -exec go fmt {} \; + $(GO) mod tidy && find . -path vendor -prune -o -type f -iname '*.go' -exec goimports -w {} \; diff --git a/cmd/backup.go b/cmd/backup.go index 204f60f..dda054f 100644 --- a/cmd/backup.go +++ b/cmd/backup.go @@ -28,7 +28,7 @@ func NewBackupCmd() *cobra.Command { func newFullBackupCmd() *cobra.Command { fullBackupCmd := &cobra.Command{ Use: "full", - Short: "full backup Nebula Graph Database", + Short: "Full backup Nebula Graph Database", RunE: func(cmd *cobra.Command, args []string) error { err := log.SetLog(cmd.Flags()) if err != nil { @@ -46,10 +46,10 @@ func newFullBackupCmd() *cobra.Command { return err } - fmt.Println("start to backup cluster...") + fmt.Println("Start to backup cluster...") backupName, err := b.Backup() if err != nil { - fmt.Println("backup failed, will try to clean the remaining garbage...") + fmt.Println("Backup failed, will try to clean the remaining garbage...") if backupName != "" { cleanCfg := &config.CleanupConfig{ @@ -66,12 +66,12 @@ func newFullBackupCmd() *cobra.Command { if err != nil { return fmt.Errorf("cleanup %s failed when backup failed: %w", backupName, err) } - fmt.Printf("cleanup backup %s successfully after backup failed", backupName) + fmt.Printf("Cleanup backup %s successfully after backup failed.", backupName) } return err } - fmt.Println("backup succeed.") + fmt.Println("Backup succeed.") return nil }, } diff --git a/cmd/restore.go b/cmd/restore.go index 30799c5..4f3f028 100644 --- a/cmd/restore.go +++ b/cmd/restore.go @@ -14,7 +14,7 @@ import ( func NewRestoreCmd() *cobra.Command { restoreCmd := &cobra.Command{ Use: "restore", - Short: "restore Nebula Graph Database, notice that it will restart the cluster", + Short: "Restore Nebula Graph Database, notice that it will restart the cluster", SilenceUsage: true, } config.AddCommonFlags(restoreCmd.PersistentFlags()) @@ -46,9 +46,19 @@ func newFullRestoreCmd() *cobra.Command { err = r.Restore() if err != nil { + f, ferr := restore.NewFixFrom(r) + if ferr != nil { + return err + } + + ferr = f.Fix() + if ferr != nil { + fmt.Println("Fix failed when restore failed", ferr) + } + return err } - fmt.Println("restore succeed") + fmt.Println("Restore succeed.") return nil }, } diff --git a/cmd/show.go b/cmd/show.go index 1dadb5c..e30772c 100644 --- a/cmd/show.go +++ b/cmd/show.go @@ -14,7 +14,7 @@ import ( func NewShowCmd() *cobra.Command { showCmd := &cobra.Command{ Use: "show", - Short: "show backup info list in external storage", + Short: "Show backup info list in external storage", SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { err := log.SetLog(cmd.Flags()) diff --git a/cmd/version.go b/cmd/version.go index baac016..4f673f9 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -11,7 +11,7 @@ import ( func NewVersionCmd() *cobra.Command { versionCmd := &cobra.Command{ Use: "version", - Short: "print the version of nebula br tool", + Short: "Print the version of nebula br tool", RunE: func(cmd *cobra.Command, args []string) error { fmt.Printf(`%s,V-%d.%d.%d GitSha: %s diff --git a/go.mod b/go.mod index a12d0d4..8870472 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/spf13/cobra v1.1.1 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.7.0 - github.com/vesoft-inc/nebula-agent v0.1.0 - github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20211228055601-b5b11a36e453 + github.com/vesoft-inc/nebula-agent v0.1.1-0.20220208095610-fe80654911f8 + github.com/vesoft-inc/nebula-go/v3 v3.0.0-20220119024722-ab348afbb79d golang.org/x/sys v0.0.0-20211124211545-fe61309f8881 // indirect ) diff --git a/go.sum b/go.sum index f9eb7b4..fc9dbb3 100644 --- a/go.sum +++ b/go.sum @@ -39,6 +39,7 @@ github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -142,11 +143,13 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= @@ -189,6 +192,8 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= @@ -218,10 +223,10 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/vesoft-inc/nebula-agent v0.1.0 h1:ROcnM5BUguBErwMaaZM4tmiCl2T92xE1fxAiB9cAc6g= -github.com/vesoft-inc/nebula-agent v0.1.0/go.mod h1:79lL9wmxYYKgMHP+9Q+MLc3q+G9HFU/sCnBhy85G0B0= -github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20211228055601-b5b11a36e453 h1:1rwe3LQVuTRUJBf4Gonc47+T3dCD29EzkrRaTzkUNdw= -github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20211228055601-b5b11a36e453/go.mod h1:YRIuog6zyRKz0SagwwTcqHXCPjJ4GfQelIl+/FgSC+Y= +github.com/vesoft-inc/nebula-agent v0.1.1-0.20220208095610-fe80654911f8 h1:UY7ygJyfzpYWIsdLpLJTf1yjh3FhW8xRYBNQg1OL77o= +github.com/vesoft-inc/nebula-agent v0.1.1-0.20220208095610-fe80654911f8/go.mod h1:uA6GJsvhNdTZkLQp1grX74fUm6TWi7EWA2AEWNeHzNU= +github.com/vesoft-inc/nebula-go/v3 v3.0.0-20220119024722-ab348afbb79d h1:spO7OAtYI1wiqBiJ9417pKhqx0IkqFAFdFQFPm4JIrs= +github.com/vesoft-inc/nebula-go/v3 v3.0.0-20220119024722-ab348afbb79d/go.mod h1:+sXv05jYQBARdTbTcIEsWVXCnF/6ttOlDK35xQ6m54s= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= diff --git a/pkg/backup/backup.go b/pkg/backup/backup.go index 91a4d2c..f9ffca7 100644 --- a/pkg/backup/backup.go +++ b/pkg/backup/backup.go @@ -9,10 +9,11 @@ import ( "github.com/google/uuid" log "github.com/sirupsen/logrus" + pb "github.com/vesoft-inc/nebula-agent/pkg/proto" "github.com/vesoft-inc/nebula-agent/pkg/storage" - "github.com/vesoft-inc/nebula-go/v2/nebula" - "github.com/vesoft-inc/nebula-go/v2/nebula/meta" + "github.com/vesoft-inc/nebula-go/v3/nebula" + "github.com/vesoft-inc/nebula-go/v3/nebula/meta" "github.com/vesoft-inc/nebula-br/pkg/clients" "github.com/vesoft-inc/nebula-br/pkg/config" @@ -123,7 +124,7 @@ func (b *Backup) uploadStorage(hostDirs map[string]map[string][]string, targetUr if err != nil { return fmt.Errorf("upload %s to %s failed:%w", source, target, err) } - logger.WithField("src", source).WithField("target", target).Info("Upload storage checkpoint successfully") + logger.WithField("src", source).WithField("target", target).Info("Upload storage checkpoint successfully.") } } } @@ -146,7 +147,7 @@ func (b *Backup) generateMetaFile(meta *meta.BackupMeta) (string, error) { // Backup backs up data in given external storage, and return the backup name func (b *Backup) Backup() (string, error) { - // step2: call the meta service, create backup files in each local + // call the meta service, create backup files in each local backupRes, err := b.meta.CreateBackup(b.cfg.Spaces) if err != nil { if backupRes != nil && backupRes.GetMeta() != nil && backupRes.GetMeta().GetBackupName() != nil { @@ -157,9 +158,9 @@ func (b *Backup) Backup() (string, error) { backupInfo := backupRes.GetMeta() backupName := string(backupInfo.GetBackupName()) logger := log.WithField("name", backupName) - logger.WithField("backup info", utils.StringifyBackup(backupInfo)).Info("Create backup in nebula machine's local") + logger.WithField("backup info", utils.StringifyBackup(backupInfo)).Info("Create backup in nebula machine's local.") - // step3: ensure root dir + // ensure root dir rootUri, err := utils.UriJoin(b.cfg.Backend.Uri(), string(backupInfo.BackupName)) if err != nil { return backupName, err @@ -168,9 +169,9 @@ func (b *Backup) Backup() (string, error) { if err != nil { return backupName, fmt.Errorf("ensure dir %s failed: %w", rootUri, err) } - logger.WithField("root", rootUri).Info("Ensure backup root dir") + logger.WithField("root", rootUri).Info("Ensure backup root dir.") - // step4: upload meta files + // upload meta files metaDir, err := utils.UriJoin(rootUri, "meta") if err != nil { return backupName, err @@ -182,9 +183,9 @@ func (b *Backup) Backup() (string, error) { if err = b.uploadMeta(b.meta.LeaderAddr(), metaDir, localMetaDir); err != nil { return backupName, err } - logger.WithField("meta", metaDir).Info("Upload meta successfully") + logger.WithField("meta", metaDir).Info("Upload meta successfully.") - // step5: upload storage files + // upload storage files storageDir, _ := utils.UriJoin(rootUri, "data") hostDirs := make(map[string]map[string][]string) // group checkpoint dirs by host and space id @@ -203,17 +204,17 @@ func (b *Backup) Backup() (string, error) { } err = b.uploadStorage(hostDirs, storageDir) if err != nil { - return backupName, fmt.Errorf("upload stoarge failed %w", err) + return backupName, fmt.Errorf("upload storage failed %w", err) } - logger.WithField("data", storageDir).Info("Upload data backup successfully") + logger.WithField("data", storageDir).Info("Upload data backup successfully.") - // step6: generate backup meta files and upload + // generate backup meta files and upload if err := utils.EnsureDir(utils.LocalTmpDir); err != nil { return backupName, err } defer func() { if err := utils.RemoveDir(utils.LocalTmpDir); err != nil { - log.WithError(err).Errorf("Remove tmp dir %s failed", utils.LocalTmpDir) + log.WithError(err).Errorf("Remove tmp dir %s failed.", utils.LocalTmpDir) } }() @@ -221,7 +222,7 @@ func (b *Backup) Backup() (string, error) { if err != nil { return backupName, fmt.Errorf("write meta to tmp path failed: %w", err) } - logger.WithField("tmp path", tmpMetaPath).Info("Write meta data to local tmp file successfully") + logger.WithField("tmp path", tmpMetaPath).Info("Write meta data to local tmp file successfully.") backupMetaPath, err := utils.UriJoin(rootUri, filepath.Base(tmpMetaPath)) if err != nil { return backupName, err @@ -230,15 +231,15 @@ func (b *Backup) Backup() (string, error) { if err != nil { return backupName, fmt.Errorf("upload local tmp file to remote storage %s failed: %w", backupMetaPath, err) } - logger.WithField("remote path", backupMetaPath).Info("Upload tmp backup meta file to remote") + logger.WithField("remote path", backupMetaPath).Info("Upload tmp backup meta file to remote.") - // step7: drop backup files in cluster machine local and local tmp files + // drop backup files in cluster machine local and local tmp files err = b.meta.DropBackup(backupInfo.GetBackupName()) if err != nil { return backupName, fmt.Errorf("drop backup %s in cluster local failed: %w", string(backupInfo.BackupName[:]), err) } - logger.Info("Drop backup in cluster and local tmp folder successfully") + logger.Info("Drop backup in cluster and local tmp folder successfully.") return backupName, nil } diff --git a/pkg/cleanup/cleanup.go b/pkg/cleanup/cleanup.go index 665afa4..e5502e7 100644 --- a/pkg/cleanup/cleanup.go +++ b/pkg/cleanup/cleanup.go @@ -6,6 +6,7 @@ import ( "strings" log "github.com/sirupsen/logrus" + pb "github.com/vesoft-inc/nebula-agent/pkg/proto" "github.com/vesoft-inc/nebula-agent/pkg/storage" @@ -60,7 +61,7 @@ func (c *Cleanup) cleanNebula() error { if err != nil { return fmt.Errorf("drop backup failed: %w", err) } - log.Debugf("Drop backup %s successfully", c.cfg.BackupName) + log.Debugf("Drop backup %s successfully.", c.cfg.BackupName) return nil } @@ -75,7 +76,7 @@ func (c *Cleanup) cleanExternal() error { if err != nil { return fmt.Errorf("remove %s in external storage failed: %w", backupUri, err) } - log.Debugf("Remove %s successfullly", backupUri) + log.Debugf("Remove %s successfully.", backupUri) // Local backend's data lay in different cluster machines, // which should be handled separately @@ -97,7 +98,7 @@ func (c *Cleanup) cleanExternal() error { if err != nil { return fmt.Errorf("remove %s in host: %s failed: %w", backupPath, addr.Host, err) } - log.Debugf("Remove local data %s in %s successfullly", backupPath, addr.Host) + log.Debugf("Remove local data %s in %s successfully.", backupPath, addr.Host) } } @@ -107,18 +108,18 @@ func (c *Cleanup) cleanExternal() error { func (c *Cleanup) Clean() error { logger := log.WithField("backup name", c.cfg.BackupName) - logger.Info("Start to cleanup data in nebula cluster") + logger.Info("Start to cleanup data in nebula cluster.") err := c.cleanNebula() if err != nil { return fmt.Errorf("clean nebula local data failed: %w", err) } - logger.Info("Start cleanup data in external storage") + logger.Info("Start cleanup data in external storage.") err = c.cleanExternal() if err != nil { return fmt.Errorf("clean external storage data failed: %w", err) } - logger.Info("Clean up backup data successfully") + logger.Info("Clean up backup data successfully.") return nil } diff --git a/pkg/clients/agent.go b/pkg/clients/agent.go index b9f0451..20883bd 100644 --- a/pkg/clients/agent.go +++ b/pkg/clients/agent.go @@ -5,9 +5,8 @@ import ( "fmt" agent "github.com/vesoft-inc/nebula-agent/pkg/client" - "github.com/vesoft-inc/nebula-go/v2/nebula" - "github.com/vesoft-inc/nebula-br/pkg/utils" + "github.com/vesoft-inc/nebula-go/v3/nebula" ) type NebulaAgent struct { diff --git a/pkg/clients/meta.go b/pkg/clients/meta.go index 974da4b..7b91c3a 100644 --- a/pkg/clients/meta.go +++ b/pkg/clients/meta.go @@ -5,10 +5,10 @@ import ( "time" log "github.com/sirupsen/logrus" - "github.com/vesoft-inc/nebula-go/v2/nebula" - "github.com/vesoft-inc/nebula-go/v2/nebula/meta" "github.com/vesoft-inc/nebula-br/pkg/utils" + "github.com/vesoft-inc/nebula-go/v3/nebula" + "github.com/vesoft-inc/nebula-go/v3/nebula/meta" ) type NebulaMeta struct { @@ -205,14 +205,14 @@ func (m *NebulaMeta) RestoreMeta(metaAddr *nebula.HostAddr, hostMap []*meta.Host client, err := connect(metaAddr) if err != nil { log.WithError(err).WithField("addr", utils.StringifyAddr(metaAddr)). - Errorf("connect to metad failed, try times %d", try) + Errorf("Connect to metad failed, try times %d.", try) time.Sleep(time.Second * 2) continue } resp, err := client.RestoreMeta(req) if err != nil { - log.WithError(err).WithField("req", req).Error("Restore meta failed") + log.WithError(err).WithField("req", req).Error("Restore meta failed.") return err } @@ -227,7 +227,7 @@ func (m *NebulaMeta) RestoreMeta(metaAddr *nebula.HostAddr, hostMap []*meta.Host } func (m *NebulaMeta) getMetaDirInfo(addr *nebula.HostAddr) (*nebula.DirInfo, error) { - log.WithField("addr", utils.StringifyAddr(addr)).Debug("Try to get dir info from meta service") + log.WithField("addr", utils.StringifyAddr(addr)).Debug("Try to get dir info from meta service.") c, err := connect(addr) if err != nil { return nil, err diff --git a/pkg/clients/utils.go b/pkg/clients/utils.go index 30b69ab..cae2484 100644 --- a/pkg/clients/utils.go +++ b/pkg/clients/utils.go @@ -6,10 +6,10 @@ import ( "github.com/facebook/fbthrift/thrift/lib/go/thrift" log "github.com/sirupsen/logrus" - "github.com/vesoft-inc/nebula-go/v2/nebula" - "github.com/vesoft-inc/nebula-go/v2/nebula/meta" "github.com/vesoft-inc/nebula-br/pkg/utils" + "github.com/vesoft-inc/nebula-go/v3/nebula" + "github.com/vesoft-inc/nebula-go/v3/nebula/meta" ) const ( @@ -17,7 +17,7 @@ const ( ) func connect(metaAddr *nebula.HostAddr) (*meta.MetaServiceClient, error) { - log.WithField("meta address", utils.StringifyAddr(metaAddr)).Info("try to connect meta service") + log.WithField("meta address", utils.StringifyAddr(metaAddr)).Info("Try to connect meta service.") timeoutOption := thrift.SocketTimeout(defaultTimeout) addressOption := thrift.SocketAddr(utils.StringifyAddr(metaAddr)) sock, err := thrift.NewSocket(timeoutOption, addressOption) @@ -33,6 +33,21 @@ func connect(metaAddr *nebula.HostAddr) (*meta.MetaServiceClient, error) { return nil, fmt.Errorf("open meta failed %w", err) } - log.WithField("meta address", utils.StringifyAddr(metaAddr)).Info("connect meta server successfully") + req := newVerifyClientVersionReq() + resp, err := client.VerifyClientVersion(req) + if err != nil || resp.Code != nebula.ErrorCode_SUCCEEDED { + log.WithError(err).WithField("addr", metaAddr).Error("Incompatible version between client and server.") + client.Close() + return nil, err + } + + log.WithField("meta address", utils.StringifyAddr(metaAddr)).Info("Connect meta server successfully.") return client, nil } + +func newVerifyClientVersionReq() *meta.VerifyClientVersionReq { + return &meta.VerifyClientVersionReq{ + ClientVersion: []byte(nebula.Version), + Host: nebula.NewHostAddr(), + } +} diff --git a/pkg/config/backup.go b/pkg/config/backup.go index 9bd548b..a116e6f 100644 --- a/pkg/config/backup.go +++ b/pkg/config/backup.go @@ -5,8 +5,8 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" - pb "github.com/vesoft-inc/nebula-agent/pkg/proto" + pb "github.com/vesoft-inc/nebula-agent/pkg/proto" "github.com/vesoft-inc/nebula-br/pkg/storage" ) diff --git a/pkg/config/cleanup.go b/pkg/config/cleanup.go index 36bb307..f011272 100644 --- a/pkg/config/cleanup.go +++ b/pkg/config/cleanup.go @@ -5,8 +5,8 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" - pb "github.com/vesoft-inc/nebula-agent/pkg/proto" + pb "github.com/vesoft-inc/nebula-agent/pkg/proto" "github.com/vesoft-inc/nebula-br/pkg/storage" ) diff --git a/pkg/config/restore.go b/pkg/config/restore.go index f501a0e..db71aad 100644 --- a/pkg/config/restore.go +++ b/pkg/config/restore.go @@ -5,8 +5,8 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" - pb "github.com/vesoft-inc/nebula-agent/pkg/proto" + pb "github.com/vesoft-inc/nebula-agent/pkg/proto" "github.com/vesoft-inc/nebula-br/pkg/storage" ) diff --git a/pkg/log/log.go b/pkg/log/log.go index 27e1498..a9f0083 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -33,7 +33,7 @@ func SetLog(flags *pflag.FlagSet) error { file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) if err != nil { - logrus.WithError(err).WithField("file", path).Error("Create log path failed") + logrus.WithError(err).WithField("file", path).Error("Create log path failed.") return err } diff --git a/pkg/restore/fix.go b/pkg/restore/fix.go new file mode 100644 index 0000000..313a77a --- /dev/null +++ b/pkg/restore/fix.go @@ -0,0 +1,237 @@ +package restore + +import ( + "fmt" + "path/filepath" + "time" + + log "github.com/sirupsen/logrus" + + pb "github.com/vesoft-inc/nebula-agent/pkg/proto" + "github.com/vesoft-inc/nebula-br/pkg/clients" + "github.com/vesoft-inc/nebula-br/pkg/utils" + "github.com/vesoft-inc/nebula-go/v3/nebula" + "github.com/vesoft-inc/nebula-go/v3/nebula/meta" +) + +type Fix struct { + r *Restore + hosts *utils.NebulaHosts + agentMgr *clients.AgentManager + + backSuffix string +} + +func NewFixFrom(r *Restore) (*Fix, error) { + if r.hosts == nil || r.agentMgr == nil { + return nil, fmt.Errorf("empty hosts or agents manager") + } + + return &Fix{ + r: r, + hosts: r.hosts, + agentMgr: r.agentMgr, + backSuffix: r.backSuffix, + }, nil +} + +// Move back the data dir in restore process +func (f *Fix) fixData() error { + services := f.hosts.GetStorages() + services = append(services, f.hosts.GetMetas()...) + + for _, s := range services { + name := fmt.Sprintf("%s[%s]", s.GetRole().String(), utils.StringifyAddr(s.GetAddr())) + logger := log.WithField("name", name) + + agent, err := f.agentMgr.GetAgentFor(s.GetAddr()) + if err != nil { + return fmt.Errorf("get agent for %s failed: %w", name, err) + } + + if s.GetRole() == meta.HostRole_META && len(s.Dir.Data) != 1 { + return fmt.Errorf("meta service: %s should only have one data dir, but %d", + name, len(s.Dir.Data)) + } + + for _, d := range s.Dir.Data { + opath := filepath.Join(string(d), "nebula") + bpath := fmt.Sprintf("%s%s", opath, f.backSuffix) + + // check if the old data exist + existReq := &pb.ExistDirRequest{ + Path: bpath, + } + res, err := agent.ExistDir(existReq) + if err != nil { + return fmt.Errorf("check %s:%s exist failed: %w", name, opath, err) + } + if !res.Exist { + logger.WithField("path", bpath).Debug("Origin backup storage data path does not exist, skip it") + continue + } + + // remove the newly downloaded data + rmReq := &pb.RemoveDirRequest{ + Path: opath, + } + _, err = agent.RemoveDir(rmReq) + if err != nil { + return fmt.Errorf("remove new origin dir %s failed: %w", opath, err) + } + + // move the old data back + req := &pb.MoveDirRequest{ + SrcPath: bpath, + DstPath: opath, + } + _, err = agent.MoveDir(req) + if err != nil { + return fmt.Errorf("move data dir back from %s to %s failed: %w", opath, bpath, err) + } + + logger.WithField("origin path", opath). + WithField("backup path", bpath). + Infof("Moveback origin %s data path successfully", s.GetRole().String()) + } + } + + return nil +} + +func (f *Fix) getDead() ([]*meta.ServiceInfo, error) { + deadServices := make([]*meta.ServiceInfo, 0) + + for host, services := range f.hosts.GetHostServices() { + logger := log.WithField("host", host) + + // get and check agent + var agentAddr *nebula.HostAddr + for _, s := range services { + if s.GetRole() == meta.HostRole_AGENT { + if agentAddr == nil { + agentAddr = s.GetAddr() + } else { + return deadServices, fmt.Errorf("there are two agents in host %s: %s, %s", s.GetAddr().GetHost(), + utils.StringifyAddr(agentAddr), utils.StringifyAddr(s.GetAddr())) + } + } + } + agent, err := f.agentMgr.GetAgent(agentAddr) + if err != nil { + return deadServices, fmt.Errorf("get agent %s failed: %w", utils.StringifyAddr(agentAddr), err) + } + + // collect all dead services + for _, s := range services { + if s.GetRole() == meta.HostRole_AGENT { + continue + } + + req := &pb.ServiceStatusRequest{ + Role: utils.ToRole(s.GetRole()), + Dir: string(s.GetDir().GetRoot()), + } + + resp, err := agent.ServiceStatus(req) + if err != nil { + return deadServices, fmt.Errorf("get service status in host %s failed: %w", agentAddr.Host, err) + } + + if resp.Status != pb.Status_RUNNING { + logger.WithField("dir", req.Dir).WithField("role", s.GetRole().String()).Debugf("%s:%s is dead.", + s.Role.String(), utils.StringifyAddr(s.Addr)) + deadServices = append(deadServices, s) + } + } + } + + return deadServices, nil +} + +func (f *Fix) startDead(deadServices []*meta.ServiceInfo) error { + for _, ds := range deadServices { + name := fmt.Sprintf("%s[%s]", ds.GetRole().String(), utils.StringifyAddr(ds.GetAddr())) + agent, err := f.agentMgr.GetAgentFor(ds.GetAddr()) + if err != nil { + return fmt.Errorf("get agent for %s failed: %w", name, err) + } + + req := &pb.StartServiceRequest{ + Role: utils.ToRole(ds.GetRole()), + Dir: string(ds.GetDir().GetRoot()), + } + _, err = agent.StartService(req) + if err != nil { + return fmt.Errorf("start %s by agent failed: %w", name, err) + } + log.WithField("addr", utils.StringifyAddr(ds.GetAddr())). + Infof("Start %s by agent successfully.", name) + } + return nil +} + +func retry(action func() error, aname string, times int) (err error) { + for try := 1; try <= times; try++ { + err = action() + if err == nil { + return + } + + log.WithError(err).Infof("%s failed, try times=%d.", aname, try) + time.Sleep(time.Second * time.Duration(try)) + } + + return +} + +func (f *Fix) Fix() error { + tryTimes := 3 + + // check if all services alive + allAlive := false + checkAlive := func() error { + if ds, err := f.getDead(); err != nil { + return err + } else { + allAlive = len(ds) == 0 + return nil + } + } + err := retry(checkAlive, "Get dead services", tryTimes) + if allAlive { + log.Info("All services are OK.") + return nil + } + if err != nil { + return err + } + + // stop all service for data movement + if err := retry(f.r.stopCluster, "Stop all services", tryTimes); err != nil { + return err + } + + // move back data path + if err := retry(f.fixData, "Fix data", tryTimes); err != nil { + return err + } + + // start all services + getdeadThenStart := func() error { + ds, err := f.getDead() + if err != nil { + return fmt.Errorf("get services failed: %w", err) + } + err = f.startDead(ds) + if err != nil { + return fmt.Errorf("start dead services failed: %w", err) + } + return nil + } + if err := retry(getdeadThenStart, "Get dead services then start", tryTimes); err != nil { + return err + } + + return nil +} diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 806fdf3..dc66f29 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -10,14 +10,14 @@ import ( "time" log "github.com/sirupsen/logrus" + pb "github.com/vesoft-inc/nebula-agent/pkg/proto" "github.com/vesoft-inc/nebula-agent/pkg/storage" - "github.com/vesoft-inc/nebula-go/v2/nebula" - "github.com/vesoft-inc/nebula-go/v2/nebula/meta" - "github.com/vesoft-inc/nebula-br/pkg/clients" "github.com/vesoft-inc/nebula-br/pkg/config" "github.com/vesoft-inc/nebula-br/pkg/utils" + "github.com/vesoft-inc/nebula-go/v3/nebula" + "github.com/vesoft-inc/nebula-go/v3/nebula/meta" ) func GetBackupSuffix() string { @@ -92,7 +92,7 @@ func (r *Restore) checkPhysicalTopology(info map[nebula.GraphSpaceID]*meta.Space clusterPaths := r.hosts.StoragePaths() if !reflect.DeepEqual(backupPaths, clusterPaths) { - log.WithField("backup", backupPaths).WithField("cluster", clusterPaths).Error("Path distribution is not consistent") + log.WithField("backup", backupPaths).WithField("cluster", clusterPaths).Error("Path distribution is not consistent.") return fmt.Errorf("the physical topology is not consistent, path distribution is not consistent") } @@ -111,7 +111,7 @@ func (r *Restore) checkAndDropSpaces(info map[nebula.GraphSpaceID]*meta.SpaceBac } if resp.GetCode() == nebula.ErrorCode_SUCCEEDED { if resp.Item.SpaceID != sid { - return fmt.Errorf("space to resotre already exist and the space id is not consistent, name: %s, backup: %d, cluster: %d", + return fmt.Errorf("space to restore already exist and the space id is not consistent, name: %s, backup: %d, cluster: %d", string(backup.Space.SpaceName), sid, resp.Item.SpaceID) } } else { @@ -155,7 +155,7 @@ func (r *Restore) backupOriginal(allspaces bool) error { logger.WithField("origin path", opath). WithField("backup path", bpath). - Info("Backup origin storage data path successfully") + Info("Backup origin storage data path successfully.") } } @@ -187,7 +187,7 @@ func (r *Restore) backupOriginal(allspaces bool) error { log.WithField("addr", utils.StringifyAddr(m.GetAddr())). WithField("origin path", opath). WithField("backup path", bpath). - Info("Backup origin meta data path successfully") + Info("Backup origin meta data path successfully.") } } @@ -291,7 +291,7 @@ func (r *Restore) downloadStorage(backup *meta.BackupMeta) (map[string]string, e externalUri, localDir, utils.StringifyAddr(s.GetAddr()), err) } logger.WithField("external", externalUri). - WithField("local", localDir).Info("Download storage data successfully") + WithField("local", localDir).Info("Download storage data successfully.") } serviceMap[utils.StringifyAddr(prevList[idx])] = utils.StringifyAddr(s.GetAddr()) @@ -319,7 +319,7 @@ func (r *Restore) startMetaService() error { utils.StringifyAddr(meta.GetAddr()), err) } log.WithField("addr", utils.StringifyAddr(meta.GetAddr())). - Info("Start meta service successfully") + Info("Start meta service successfully.") } return nil @@ -351,11 +351,11 @@ func (r *Restore) stopCluster() error { } req := &pb.StopServiceRequest{ - Role: pb.ServiceRole(s.GetRole()), + Role: utils.ToRole(s.GetRole()), Dir: string(s.GetDir().GetRoot()), } - logger.WithField("dir", req.Dir).WithField("role", s.GetRole().String()).Info("Stop services") + logger.WithField("dir", req.Dir).WithField("role", s.GetRole().String()).Info("Stop services.") _, err := agent.StopService(req) if err != nil { return fmt.Errorf("stop services in host %s failed: %w", agentAddr.Host, err) @@ -396,7 +396,7 @@ func (r *Restore) restoreMeta(backup *meta.BackupMeta, storageMap map[string]str } log.WithField("addr", utils.StringifyAddr(meta.GetAddr())). - Info("restore backup in this metad successfully") + Info("Restore backup in this metad successfully.") } return nil @@ -419,7 +419,7 @@ func (r *Restore) startStorageService() error { return fmt.Errorf("start storaged by agent failed: %w", err) } log.WithField("addr", utils.StringifyAddr(s.GetAddr())). - Info("Start storaged by agent successfully") + Info("Start storaged by agent successfully.") } return nil @@ -442,7 +442,7 @@ func (r *Restore) startGraphService() error { return fmt.Errorf("start graphd by agent failed: %w", err) } log.WithField("addr", utils.StringifyAddr(s.GetAddr())). - Info("Start graphd by agent successfully") + Info("Start graphd by agent successfully.") } return nil @@ -506,7 +506,7 @@ func (r *Restore) Restore() error { if !exist { return fmt.Errorf("backup dir %s does not exist", rootUri) } - logger.WithField("uri", rootUri).Info("Check backup dir successfully") + logger.WithField("uri", rootUri).Info("Check backup dir successfully.") // download and parse backup meta file if err := utils.EnsureDir(utils.LocalTmpDir); err != nil { @@ -514,7 +514,7 @@ func (r *Restore) Restore() error { } defer func() { if err := utils.RemoveDir(utils.LocalTmpDir); err != nil { - log.WithError(err).Errorf("Remove tmp dir %s failed", utils.LocalTmpDir) + log.WithError(err).Errorf("Remove tmp dir %s failed.", utils.LocalTmpDir) } }() @@ -536,13 +536,13 @@ func (r *Restore) Restore() error { return fmt.Errorf("physical topology not consistent: %w", err) } - // if only resotre some spaces, check and remove these spaces + // if only restore some spaces, check and remove these spaces if !bakMeta.AllSpaces { err = r.checkAndDropSpaces(bakMeta.SpaceBackups) if err != nil { return fmt.Errorf("check and drop space failed: %w", err) } - log.Info("Check and drop spaces successfully") + log.Info("Check and drop spaces successfully.") } // stop cluster @@ -550,14 +550,14 @@ func (r *Restore) Restore() error { if err != nil { return fmt.Errorf("stop cluster failed: %w", err) } - logger.Info("Stop cluster successfully") + logger.Info("Stop cluster successfully.") - // backup original data if we are to restore whole cluster + // backup original data err = r.backupOriginal(bakMeta.AllSpaces) if err != nil { return fmt.Errorf("backup origin data path failed: %w", err) } - logger.Info("Backup origin cluster data successfully") + logger.Info("Backup origin cluster data successfully.") // download backup data from external storage to cluster err = r.downloadMeta() @@ -595,13 +595,13 @@ func (r *Restore) Restore() error { if err != nil { return fmt.Errorf("start graph service failed: %w", err) } - log.Info("Start storage and graph services successfully") + log.Info("Start storage and graph services successfully.") // after success restore, cleanup the backup data if needed err = r.cleanupOriginalData() if err != nil { return fmt.Errorf("clean up origin data failed: %w", err) } - log.Info("Cleanup origin data successfully") + log.Info("Cleanup origin data successfully.") return nil } diff --git a/pkg/show/show.go b/pkg/show/show.go index 49efbc5..78ca795 100644 --- a/pkg/show/show.go +++ b/pkg/show/show.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "sort" "strconv" "strings" "time" @@ -12,9 +13,8 @@ import ( _ "github.com/facebook/fbthrift/thrift/lib/go/thrift" "github.com/olekukonko/tablewriter" log "github.com/sirupsen/logrus" - "github.com/vesoft-inc/nebula-agent/pkg/storage" - _ "github.com/vesoft-inc/nebula-go/v2/nebula/meta" + "github.com/vesoft-inc/nebula-agent/pkg/storage" "github.com/vesoft-inc/nebula-br/pkg/config" "github.com/vesoft-inc/nebula-br/pkg/utils" ) @@ -72,7 +72,7 @@ func NewShow(ctx context.Context, cfg *config.ShowConfig) (*Show, error) { if err != nil { return nil, fmt.Errorf("list dir failed: %w", err) } - log.WithField("prefix", cfg.Backend.Uri()).WithField("backup names", dirNames).Debug("List backups") + log.WithField("prefix", cfg.Backend.Uri()).WithField("backup names", dirNames).Debug("List backups.") return &Show{ ctx: ctx, @@ -88,7 +88,7 @@ func (s *Show) downloadMetaFiles() (map[string]string, error) { bname = strings.Trim(bname, "/") // the s3 list result may have slashes if !utils.IsBackupName(bname) { - log.Infof("%s is not backup name", bname) + log.Infof("%s is not backup name.", bname) continue } @@ -98,7 +98,7 @@ func (s *Show) downloadMetaFiles() (map[string]string, error) { err := s.sto.Download(s.ctx, localTmpPath, externalUri, false) if err != nil { - log.WithError(err).Infof("download %s to %s failed", externalUri, localTmpPath) + log.WithError(err).Infof("Download %s to %s failed.", externalUri, localTmpPath) } else { log.WithField("external", externalUri).WithField("local", localTmpPath).Debug("Download backup meta file successfully.") } @@ -112,16 +112,16 @@ func (s *Show) downloadMetaFiles() (map[string]string, error) { func (s *Show) parseMetaFiles(metaPaths map[string]string) ([]*backupInfo, error) { var infoList []*backupInfo for name, path := range metaPaths { - log.WithField("meta path", path).Debug("Start parse meta file") + log.WithField("meta path", path).Debug("Start parse meta file.") m, err := utils.ParseMetaFromFile(path) if err != nil || m == nil { - log.WithError(err).WithField("meta path", path).Error("parse meta file failed") + log.WithError(err).WithField("meta path", path).Error("Parse meta file failed.") infoList = append(infoList, &backupInfo{BackupName: name}) continue } if name != string(m.BackupName) { - log.Errorf("Name from path: %s and name parsed from meta: %s are not consistent", name, string(m.BackupName)) + log.Errorf("Name from path: %s and name parsed from meta: %s are not consistent.", name, string(m.BackupName)) } spaces := make([]string, 0) @@ -144,6 +144,9 @@ func (s *Show) parseMetaFiles(metaPaths map[string]string) ([]*backupInfo, error } func (s *Show) showBackupInfo(infoList []*backupInfo) { + sort.Slice(infoList, func(i, j int) bool { + return strings.Compare(infoList[i].BackupName, infoList[j].BackupName) < 0 + }) asciiTable := make([][]string, 0) for _, info := range infoList { asciiTable = append(asciiTable, info.StringTable()) @@ -163,7 +166,7 @@ func (s *Show) Show() error { } defer func() { if err := utils.RemoveDir(utils.LocalTmpDir); err != nil { - log.WithError(err).Errorf("Remove tmp dir %s failed", utils.LocalTmpDir) + log.WithError(err).Errorf("Remove tmp dir %s failed.", utils.LocalTmpDir) } }() diff --git a/pkg/storage/flags.go b/pkg/storage/flags.go index c1a3912..4bb3e08 100644 --- a/pkg/storage/flags.go +++ b/pkg/storage/flags.go @@ -7,6 +7,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/pflag" + pb "github.com/vesoft-inc/nebula-agent/pkg/proto" ) @@ -29,7 +30,7 @@ func AddFlags(flags *pflag.FlagSet) { for s3 - "s3://example/url/to/the/backup" `) if err := cobra.MarkFlagRequired(flags, flagStorage); err != nil { - log.Errorf("failed to mark flag %s required: %v", flagStorage, err) + log.Errorf("Failed to mark flag %s required: %v.", flagStorage, err) } AddS3Flags(flags) AddLocalFlags(flags) @@ -89,6 +90,6 @@ func ParseFromFlags(flags *pflag.FlagSet) (*pb.Backend, error) { return nil, fmt.Errorf("bad format backend: %d", t) } - log.WithField("type", t).WithField("uri", s).Debugln("Parse storage flag") + log.WithField("type", t).WithField("uri", s).Debugln("Parse storage flag.") return b, nil } diff --git a/pkg/utils/hosts.go b/pkg/utils/hosts.go index dafc6b3..15ef07c 100644 --- a/pkg/utils/hosts.go +++ b/pkg/utils/hosts.go @@ -5,8 +5,9 @@ import ( "strings" log "github.com/sirupsen/logrus" - "github.com/vesoft-inc/nebula-go/v2/nebula" - "github.com/vesoft-inc/nebula-go/v2/nebula/meta" + + "github.com/vesoft-inc/nebula-go/v3/nebula" + "github.com/vesoft-inc/nebula-go/v3/nebula/meta" ) // NebulaHosts group all services(storaged/metad/graphd/listener) and agents by hostname or ip @@ -47,7 +48,23 @@ func (h *NebulaHosts) LoadFrom(resp *meta.ListClusterInfoResp) error { } h.hosts = resp.GetHostServices() - log.WithField("host info", h.String()).Info("Get cluster topology from the nebula") + + // check only one agent in each host + for _, services := range h.hosts { + var agentAddr *nebula.HostAddr + for _, s := range services { + if s.GetRole() == meta.HostRole_AGENT { + if agentAddr == nil { + agentAddr = s.GetAddr() + } else { + return fmt.Errorf("there are more than one agent in host %s: %s, %s", s.GetAddr().GetHost(), + StringifyAddr(agentAddr), StringifyAddr(s.GetAddr())) + } + } + } + } + + log.WithField("host info", h.String()).Info("Get cluster topology from the nebula.") return nil } @@ -98,7 +115,7 @@ func (h *NebulaHosts) HasService(addr *nebula.HostAddr) bool { if s.Addr.GetHost() != addr.GetHost() { log.WithField("should", addr.GetHost()). WithField("but", s.Addr.GetHost()). - Infof("Wrong address %s in hosts map", StringifyAddr(s.Addr)) + Infof("Wrong address %s in hosts map.", StringifyAddr(s.Addr)) continue } diff --git a/pkg/utils/hosts_test.go b/pkg/utils/hosts_test.go index 4780328..3bda294 100644 --- a/pkg/utils/hosts_test.go +++ b/pkg/utils/hosts_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/vesoft-inc/nebula-go/v2/nebula" - "github.com/vesoft-inc/nebula-go/v2/nebula/meta" + "github.com/vesoft-inc/nebula-go/v3/nebula" + "github.com/vesoft-inc/nebula-go/v3/nebula/meta" ) var ( diff --git a/pkg/utils/stringify.go b/pkg/utils/stringify.go index 9aa2611..6bed89e 100644 --- a/pkg/utils/stringify.go +++ b/pkg/utils/stringify.go @@ -6,8 +6,8 @@ import ( "strings" "time" - "github.com/vesoft-inc/nebula-go/v2/nebula" - "github.com/vesoft-inc/nebula-go/v2/nebula/meta" + "github.com/vesoft-inc/nebula-go/v3/nebula" + "github.com/vesoft-inc/nebula-go/v3/nebula/meta" ) func StringifyAddr(addr *nebula.HostAddr) string { @@ -25,7 +25,7 @@ func ParseAddr(addrStr string) (*nebula.HostAddr, error) { port, err := strconv.ParseInt(ipAddr[1], 10, 32) if err != nil { - return nil, fmt.Errorf("bad fomrat: %s", addrStr) + return nil, fmt.Errorf("bad format: %s", addrStr) } return &nebula.HostAddr{Host: ipAddr[0], Port: nebula.Port(port)}, nil diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 1f76873..0178919 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -8,7 +8,9 @@ import ( "strings" "github.com/facebook/fbthrift/thrift/lib/go/thrift" - "github.com/vesoft-inc/nebula-go/v2/nebula/meta" + + pb "github.com/vesoft-inc/nebula-agent/pkg/proto" + "github.com/vesoft-inc/nebula-go/v3/nebula/meta" ) func DumpMetaToFile(meta *meta.BackupMeta, filename string) error { @@ -103,3 +105,16 @@ func UriJoin(elem ...string) (string, error) { u.Path = path.Join(elem...) return u.String(), nil } + +func ToRole(r meta.HostRole) pb.ServiceRole { + switch r { + case meta.HostRole_STORAGE: + return pb.ServiceRole_STORAGE + case meta.HostRole_GRAPH: + return pb.ServiceRole_GRAPH + case meta.HostRole_META: + return pb.ServiceRole_META + default: + return pb.ServiceRole_UNKNOWN_ROLE + } +} diff --git a/pkg/utils/utils_test.go b/pkg/utils/utils_test.go index 3ab2de8..ee9fa8f 100644 --- a/pkg/utils/utils_test.go +++ b/pkg/utils/utils_test.go @@ -7,7 +7,8 @@ import ( "time" "github.com/stretchr/testify/assert" - "github.com/vesoft-inc/nebula-go/v2/nebula/meta" + + "github.com/vesoft-inc/nebula-go/v3/nebula/meta" ) func TestDumpParseBackup(t *testing.T) {