From 0c8e033e686e8919d3b0187148191248ae1f2648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E6=98=8C=E6=9E=97?= Date: Fri, 24 Jun 2022 17:41:46 +0800 Subject: [PATCH 1/2] When the connection with the leader is disconnected, the vidMap should not be reset immediately, but should be reset after connecting to a new leader --- weed/wdclient/masterclient.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go index 244a3921a..154074fc3 100644 --- a/weed/wdclient/masterclient.go +++ b/weed/wdclient/masterclient.go @@ -98,7 +98,6 @@ func (mc *MasterClient) tryAllMasters() { } mc.currentMaster = "" - mc.vidMap = newVidMap("") } } @@ -126,9 +125,26 @@ func (mc *MasterClient) tryConnectToMaster(master pb.ServerAddress) (nextHintedL stats.MasterClientConnectCounter.WithLabelValues(stats.FailedToSend).Inc() return err } - glog.V(1).Infof("%s.%s masterClient Connected to %v", mc.FilerGroup, mc.clientType, master) + + //reset vidMap only when masterClient successfully connected to new leader + resp, err := stream.Recv() + if err != nil { + glog.V(0).Infof("%s.%s masterClient failed to receive from %s: %v", mc.FilerGroup, mc.clientType, master, err) + stats.MasterClientConnectCounter.WithLabelValues(stats.FailedToReceive).Inc() + return err + } + if resp.VolumeLocation != nil { + //immediately check whether it is the leader + if resp.VolumeLocation.Leader != "" { + glog.V(0).Infof("redirected to leader %v", resp.VolumeLocation.Leader) + nextHintedLeader = pb.ServerAddress(resp.VolumeLocation.Leader) + stats.MasterClientConnectCounter.WithLabelValues(stats.RedirectedToleader).Inc() + return nil + } + } mc.currentMaster = master + mc.vidMap = newVidMap("") for { resp, err := stream.Recv() From f1ea906c13177fc719797f5ea9bf5b870a32f500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E6=98=8C=E6=9E=97?= Date: Sat, 25 Jun 2022 11:56:09 +0800 Subject: [PATCH 2/2] Code comment optimization --- weed/wdclient/masterclient.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go index 154074fc3..da151ddcf 100644 --- a/weed/wdclient/masterclient.go +++ b/weed/wdclient/masterclient.go @@ -127,22 +127,21 @@ func (mc *MasterClient) tryConnectToMaster(master pb.ServerAddress) (nextHintedL } glog.V(1).Infof("%s.%s masterClient Connected to %v", mc.FilerGroup, mc.clientType, master) - //reset vidMap only when masterClient successfully connected to new leader resp, err := stream.Recv() if err != nil { glog.V(0).Infof("%s.%s masterClient failed to receive from %s: %v", mc.FilerGroup, mc.clientType, master, err) stats.MasterClientConnectCounter.WithLabelValues(stats.FailedToReceive).Inc() return err } - if resp.VolumeLocation != nil { - //immediately check whether it is the leader - if resp.VolumeLocation.Leader != "" { - glog.V(0).Infof("redirected to leader %v", resp.VolumeLocation.Leader) - nextHintedLeader = pb.ServerAddress(resp.VolumeLocation.Leader) - stats.MasterClientConnectCounter.WithLabelValues(stats.RedirectedToleader).Inc() - return nil - } + + // 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) + nextHintedLeader = pb.ServerAddress(resp.VolumeLocation.Leader) + stats.MasterClientConnectCounter.WithLabelValues(stats.RedirectedToleader).Inc() + return nil } + mc.currentMaster = master mc.vidMap = newVidMap("")