Skip to content

Commit f9a4d02

Browse files
committed
Make long gRPC timeout configurable
longhorn-2765 Signed-off-by: Phan Le <[email protected]>
1 parent 2fa2614 commit f9a4d02

File tree

10 files changed

+347
-321
lines changed

10 files changed

+347
-321
lines changed

app/cmd/add_replica.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,12 @@ func addReplica(c *cli.Context) error {
9292

9393
fastSync := c.Bool("fast-sync")
9494
fileSyncHTTPClientTimeout := c.Int("file-sync-http-client-timeout")
95+
grpcTimeoutSeconds := c.Int64("grpc-timeout-seconds")
9596

9697
if c.Bool("restore") {
9798
return task.AddRestoreReplica(volumeSize, volumeCurrentSize, replica, replicaInstanceName)
9899
}
99-
return task.AddReplica(volumeSize, volumeCurrentSize, replica, replicaInstanceName, fileSyncHTTPClientTimeout, fastSync)
100+
return task.AddReplica(volumeSize, volumeCurrentSize, replica, replicaInstanceName, fileSyncHTTPClientTimeout, fastSync, grpcTimeoutSeconds)
100101
}
101102

102103
func StartWithReplicasCmd() cli.Command {

app/cmd/snapshot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ func cloneSnapshot(c *cli.Context) error {
469469
defer fromControllerClient.Close()
470470

471471
if err := sync.CloneSnapshot(controllerClient, fromControllerClient, volumeName, fromVolumeName,
472-
snapshotName, exportBackingImageIfExist, fileSyncHTTPClientTimeout); err != nil {
472+
snapshotName, exportBackingImageIfExist, fileSyncHTTPClientTimeout, 0); err != nil {
473473
return err
474474
}
475475
return nil

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ require (
2828
k8s.io/mount-utils v0.30.0
2929
)
3030

31+
replace github.com/longhorn/types => ../types
32+
3133
require (
3234
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1 // indirect
3335
github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ github.com/longhorn/go-iscsi-helper v0.0.0-20240427164656-e9439c0018ce h1:PxKniE
7474
github.com/longhorn/go-iscsi-helper v0.0.0-20240427164656-e9439c0018ce/go.mod h1:d9t3gtE+UPjescbCFluXd4xBc8OQT/JrC2cdkk2IXWQ=
7575
github.com/longhorn/sparse-tools v0.0.0-20240427164751-a7b9f1b2c8a8 h1:lwtmZEomiv8uchwo9JIyoo+lK8J3cLCm7/qzpn6wmzo=
7676
github.com/longhorn/sparse-tools v0.0.0-20240427164751-a7b9f1b2c8a8/go.mod h1:pvlUkVwRGojXhcTkkzksOe4i7GVk59P2PbJjHIB2Yj0=
77-
github.com/longhorn/types v0.0.0-20240605091135-ef450e1c04cd h1:gzvHnEc4vdHmOtxwgjC/7YmChbzDsfYiY0wpI3RgB1A=
78-
github.com/longhorn/types v0.0.0-20240605091135-ef450e1c04cd/go.mod h1:1oEh1cnDDqNSuFh/dH/lvJ3Ssq83SOweTAAPLRY4PMI=
7977
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
8078
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
8179
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=

pkg/controller/rebuild.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func syncFile(from, to, fromAddress, toAddress, volumeName, toInstanceName strin
118118
strHostPort := net.JoinHostPort(host, strconv.Itoa(int(port)))
119119

120120
logrus.Infof("Synchronizing %s to %s:%s", from, to, strHostPort)
121-
err = fromClient.SendFile(from, host, port, fileSyncHTTPClientTimeout, fastSync)
121+
err = fromClient.SendFile(from, host, port, fileSyncHTTPClientTimeout, fastSync, 0)
122122
if err != nil {
123123
logrus.WithError(err).Errorf("failed to synchronize %s to %s:%s", from, to, strHostPort)
124124
} else {

pkg/replica/client/client.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,16 @@ func (c *ReplicaClient) RenameFile(oldFileName, newFileName string) error {
442442
return nil
443443
}
444444

445-
func (c *ReplicaClient) SendFile(from, host string, port int32, fileSyncHTTPClientTimeout int, fastSync bool) error {
445+
func (c *ReplicaClient) SendFile(from, host string, port int32, fileSyncHTTPClientTimeout int, fastSync bool, grpcTimeoutSeconds int64) error {
446446
syncAgentServiceClient, err := c.getSyncServiceClient()
447447
if err != nil {
448448
return err
449449
}
450-
ctx, cancel := context.WithTimeout(context.Background(), GRPCServiceLongTimeout)
450+
grpcTimeout := GRPCServiceLongTimeout
451+
if grpcTimeoutSeconds > 0 {
452+
grpcTimeout = time.Second * time.Duration(grpcTimeoutSeconds)
453+
}
454+
ctx, cancel := context.WithTimeout(context.Background(), grpcTimeout)
451455
defer cancel()
452456

453457
if _, err := syncAgentServiceClient.FileSend(ctx, &enginerpc.FileSendRequest{
@@ -502,12 +506,16 @@ func (c *ReplicaClient) LaunchReceiver(toFilePath string) (string, int32, error)
502506
return c.host, reply.Port, nil
503507
}
504508

505-
func (c *ReplicaClient) SyncFiles(fromAddress string, list []types.SyncFileInfo, fileSyncHTTPClientTimeout int, fastSync bool) error {
509+
func (c *ReplicaClient) SyncFiles(fromAddress string, list []types.SyncFileInfo, fileSyncHTTPClientTimeout int, fastSync bool, grpcTimeoutSeconds int64) error {
506510
syncAgentServiceClient, err := c.getSyncServiceClient()
507511
if err != nil {
508512
return err
509513
}
510-
ctx, cancel := context.WithTimeout(context.Background(), GRPCServiceLongTimeout)
514+
grpcTimeout := GRPCServiceLongTimeout
515+
if grpcTimeoutSeconds > 0 {
516+
grpcTimeout = time.Second * time.Duration(grpcTimeoutSeconds)
517+
}
518+
ctx, cancel := context.WithTimeout(context.Background(), grpcTimeout)
511519
defer cancel()
512520

513521
if _, err := syncAgentServiceClient.FilesSync(ctx, &enginerpc.FilesSyncRequest{
@@ -516,6 +524,7 @@ func (c *ReplicaClient) SyncFiles(fromAddress string, list []types.SyncFileInfo,
516524
SyncFileInfoList: syncFileInfoListToSyncAgentGRPCFormat(list),
517525
FastSync: fastSync,
518526
FileSyncHttpClientTimeout: int32(fileSyncHTTPClientTimeout),
527+
GrpcTimeoutSeconds: grpcTimeoutSeconds,
519528
}); err != nil {
520529
return errors.Wrapf(err, "failed to sync files %+v from %v", list, fromAddress)
521530
}
@@ -686,12 +695,16 @@ func (c *ReplicaClient) ReplicaRebuildStatus() (*enginerpc.ReplicaRebuildStatusR
686695
return status, nil
687696
}
688697

689-
func (c *ReplicaClient) CloneSnapshot(fromAddress, fromVolumeName, snapshotFileName string, exportBackingImageIfExist bool, fileSyncHTTPClientTimeout int) error {
698+
func (c *ReplicaClient) CloneSnapshot(fromAddress, fromVolumeName, snapshotFileName string, exportBackingImageIfExist bool, fileSyncHTTPClientTimeout int, grpcTimeoutSeconds int64) error {
690699
syncAgentServiceClient, err := c.getSyncServiceClient()
691700
if err != nil {
692701
return err
693702
}
694-
ctx, cancel := context.WithTimeout(context.Background(), GRPCServiceLongTimeout)
703+
grpcTimeout := GRPCServiceLongTimeout
704+
if grpcTimeoutSeconds > 0 {
705+
grpcTimeout = time.Second * time.Duration(grpcTimeoutSeconds)
706+
}
707+
ctx, cancel := context.WithTimeout(context.Background(), grpcTimeout)
695708
defer cancel()
696709

697710
if _, err := syncAgentServiceClient.SnapshotClone(ctx, &enginerpc.SnapshotCloneRequest{

pkg/sync/rpc/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ func (s *SyncAgentServer) FilesSync(ctx context.Context, req *enginerpc.FilesSyn
467467
if err != nil {
468468
return nil, errors.Wrapf(err, "failed to launch receiver for file %v", info.ToFileName)
469469
}
470-
if err := fromClient.SendFile(info.FromFileName, req.ToHost, int32(port), int(req.FileSyncHttpClientTimeout), req.FastSync); err != nil {
470+
if err := fromClient.SendFile(info.FromFileName, req.ToHost, int32(port), int(req.FileSyncHttpClientTimeout), req.FastSync, req.GrpcTimeoutSeconds); err != nil {
471471
return nil, errors.Wrapf(err, "replica %v failed to send file %v to %v:%v", req.FromAddress, info.ToFileName, req.ToHost, port)
472472
}
473473
}

pkg/sync/sync.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ func (t *Task) VerifyRebuildReplica(address, instanceName string) error {
412412
return nil
413413
}
414414

415-
func (t *Task) AddReplica(volumeSize, volumeCurrentSize int64, address, instanceName string, fileSyncHTTPClientTimeout int, fastSync bool) error {
415+
func (t *Task) AddReplica(volumeSize, volumeCurrentSize int64, address, instanceName string, fileSyncHTTPClientTimeout int, fastSync bool, grpcTimeoutSeconds int64) error {
416416
volume, err := t.client.VolumeGet()
417417
if err != nil {
418418
return err
@@ -459,7 +459,7 @@ func (t *Task) AddReplica(volumeSize, volumeCurrentSize int64, address, instance
459459
return fmt.Errorf("sync file list shouldn't contain volume head")
460460
}
461461

462-
if err = toClient.SyncFiles(fromAddress, resp, fileSyncHTTPClientTimeout, fastSync); err != nil {
462+
if err = toClient.SyncFiles(fromAddress, resp, fileSyncHTTPClientTimeout, fastSync, grpcTimeoutSeconds); err != nil {
463463
return err
464464
}
465465

@@ -808,7 +808,7 @@ func (t *Task) RebuildStatus() (map[string]*ReplicaRebuildStatus, error) {
808808
}
809809

810810
func CloneSnapshot(engineControllerClient, fromControllerClient *client.ControllerClient, volumeName, fromVolumeName,
811-
snapshotFileName string, exportBackingImageIfExist bool, fileSyncHTTPClientTimeout int) error {
811+
snapshotFileName string, exportBackingImageIfExist bool, fileSyncHTTPClientTimeout int, grpcTimeoutSeconds int64) error {
812812
replicas, err := fromControllerClient.ReplicaList()
813813
if err != nil {
814814
return err
@@ -851,7 +851,7 @@ func CloneSnapshot(engineControllerClient, fromControllerClient *client.Controll
851851
}
852852
defer repClient.Close()
853853
if err := repClient.CloneSnapshot(sourceReplica.Address, fromVolumeName, snapshotFileName,
854-
exportBackingImageIfExist, fileSyncHTTPClientTimeout); err != nil {
854+
exportBackingImageIfExist, fileSyncHTTPClientTimeout, grpcTimeoutSeconds); err != nil {
855855
syncErrorMap.Store(r.Address, err)
856856
}
857857
}(r)

0 commit comments

Comments
 (0)