From 868c45baa413613e70366443185cd17e24467c69 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Mon, 21 Jul 2025 15:02:27 +0530 Subject: [PATCH] fileData: Use primary bucket as preferred bucket to read --- server/pkg/controller/filedata/controller.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/server/pkg/controller/filedata/controller.go b/server/pkg/controller/filedata/controller.go index 65cbef0033..9c192d7495 100644 --- a/server/pkg/controller/filedata/controller.go +++ b/server/pkg/controller/filedata/controller.go @@ -22,6 +22,7 @@ import ( "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" "net/http" + "strings" "sync" gTime "time" ) @@ -264,12 +265,12 @@ func (c *Controller) getS3FileMetadataParallel(ctx *gin.Context, dbRows []fileDa func (c *Controller) fetchS3FileMetadata(ctx context.Context, row fileData.Row, ctxLogger *log.Entry) (*fileData.S3FileMetadata, error) { dc := row.LatestBucket - // :todo:neeraj make it configurable to - // specify preferred dc to read from - // and fallback logic to read from different bucket when we fail to read from preferred dc - if dc == "b5" { - if array.StringInList("b6", row.ReplicatedBuckets) { - dc = "b6" + preferredBucket := c.S3Config.GetBucketID(row.Type) + // If the current primary bucket is different from the latest bucket where data was written, + // check and use the preferred bucket if the data is replicated there. + if !strings.EqualFold(preferredBucket, dc) { + if array.StringInList(preferredBucket, row.ReplicatedBuckets) { + dc = preferredBucket } } opt := _defaultFetchConfig