Skip to content

Commit

Permalink
feat(auto-balance): implement local sync when proxying for added replica
Browse files Browse the repository at this point in the history
longhorn/longhorn-4105

Signed-off-by: Chin-Ya Huang <chin-ya.huang@suse.com>
  • Loading branch information
c3y1huang authored and derekbit committed Jul 4, 2024
1 parent 5d103ef commit 17dde47
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion pkg/client/proxy_replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func (c *ProxyClient) ReplicaAdd(dataEngine, engineName, volumeName, serviceAddress, replicaName,
replicaAddress string, restore bool, size, currentSize int64, fileSyncHTTPClientTimeout int,
fastSync bool, grpcTimeoutSeconds int64) (err error) {
fastSync bool, localSync *etypes.FileLocalSync, grpcTimeoutSeconds int64) (err error) {
input := map[string]string{
"engineName": engineName,
"volumeName": volumeName,
Expand Down Expand Up @@ -53,6 +53,14 @@ func (c *ProxyClient) ReplicaAdd(dataEngine, engineName, volumeName, serviceAddr
FileSyncHttpClientTimeout: int32(fileSyncHTTPClientTimeout),
GrpcTimeoutSeconds: grpcTimeoutSeconds,
}

if localSync != nil {
req.LocalSync = &rpc.EngineReplicaLocalSync{
SourcePath: localSync.SourcePath,
TargetPath: localSync.TargetPath,
}
}

_, err = c.service.ReplicaAdd(getContextWithGRPCLongTimeout(c.ctx, grpcTimeoutSeconds), req)
if err != nil {
return err
Expand Down
10 changes: 9 additions & 1 deletion pkg/proxy/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (p *Proxy) ReplicaAdd(ctx context.Context, req *rpc.EngineReplicaAddRequest
"size": req.Size,
"currentSize": req.CurrentSize,
"fastSync": req.FastSync,
"localSync": req.LocalSync,
})
log.Info("Adding replica")

Expand All @@ -51,8 +52,15 @@ func (ops V1DataEngineProxyOps) ReplicaAdd(ctx context.Context, req *rpc.EngineR
return nil, err
}
} else {
var localSync *etypes.FileLocalSync
if req.LocalSync != nil {
localSync = &etypes.FileLocalSync{
SourcePath: req.LocalSync.SourcePath,
TargetPath: req.LocalSync.TargetPath,
}
}
if err := task.AddReplica(req.Size, req.CurrentSize, req.ReplicaAddress, req.ReplicaName,
int(req.FileSyncHttpClientTimeout), req.FastSync, req.GrpcTimeoutSeconds); err != nil {
int(req.FileSyncHttpClientTimeout), req.FastSync, localSync, req.GrpcTimeoutSeconds); err != nil {
return nil, err
}
}
Expand Down

0 comments on commit 17dde47

Please sign in to comment.