From 6c20a3b622c431f3245c9996b8ca093bd768c106 Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Mon, 27 Jun 2022 21:47:05 +0500 Subject: [PATCH 1/2] avoid set currentMaster k8s svc.local discoveruy service domains https://github.com/chrislusf/seaweedfs/issues/2589 --- weed/security/tls.go | 2 +- weed/server/master_grpc_server.go | 8 ++++++-- weed/wdclient/masterclient.go | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/weed/security/tls.go b/weed/security/tls.go index 137b7d06a..bfa9d43c7 100644 --- a/weed/security/tls.go +++ b/weed/security/tls.go @@ -35,7 +35,7 @@ func LoadServerTLS(config *util.ViperProxy, component string) (grpc.ServerOption serverIdentityProvider, err := pemfile.NewProvider(serverOptions) if err != nil { - glog.Warningf("pemfile.NewProvider(%v) failed: %v", serverOptions, err) + glog.Warningf("pemfile.NewProvider(%v) %v failed: %v", serverOptions, component, err) return nil, nil } diff --git a/weed/server/master_grpc_server.go b/weed/server/master_grpc_server.go index 4d0fbbc41..4f5455cb1 100644 --- a/weed/server/master_grpc_server.go +++ b/weed/server/master_grpc_server.go @@ -263,8 +263,12 @@ func (ms *MasterServer) KeepConnected(stream master_pb.Seaweed_KeepConnectedServ } ms.deleteClient(clientName) }() - - for _, message := range ms.Topo.ToVolumeLocations() { + for i, message := range ms.Topo.ToVolumeLocations() { + if i == 0 { + if leader, err := ms.Topo.Leader(); err == nil { + message.Leader = string(leader) + } + } if sendErr := stream.Send(&master_pb.KeepConnectedResponse{VolumeLocation: message}); sendErr != nil { return sendErr } diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go index fb681b523..0e58a3753 100644 --- a/weed/wdclient/masterclient.go +++ b/weed/wdclient/masterclient.go @@ -168,8 +168,8 @@ func (mc *MasterClient) tryConnectToMaster(master pb.ServerAddress) (nextHintedL } // check if it is the leader to determine whether to reset the vidMap - if resp.VolumeLocation != nil && resp.VolumeLocation.Leader != "" { - glog.V(0).Infof("redirected to leader %v", resp.VolumeLocation.Leader) + if resp.VolumeLocation != nil && resp.VolumeLocation.Leader != "" && string(master) != resp.VolumeLocation.Leader { + glog.V(0).Infof("master %v redirected to leader %v", master, resp.VolumeLocation.Leader) nextHintedLeader = pb.ServerAddress(resp.VolumeLocation.Leader) stats.MasterClientConnectCounter.WithLabelValues(stats.RedirectedToleader).Inc() return nil From 9bff097b01e92ea3505757b9a0b8a36db85e810a Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Mon, 27 Jun 2022 21:55:16 +0500 Subject: [PATCH 2/2] currentMaster redirected --- weed/wdclient/masterclient.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go index 0e58a3753..35f1c4cf8 100644 --- a/weed/wdclient/masterclient.go +++ b/weed/wdclient/masterclient.go @@ -188,8 +188,8 @@ func (mc *MasterClient) tryConnectToMaster(master pb.ServerAddress) (nextHintedL if resp.VolumeLocation != nil { // maybe the leader is changed - if resp.VolumeLocation.Leader != "" { - glog.V(0).Infof("redirected to leader %v", resp.VolumeLocation.Leader) + if resp.VolumeLocation.Leader != "" && string(mc.currentMaster) != resp.VolumeLocation.Leader { + glog.V(0).Infof("currentMaster %v redirected to leader %v", mc.currentMaster, resp.VolumeLocation.Leader) nextHintedLeader = pb.ServerAddress(resp.VolumeLocation.Leader) stats.MasterClientConnectCounter.WithLabelValues(stats.RedirectedToleader).Inc() return nil