diff options
| author | chrislu <chris.lu@gmail.com> | 2025-10-30 19:41:48 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2025-10-30 19:41:48 -0700 |
| commit | d1428df1df4ca6ff01d242134f5b211bdc783b86 (patch) | |
| tree | dfc1d06d314e2570eca110041b921063c6e36c2c | |
| parent | 6b2f5147b983bcf7086f0087c605a2b50d3a3645 (diff) | |
| download | seaweedfs-d1428df1df4ca6ff01d242134f5b211bdc783b86.tar.xz seaweedfs-d1428df1df4ca6ff01d242134f5b211bdc783b86.zip | |
address comments
| -rw-r--r-- | weed/server/filer_grpc_server.go | 2 | ||||
| -rw-r--r-- | weed/wdclient/masterclient.go | 17 |
2 files changed, 13 insertions, 6 deletions
diff --git a/weed/server/filer_grpc_server.go b/weed/server/filer_grpc_server.go index e79f26385..02eceebde 100644 --- a/weed/server/filer_grpc_server.go +++ b/weed/server/filer_grpc_server.go @@ -109,7 +109,7 @@ func (fs *FilerServer) LookupVolume(ctx context.Context, req *filer_pb.LookupVol } func wdclientLocationsToPb(locations []wdclient.Location) []*filer_pb.Location { - var locs []*filer_pb.Location + locs := make([]*filer_pb.Location, 0, len(locations)) for _, loc := range locations { locs = append(locs, &filer_pb.Location{ Url: loc.Url, diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go index 8ed8573a3..62ced6daf 100644 --- a/weed/wdclient/masterclient.go +++ b/weed/wdclient/masterclient.go @@ -114,12 +114,15 @@ func (mc *MasterClient) LookupVolumeIdsWithFallback(ctx context.Context, volumeI var needsLookup []string var lookupErrors []error - // Check cache first and separate volumes that need lookup + // Check cache first and parse volume IDs once + vidStringToUint := make(map[string]uint32, len(volumeIds)) for _, vidString := range volumeIds { vid, err := strconv.ParseUint(vidString, 10, 32) if err != nil { return nil, fmt.Errorf("invalid volume id %s: %v", vidString, err) } + vidStringToUint[vidString] = uint32(vid) + locations, found := mc.GetLocations(uint32(vid)) if found && len(locations) > 0 { result[vidString] = locations @@ -143,8 +146,8 @@ func (mc *MasterClient) LookupVolumeIdsWithFallback(ctx context.Context, volumeI batchResult := make(map[string][]Location) for _, vidString := range needsLookup { - vid, _ := strconv.ParseUint(vidString, 10, 32) - if locations, found := mc.GetLocations(uint32(vid)); found && len(locations) > 0 { + vid := vidStringToUint[vidString] // Use pre-parsed value + if locations, found := mc.GetLocations(vid); found && len(locations) > 0 { batchResult[vidString] = locations } else { stillNeedLookup = append(stillNeedLookup, vidString) @@ -224,9 +227,13 @@ func (mc *MasterClient) LookupVolumeIdsWithFallback(ctx context.Context, volumeI } } - // Return aggregated errors + // Return aggregated errors with clear formatting if len(lookupErrors) > 0 { - return result, fmt.Errorf("lookup errors: %v", lookupErrors) + errorMessages := make([]string, 0, len(lookupErrors)) + for _, err := range lookupErrors { + errorMessages = append(errorMessages, err.Error()) + } + return result, fmt.Errorf("lookup errors: %s", strings.Join(errorMessages, "; ")) } return result, nil |
