From 9e00484c21a7cc4730f189c813cf986447879467 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 26 Nov 2025 10:44:14 -0800 Subject: [PATCH] Update current filer after successful failover MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- weed/s3api/s3api_handlers.go | 2 +- weed/wdclient/filer_client.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/weed/s3api/s3api_handlers.go b/weed/s3api/s3api_handlers.go index de9f98a36..584d51230 100644 --- a/weed/s3api/s3api_handlers.go +++ b/weed/s3api/s3api_handlers.go @@ -62,7 +62,7 @@ func (s3a *S3ApiServer) withFilerClientFailover(streamingMode bool, fn func(file if err == nil { // 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) return nil } diff --git a/weed/wdclient/filer_client.go b/weed/wdclient/filer_client.go index 057cedf19..728f5a7b2 100644 --- a/weed/wdclient/filer_client.go +++ b/weed/wdclient/filer_client.go @@ -217,6 +217,22 @@ func (fc *FilerClient) GetAllFilers() []pb.ServerAddress { 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 // Safe to call multiple times (idempotent) func (fc *FilerClient) Close() {