Skip to content

Commit

Permalink
Use instance name in ReplicaAdd
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Weber <eric.weber@suse.com>
  • Loading branch information
ejweber committed May 11, 2023
1 parent c79cbbb commit 7bc70ba
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 146 deletions.
4 changes: 2 additions & 2 deletions controller/engine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1816,12 +1816,12 @@ func (ec *EngineController) startRebuilding(e *longhorn.Engine, replicaName, add
if e.Spec.NodeID != "" {
ec.eventRecorder.Eventf(e, v1.EventTypeNormal, constant.EventReasonRebuilding,
"Start rebuilding replica %v with Address %v for restore engine %v and volume %v", replicaName, addr, e.Name, e.Spec.VolumeName)
err = engineClientProxy.ReplicaAdd(e, replicaURL, true, fastReplicaRebuild, fileSyncHTTPClientTimeout)
err = engineClientProxy.ReplicaAdd(e, replicaURL, true, fastReplicaRebuild, fileSyncHTTPClientTimeout, replicaName)
}
} else {
ec.eventRecorder.Eventf(e, v1.EventTypeNormal, constant.EventReasonRebuilding,
"Start rebuilding replica %v with Address %v for normal engine %v and volume %v", replicaName, addr, e.Name, e.Spec.VolumeName)
err = engineClientProxy.ReplicaAdd(e, replicaURL, false, fastReplicaRebuild, fileSyncHTTPClientTimeout)
err = engineClientProxy.ReplicaAdd(e, replicaURL, false, fastReplicaRebuild, fileSyncHTTPClientTimeout, replicaName)
}
if err != nil {
replicaRebuildErrMsg := err.Error()
Expand Down
6 changes: 5 additions & 1 deletion engineapi/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (e *EngineBinary) ReplicaList(*longhorn.Engine) (map[string]*Replica, error

// ReplicaAdd calls engine binary
// TODO: Deprecated, replaced by gRPC proxy
func (e *EngineBinary) ReplicaAdd(engine *longhorn.Engine, url string, isRestoreVolume, fastSync bool, replicaFileSyncHTTPClientTimeout int64) error {
func (e *EngineBinary) ReplicaAdd(engine *longhorn.Engine, url string, isRestoreVolume, fastSync bool, replicaFileSyncHTTPClientTimeout int64, replicaInstanceName string) error {
if err := ValidateReplicaURL(url); err != nil {
return err
}
Expand Down Expand Up @@ -148,6 +148,10 @@ func (e *EngineBinary) ReplicaAdd(engine *longhorn.Engine, url string, isRestore
}
}

if version.ClientVersion.CLIAPIVersion >= 9 {
cmd = append(cmd, "--instance-name", replicaInstanceName)
}

if _, err := e.ExecuteEngineBinaryWithoutTimeout([]string{}, cmd...); err != nil {
return errors.Wrapf(err, "failed to add replica address='%s' to controller '%s'", url, e.name)
}
Expand Down
7 changes: 5 additions & 2 deletions engineapi/enginesim.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (c *EngineSimulatorCollection) CreateEngineSimulator(request *EngineSimulat
mutex: &sync.RWMutex{},
}
for _, addr := range request.ReplicaAddrs {
if err := s.ReplicaAdd(&longhorn.Engine{}, addr, false, false, 30); err != nil {
if err := s.ReplicaAdd(&longhorn.Engine{}, addr, false, false, 30, ""); err != nil { // TODO: Do I need to do something here?
return err
}
}
Expand Down Expand Up @@ -121,7 +121,7 @@ func (e *EngineSimulator) ReplicaList(*longhorn.Engine) (map[string]*Replica, er
return ret, nil
}

func (e *EngineSimulator) ReplicaAdd(engine *longhorn.Engine, url string, isRestoreVolume, fastSync bool, replicaFileSyncHTTPClientTimeout int64) error {
func (e *EngineSimulator) ReplicaAdd(engine *longhorn.Engine, url string, isRestoreVolume, fastSync bool, replicaFileSyncHTTPClientTimeout int64, instanceName string) error {
e.mutex.Lock()
defer e.mutex.Unlock()

Expand All @@ -137,6 +137,9 @@ func (e *EngineSimulator) ReplicaAdd(engine *longhorn.Engine, url string, isRest
URL: url,
Mode: longhorn.ReplicaModeRW,
}

// TODO: Do I need to do something here?

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion engineapi/enginesim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *TestSuite) TestBasic(c *C) {
c.Assert(replicas, HasLen, 1)
c.Assert(replicas[Replica1Addr].Mode, Equals, longhorn.ReplicaModeRW)

err = sim.ReplicaAdd(e, Replica3Addr, false, false, 30)
err = sim.ReplicaAdd(e, Replica3Addr, false, false, 30, "") // TODO: Do I need to do something here?
replicas, err = sim.ReplicaList(e)
c.Assert(err, IsNil)
c.Assert(replicas, HasLen, 2)
Expand Down
4 changes: 2 additions & 2 deletions engineapi/proxy_replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
)

func (p *Proxy) ReplicaAdd(e *longhorn.Engine, address string, restore, fastSync bool, replicaFileSyncHTTPClientTimeout int64) (err error) {
return p.grpcClient.ReplicaAdd(p.ToProxyEngineRequest(e), address, restore, e.Spec.VolumeSize, e.Status.CurrentSize, int(replicaFileSyncHTTPClientTimeout), fastSync)
func (p *Proxy) ReplicaAdd(e *longhorn.Engine, address string, restore, fastSync bool, replicaFileSyncHTTPClientTimeout int64, instanceName string) (err error) {
return p.grpcClient.ReplicaAdd(p.ToProxyEngineRequest(e), address, restore, e.Spec.VolumeSize, e.Status.CurrentSize, int(replicaFileSyncHTTPClientTimeout), fastSync, instanceName)
}

func (p *Proxy) ReplicaRemove(e *longhorn.Engine, address string) (err error) {
Expand Down
4 changes: 2 additions & 2 deletions engineapi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
const (
// CurrentCLIVersion indicates the default API version manager used to talk with the
// engine, including `longhorn-engine` and `longhorn-instance-manager`
CurrentCLIVersion = 7
CurrentCLIVersion = 9
// MinCLIVersion indicates the Min API version manager used to talk with the
// engine.
MinCLIVersion = 3
Expand Down Expand Up @@ -76,7 +76,7 @@ type EngineClient interface {
VolumeUnmapMarkSnapChainRemovedSet(engine *longhorn.Engine) error

ReplicaList(*longhorn.Engine) (map[string]*Replica, error)
ReplicaAdd(engine *longhorn.Engine, url string, isRestoreVolume, fastSync bool, replicaFileSyncHTTPClientTimeout int64) error
ReplicaAdd(engine *longhorn.Engine, url string, isRestoreVolume, fastSync bool, replicaFileSyncHTTPClientTimeout int64, instanceName string) error
ReplicaRemove(engine *longhorn.Engine, url string) error
ReplicaRebuildStatus(*longhorn.Engine) (map[string]*longhorn.RebuildStatus, error)
ReplicaRebuildVerify(engine *longhorn.Engine, url string) error
Expand Down

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

Loading

0 comments on commit 7bc70ba

Please sign in to comment.