From 71310d40d7af9c1083e278b77834ec27d2e18831 Mon Sep 17 00:00:00 2001 From: Eric Weber Date: Thu, 17 Aug 2023 08:35:07 -0500 Subject: [PATCH] Add replicaName argument to ReplicaRebuildVerify Longhorn 6522 Signed-off-by: Eric Weber --- controller/engine_controller.go | 2 +- engineapi/engine.go | 12 +++++++++++- engineapi/enginesim.go | 2 +- engineapi/proxy_replica.go | 5 +++-- engineapi/types.go | 2 +- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/controller/engine_controller.go b/controller/engine_controller.go index 318cad2969..94a331fa26 100644 --- a/controller/engine_controller.go +++ b/controller/engine_controller.go @@ -1305,7 +1305,7 @@ func syncWithRestoreStatus(log logrus.FieldLogger, engine *longhorn.Engine, rsMa replicaName := addressReplicaMap[engineapi.GetAddressFromBackendReplicaURL(url)] if mode, exists := engine.Status.ReplicaModeMap[replicaName]; exists && mode == longhorn.ReplicaModeWO { log.Infof("Verifying the rebuild of replica %v after restore completion", url) - if err := engineClientProxy.ReplicaRebuildVerify(engine, url); err != nil { + if err := engineClientProxy.ReplicaRebuildVerify(engine, replicaName, url); err != nil { log.WithError(err).Errorf("Failed to verify the rebuild of replica %v after restore completion", url) engine.Status.ReplicaModeMap[url] = longhorn.ReplicaModeERR return false diff --git a/engineapi/engine.go b/engineapi/engine.go index 8dbd12eb4a..13a0044a25 100644 --- a/engineapi/engine.go +++ b/engineapi/engine.go @@ -290,11 +290,21 @@ func (e *EngineBinary) VolumeUnmapMarkSnapChainRemovedSet(engine *longhorn.Engin // ReplicaRebuildVerify calls engine binary // TODO: Deprecated, replaced by gRPC proxy -func (e *EngineBinary) ReplicaRebuildVerify(engine *longhorn.Engine, url string) error { +func (e *EngineBinary) ReplicaRebuildVerify(engine *longhorn.Engine, replicaName, url string) error { if err := ValidateReplicaURL(url); err != nil { return err } + + version, err := e.VersionGet(engine, true) + if err != nil { + return err + } + cmd := []string{"verify-rebuild-replica", url} + if version.ClientVersion.CLIAPIVersion >= 9 { + cmd = append(cmd, "--replica-instance-name", replicaName) + } + if _, err := e.ExecuteEngineBinaryWithoutTimeout([]string{}, cmd...); err != nil { return errors.Wrapf(err, "failed to verify rebuilding for the replica from address %s", url) } diff --git a/engineapi/enginesim.go b/engineapi/enginesim.go index 8d672ac2e5..2100424a56 100644 --- a/engineapi/enginesim.go +++ b/engineapi/enginesim.go @@ -245,7 +245,7 @@ func (e *EngineSimulator) VolumeUnmapMarkSnapChainRemovedSet(*longhorn.Engine) e return fmt.Errorf(ErrNotImplement) } -func (e *EngineSimulator) ReplicaRebuildVerify(engine *longhorn.Engine, url string) error { +func (e *EngineSimulator) ReplicaRebuildVerify(engine *longhorn.Engine, replicaName, url string) error { return fmt.Errorf(ErrNotImplement) } diff --git a/engineapi/proxy_replica.go b/engineapi/proxy_replica.go index c48f7009be..4001db2e8b 100644 --- a/engineapi/proxy_replica.go +++ b/engineapi/proxy_replica.go @@ -49,11 +49,12 @@ func (p *Proxy) ReplicaRebuildStatus(e *longhorn.Engine) (status map[string]*lon return status, nil } -func (p *Proxy) ReplicaRebuildVerify(e *longhorn.Engine, url string) (err error) { +func (p *Proxy) ReplicaRebuildVerify(e *longhorn.Engine, replicaName, url string) (err error) { if err := ValidateReplicaURL(url); err != nil { return err } - return p.grpcClient.ReplicaVerifyRebuild(string(e.Spec.BackendStoreDriver), e.Name, e.Spec.VolumeName, p.DirectToURL(e), url, "") + return p.grpcClient.ReplicaVerifyRebuild(string(e.Spec.BackendStoreDriver), e.Name, e.Spec.VolumeName, + p.DirectToURL(e), url, replicaName) } func (p *Proxy) ReplicaModeUpdate(e *longhorn.Engine, url, mode string) (err error) { diff --git a/engineapi/types.go b/engineapi/types.go index f7518bdeed..b6f532e0ae 100644 --- a/engineapi/types.go +++ b/engineapi/types.go @@ -83,7 +83,7 @@ type EngineClient interface { ReplicaAdd(engine *longhorn.Engine, replicaName, url string, isRestoreVolume, fastSync bool, replicaFileSyncHTTPClientTimeout int64) error ReplicaRemove(engine *longhorn.Engine, url string) error ReplicaRebuildStatus(*longhorn.Engine) (map[string]*longhorn.RebuildStatus, error) - ReplicaRebuildVerify(engine *longhorn.Engine, url string) error + ReplicaRebuildVerify(engine *longhorn.Engine, replicaName, url string) error ReplicaModeUpdate(engine *longhorn.Engine, url string, mode string) error SnapshotCreate(engine *longhorn.Engine, name string, labels map[string]string) (string, error)