From c6ec3fa8fde6e8572696e6a2cffae30cf593c579 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Fri, 29 Nov 2024 12:24:12 +0530 Subject: [PATCH] [server] Fixed delay in next attemp --- server/pkg/controller/replication3.go | 10 ++++++++++ server/pkg/repo/object_copies.go | 12 ++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/server/pkg/controller/replication3.go b/server/pkg/controller/replication3.go index c7b52ff870..a57a372fab 100644 --- a/server/pkg/controller/replication3.go +++ b/server/pkg/controller/replication3.go @@ -250,6 +250,16 @@ func (c *ReplicationController3) tryReplicate() error { logger.Error(err) } + if strings.Contains(err.Error(), "size of the uploaded file") { + delayErr := c.ObjectCopiesRepo.DelayNextAttemptByDays(context.Background(), objectKey, 7) + if delayErr != nil { + logger.WithError(delayErr).Error("Failed to delay next attempt by 7 days") + } else { + discordAlert := fmt.Sprintf("🔥 Size mismatch for object %s, failed to delay next attempt by 7 days", objectKey) + c.notifyDiscord(discordAlert) + } + } + if err == nil { logger.Info("Replication attempt succeeded") } else { diff --git a/server/pkg/repo/object_copies.go b/server/pkg/repo/object_copies.go index 31443e25c5..33245740f8 100644 --- a/server/pkg/repo/object_copies.go +++ b/server/pkg/repo/object_copies.go @@ -35,7 +35,6 @@ func (repo *ObjectCopiesRepository) GetAndLockUnreplicatedObject(ctx context.Con } } - // todo:(neeraj) reduce the gap between last_attempt and now_utc_micro_seconds from 7 days to 1 day row := tx.QueryRowContext(ctx, ` SELECT object_key, want_b2, b2, want_wasabi, wasabi, want_scw, scw FROM object_copies @@ -43,7 +42,7 @@ func (repo *ObjectCopiesRepository) GetAndLockUnreplicatedObject(ctx context.Con ( (wasabi IS NULL AND want_wasabi = true) OR (scw IS NULL AND want_scw = true) - ) AND last_attempt < (now_utc_micro_seconds() - (7* 24::BIGINT * 60 * 60 * 1000 * 1000)) + ) AND last_attempt < (now_utc_micro_seconds() - (24::BIGINT * 60 * 60 * 1000 * 1000)) ) LIMIT 1 FOR UPDATE SKIP LOCKED @@ -112,6 +111,15 @@ func (repo *ObjectCopiesRepository) RegisterReplicationAttempt(tx *sql.Tx, ctx c return stacktrace.Propagate(err, "") } +func (repo *ObjectCopiesRepository) DelayNextAttemptByDays(ctx context.Context, objectKey string, days int) error { + _, err := repo.DB.ExecContext(ctx, ` + UPDATE object_copies + SET last_attempt = last_attempt + ($2 * 24::BIGINT * 60 * 60 * 1000 * 1000) + WHERE object_key = $1 + `, objectKey, days) + return stacktrace.Propagate(err, "") +} + // ResetNeedsB2Replication modifies the db to indicate that objectKey should be // re-replicated to Backblaze even if it has already been replicated there. func (repo *ObjectCopiesRepository) ResetNeedsB2Replication(objectKey string) error {