[server] Fixed delay in next attemp

This commit is contained in:
Neeraj Gupta
2024-11-29 12:24:12 +05:30
parent a54cbd779a
commit c6ec3fa8fd
2 changed files with 20 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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 {