From 746677ca46745f8db3efae97899d870540a6d455 Mon Sep 17 00:00:00 2001 From: chrislu Date: Tue, 28 Oct 2025 20:08:48 -0700 Subject: [PATCH] refactor --- weed/remote_storage/azure/azure_storage_client.go | 9 +++++++++ weed/replication/sink/azuresink/azure_sink.go | 14 ++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/weed/remote_storage/azure/azure_storage_client.go b/weed/remote_storage/azure/azure_storage_client.go index 2dff07d3e..fecbd4070 100644 --- a/weed/remote_storage/azure/azure_storage_client.go +++ b/weed/remote_storage/azure/azure_storage_client.go @@ -28,12 +28,21 @@ import ( const ( defaultBlockSize = 4 * 1024 * 1024 defaultConcurrency = 16 + + // DefaultAzureOpTimeout is the timeout for individual Azure blob operations. + // This should be larger than the maximum time the Azure SDK client will spend + // retrying (MaxRetries=3 × TryTimeout=10s + retry delays ≈ 33s), so we use 60s + // to provide a reasonable buffer while still failing faster than indefinite hangs. + DefaultAzureOpTimeout = 60 * time.Second ) // DefaultAzBlobClientOptions returns the default Azure blob client options // with consistent retry configuration across the application. // This centralizes the retry policy to ensure uniform behavior between // remote storage and replication sink implementations. +// +// Related: Use DefaultAzureOpTimeout for context.WithTimeout when calling Azure operations +// to ensure the timeout accommodates all retry attempts configured here. func DefaultAzBlobClientOptions() *azblob.ClientOptions { return &azblob.ClientOptions{ ClientOptions: azcore.ClientOptions{ diff --git a/weed/replication/sink/azuresink/azure_sink.go b/weed/replication/sink/azuresink/azure_sink.go index 5ef30d4a5..a236c0de4 100644 --- a/weed/replication/sink/azuresink/azure_sink.go +++ b/weed/replication/sink/azuresink/azure_sink.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "strings" - "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming" "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" @@ -23,11 +22,6 @@ import ( "github.com/seaweedfs/seaweedfs/weed/util" ) -const ( - // azureOpTimeout is the timeout for individual Azure blob operations - azureOpTimeout = 30 * time.Second -) - type AzureSink struct { client *azblob.Client container string @@ -135,7 +129,7 @@ func (g *AzureSink) CreateEntry(key string, entry *filer_pb.Entry, signatures [] appendBlobClient := g.client.ServiceClient().NewContainerClient(g.container).NewAppendBlobClient(key) // Try to create the blob first (without access conditions for initial creation) - ctxCreate, cancelCreate := context.WithTimeout(context.Background(), azureOpTimeout) + ctxCreate, cancelCreate := context.WithTimeout(context.Background(), azure.DefaultAzureOpTimeout) _, err := appendBlobClient.Create(ctxCreate, nil) cancelCreate() @@ -181,7 +175,7 @@ func (g *AzureSink) CreateEntry(key string, entry *filer_pb.Entry, signatures [] func (g *AzureSink) handleExistingBlob(appendBlobClient *appendblob.Client, key string, entry *filer_pb.Entry, totalSize uint64) (needsWrite bool, err error) { // Get the blob's properties to decide whether to overwrite. // Use a timeout to fail fast on network issues. - ctxProps, cancelProps := context.WithTimeout(context.Background(), azureOpTimeout) + ctxProps, cancelProps := context.WithTimeout(context.Background(), azure.DefaultAzureOpTimeout) props, propErr := appendBlobClient.GetProperties(ctxProps, nil) cancelProps() @@ -218,7 +212,7 @@ func (g *AzureSink) handleExistingBlob(appendBlobClient *appendblob.Client, key } // Delete existing blob with conditional delete and timeout. - ctxDel, cancelDel := context.WithTimeout(context.Background(), azureOpTimeout) + ctxDel, cancelDel := context.WithTimeout(context.Background(), azure.DefaultAzureOpTimeout) _, delErr := appendBlobClient.Delete(ctxDel, deleteOpts) cancelDel() @@ -235,7 +229,7 @@ func (g *AzureSink) handleExistingBlob(appendBlobClient *appendblob.Client, key } // Recreate the blob with timeout. - ctxRecreate, cancelRecreate := context.WithTimeout(context.Background(), azureOpTimeout) + ctxRecreate, cancelRecreate := context.WithTimeout(context.Background(), azure.DefaultAzureOpTimeout) _, createErr := appendBlobClient.Create(ctxRecreate, nil) cancelRecreate()