mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
add context.Context
This commit is contained in:
parent
55bab1b456
commit
42cb05c088
|
@ -53,9 +53,9 @@ func (mc *MasterClient) KeepConnectedToMaster() {
|
||||||
func (mc *MasterClient) tryAllMasters() {
|
func (mc *MasterClient) tryAllMasters() {
|
||||||
for _, master := range mc.masters {
|
for _, master := range mc.masters {
|
||||||
glog.V(0).Infof("Connecting to master %v", master)
|
glog.V(0).Infof("Connecting to master %v", master)
|
||||||
gprcErr := withMasterClient(context.Background(), master, mc.grpcDialOption, func(client master_pb.SeaweedClient) error {
|
gprcErr := withMasterClient(context.Background(), master, mc.grpcDialOption, func(ctx context.Context, client master_pb.SeaweedClient) error {
|
||||||
|
|
||||||
stream, err := client.KeepConnected(context.Background())
|
stream, err := client.KeepConnected(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(0).Infof("failed to keep connected to %s: %v", master, err)
|
glog.V(0).Infof("failed to keep connected to %s: %v", master, err)
|
||||||
return err
|
return err
|
||||||
|
@ -99,7 +99,7 @@ func (mc *MasterClient) tryAllMasters() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func withMasterClient(ctx context.Context, master string, grpcDialOption grpc.DialOption, fn func(client master_pb.SeaweedClient) error) error {
|
func withMasterClient(ctx context.Context, master string, grpcDialOption grpc.DialOption, fn func(ctx context.Context, client master_pb.SeaweedClient) error) error {
|
||||||
|
|
||||||
masterGrpcAddress, parseErr := util.ParseServerToGrpcAddress(master, 0)
|
masterGrpcAddress, parseErr := util.ParseServerToGrpcAddress(master, 0)
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
|
@ -114,5 +114,5 @@ func withMasterClient(ctx context.Context, master string, grpcDialOption grpc.Di
|
||||||
|
|
||||||
client := master_pb.NewSeaweedClient(grpcConnection)
|
client := master_pb.NewSeaweedClient(grpcConnection)
|
||||||
|
|
||||||
return fn(client)
|
return fn(ctx, client)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue