aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2022-06-24 02:08:57 -0700
committerchrislu <chris.lu@gmail.com>2022-06-24 02:08:57 -0700
commit9c517d2b358da00c6d8fe638eaa6e8551c65aa8d (patch)
treef07d65d0fd74d94c7c812c9c1d11280ef7f128f9
parent280e33092cde63e7b10ec61e911824e4f3bcc533 (diff)
downloadseaweedfs-9c517d2b358da00c6d8fe638eaa6e8551c65aa8d.tar.xz
seaweedfs-9c517d2b358da00c6d8fe638eaa6e8551c65aa8d.zip
masterclient: fallback to directly querying master in case of missing volume id location
-rw-r--r--weed/wdclient/masterclient.go30
-rw-r--r--weed/wdclient/vid_map.go4
2 files changed, 30 insertions, 4 deletions
diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go
index 244a3921a..a6f7e49a4 100644
--- a/weed/wdclient/masterclient.go
+++ b/weed/wdclient/masterclient.go
@@ -38,6 +38,36 @@ func NewMasterClient(grpcDialOption grpc.DialOption, filerGroup string, clientTy
}
}
+func (mc *MasterClient) GetLookupFileIdFunction() LookupFileIdFunctionType {
+ return mc.LookupFileIdWithFallback
+}
+
+func (mc *MasterClient) LookupFileIdWithFallback(fileId string) (fullUrls []string, err error) {
+ fullUrls, err = mc.vidMap.LookupFileId(fileId)
+ err = pb.WithMasterClient(false, mc.currentMaster, mc.grpcDialOption, func(client master_pb.SeaweedClient) error {
+ resp, err := client.LookupVolume(context.Background(), &master_pb.LookupVolumeRequest{
+ VolumeOrFileIds: []string{fileId},
+ })
+ if err != nil {
+ return err
+ }
+ for vid, vidLocation := range resp.VolumeIdLocations {
+ for _, vidLoc := range vidLocation.Locations {
+ loc := Location{
+ Url: vidLoc.Url,
+ PublicUrl: vidLoc.PublicUrl,
+ GrpcPort: int(vidLoc.GrpcPort),
+ }
+ mc.vidMap.addLocation(uint32(vid), loc)
+ fullUrls = append(fullUrls, loc.Url)
+ }
+ }
+
+ return nil
+ })
+ return
+}
+
func (mc *MasterClient) GetMaster() pb.ServerAddress {
mc.WaitUntilConnected()
return mc.currentMaster
diff --git a/weed/wdclient/vid_map.go b/weed/wdclient/vid_map.go
index f7a9a0f1a..754c77051 100644
--- a/weed/wdclient/vid_map.go
+++ b/weed/wdclient/vid_map.go
@@ -90,10 +90,6 @@ func (vc *vidMap) LookupVolumeServerUrl(vid string) (serverUrls []string, err er
return
}
-func (vc *vidMap) GetLookupFileIdFunction() LookupFileIdFunctionType {
- return vc.LookupFileId
-}
-
func (vc *vidMap) LookupFileId(fileId string) (fullUrls []string, err error) {
parts := strings.Split(fileId, ",")
if len(parts) != 2 {