Browse Source

Update current filer after successful failover

Address code review: https://github.com/seaweedfs/seaweedfs/pull/7550#pullrequestreview-3512223723

**Issue:**
After successful failover, the current filer index was not updated.
This meant every subsequent request would still try the (potentially
unhealthy) original filer first, then failover again.

**Solution:**

1. Added FilerClient.SetCurrentFiler(addr) method:
   - Finds the index of specified filer address
   - Atomically updates filerIndex to point to it
   - Thread-safe with RLock

2. Call SetCurrentFiler after successful failover:
   - Update happens immediately after successful connection
   - Future requests start with the known-healthy filer
   - Reduces unnecessary failover attempts

**Benefits:**
 Subsequent requests use healthy filer directly
 No repeated failover to same unhealthy filer
 Better performance - fast path hits healthy filer
 Comment now matches actual behavior
pull/7550/head
Chris Lu 1 week ago
parent
commit
9e00484c21
  1. 2
      weed/s3api/s3api_handlers.go
  2. 16
      weed/wdclient/filer_client.go

2
weed/s3api/s3api_handlers.go

@ -62,7 +62,7 @@ func (s3a *S3ApiServer) withFilerClientFailover(streamingMode bool, fn func(file
if err == nil { if err == nil {
// Success! Update current filer for future requests // Success! Update current filer for future requests
// This is a simple round-robin update - could be improved with health tracking
s3a.filerClient.SetCurrentFiler(filer)
glog.V(1).Infof("WithFilerClient: failover from %s to %s succeeded", currentFiler, filer) glog.V(1).Infof("WithFilerClient: failover from %s to %s succeeded", currentFiler, filer)
return nil return nil
} }

16
weed/wdclient/filer_client.go

@ -217,6 +217,22 @@ func (fc *FilerClient) GetAllFilers() []pb.ServerAddress {
return filers return filers
} }
// SetCurrentFiler updates the current filer index to the specified address
// This is useful after successful failover to prefer the healthy filer for future requests
func (fc *FilerClient) SetCurrentFiler(addr pb.ServerAddress) {
fc.filerAddressesMu.RLock()
defer fc.filerAddressesMu.RUnlock()
// Find the index of the specified filer address
for i, filer := range fc.filerAddresses {
if filer == addr {
atomic.StoreInt32(&fc.filerIndex, int32(i))
return
}
}
// If address not found, leave index unchanged
}
// Close stops the filer discovery goroutine if running // Close stops the filer discovery goroutine if running
// Safe to call multiple times (idempotent) // Safe to call multiple times (idempotent)
func (fc *FilerClient) Close() { func (fc *FilerClient) Close() {

Loading…
Cancel
Save