Browse Source

fix: cache successful volume lookups instead of failed ones (#7698)

The condition was inverted - it was caching lookups with errors
instead of successful lookups. This caused every replicated write
to make a gRPC call to master for volume location lookup, resulting
in ~1 second latency for writeToReplicas.

The bug particularly affected TTL volumes because:
- More unique volumes are created (separate pools per TTL)
- Volumes expire and get recreated frequently
- Each new volume requires a fresh lookup (cache miss)
- Higher volume churn = more cache misses = more master lookups

With this fix, successful lookups are cached for 10 minutes,
reducing replication latency from ~1s to ~10ms for cached volumes.
pull/7700/head
Chris Lu 7 days ago
committed by GitHub
parent
commit
ae7333d28e
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 7
      weed/operation/lookup.go

7
weed/operation/lookup.go

@ -4,12 +4,13 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/seaweedfs/seaweedfs/weed/pb"
"google.golang.org/grpc"
"math/rand/v2" "math/rand/v2"
"strings" "strings"
"time" "time"
"github.com/seaweedfs/seaweedfs/weed/pb"
"google.golang.org/grpc"
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb" "github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
) )
@ -101,7 +102,7 @@ func LookupVolumeIds(masterFn GetMasterFn, grpcDialOption grpc.DialOption, vids
GrpcPort: int(loc.GrpcPort), GrpcPort: int(loc.GrpcPort),
}) })
} }
if vidLocations.Error != "" {
if vidLocations.Error == "" {
vc.Set(vidLocations.VolumeOrFileId, locations, 10*time.Minute) vc.Set(vidLocations.VolumeOrFileId, locations, 10*time.Minute)
} }
ret[vidLocations.VolumeOrFileId] = &LookupResult{ ret[vidLocations.VolumeOrFileId] = &LookupResult{

Loading…
Cancel
Save