From d9e19cc49bc5cc0fd81d544d4f8aa68bec5eb5f0 Mon Sep 17 00:00:00 2001 From: chrislu Date: Thu, 30 Oct 2025 17:15:30 -0700 Subject: [PATCH] clean up --- weed/server/filer_grpc_server.go | 51 ++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/weed/server/filer_grpc_server.go b/weed/server/filer_grpc_server.go index 4606f8f6f..6773717ec 100644 --- a/weed/server/filer_grpc_server.go +++ b/weed/server/filer_grpc_server.go @@ -18,6 +18,7 @@ import ( "github.com/seaweedfs/seaweedfs/weed/pb/master_pb" "github.com/seaweedfs/seaweedfs/weed/storage/needle" "github.com/seaweedfs/seaweedfs/weed/util" + "github.com/seaweedfs/seaweedfs/weed/wdclient" ) func (fs *FilerServer) LookupDirectoryEntry(ctx context.Context, req *filer_pb.LookupDirectoryEntryRequest) (*filer_pb.LookupDirectoryEntryResponse, error) { @@ -97,7 +98,6 @@ func (fs *FilerServer) LookupVolume(ctx context.Context, req *filer_pb.LookupVol // Collect volume IDs that are not in cache for batch lookup var vidsToLookup []string - vidMap := make(map[string]uint32) for _, vidString := range req.VolumeIds { vid, err := strconv.Atoi(vidString) @@ -105,23 +105,13 @@ func (fs *FilerServer) LookupVolume(ctx context.Context, req *filer_pb.LookupVol glog.V(1).InfofCtx(ctx, "Unknown volume id %s", vidString) return nil, err } - vidMap[vidString] = uint32(vid) // Check cache first locations, found := fs.filer.MasterClient.GetLocations(uint32(vid)) if found && len(locations) > 0 { // Found in cache - var locs []*filer_pb.Location - for _, loc := range locations { - locs = append(locs, &filer_pb.Location{ - Url: loc.Url, - PublicUrl: loc.PublicUrl, - GrpcPort: uint32(loc.GrpcPort), - DataCenter: loc.DataCenter, - }) - } resp.LocationsMap[vidString] = &filer_pb.Locations{ - Locations: locs, + Locations: wdclientLocationsToPb(locations), } } else { // Not in cache, need to query master @@ -152,16 +142,7 @@ func (fs *FilerServer) LookupVolume(ctx context.Context, req *filer_pb.LookupVol parts := strings.Split(vidString, ",") vidOnly := parts[0] - var locs []*filer_pb.Location - for _, masterLoc := range vidLoc.Locations { - locs = append(locs, &filer_pb.Location{ - Url: masterLoc.Url, - PublicUrl: masterLoc.PublicUrl, - GrpcPort: masterLoc.GrpcPort, - DataCenter: masterLoc.DataCenter, - }) - } - + locs := masterLocationsToPb(vidLoc.Locations) if len(locs) > 0 { resp.LocationsMap[vidOnly] = &filer_pb.Locations{ Locations: locs, @@ -180,6 +161,32 @@ func (fs *FilerServer) LookupVolume(ctx context.Context, req *filer_pb.LookupVol return resp, nil } +func wdclientLocationsToPb(locations []wdclient.Location) []*filer_pb.Location { + var locs []*filer_pb.Location + for _, loc := range locations { + locs = append(locs, &filer_pb.Location{ + Url: loc.Url, + PublicUrl: loc.PublicUrl, + GrpcPort: uint32(loc.GrpcPort), + DataCenter: loc.DataCenter, + }) + } + return locs +} + +func masterLocationsToPb(masterLocs []*master_pb.Location) []*filer_pb.Location { + var locs []*filer_pb.Location + for _, masterLoc := range masterLocs { + locs = append(locs, &filer_pb.Location{ + Url: masterLoc.Url, + PublicUrl: masterLoc.PublicUrl, + GrpcPort: masterLoc.GrpcPort, + DataCenter: masterLoc.DataCenter, + }) + } + return locs +} + func (fs *FilerServer) lookupFileId(ctx context.Context, fileId string) (targetUrls []string, err error) { fid, err := needle.ParseFileIdFromString(fileId) if err != nil {