aboutsummaryrefslogtreecommitdiff
path: root/internal/database/database.go
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2021-05-27 10:25:10 -0400
committerJonathan Amsterdam <jba@google.com>2021-06-01 17:48:57 +0000
commitcdf0092c17bc875c7175ffafd63c87175a46dcc9 (patch)
treec1158b1363c0bd957f441b62137c9091967c613c /internal/database/database.go
parenta2785ff1ccd2458d2981b41b5d68179a9f70c8f2 (diff)
downloadgo-x-pkgsite-cdf0092c17bc875c7175ffafd63c87175a46dcc9.tar.xz
internal/database: reduce max retries on serialization failure
If a save-module transaction fails due to serialization, then most likely another version of the same module is being processed at the same time. The right thing to do is to retry the transaction, and we do, up to 30 times. But if many versions are being reprocessed at once--as seems to be frequently the case now--we are just wasting time and compute resources, because we retry immediately, without any backoff. It would be better to fail sooner, and let the natural exponential backoff of the task queue do the retrying for us. We don't want to eliminate the immediate retry completely, but reduce the count to 10. Change-Id: I89f1cb8a9c021083f838c6659d3e5b39226cb144 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/323411 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Jamal Carvalho <jamal@golang.org>
Diffstat (limited to 'internal/database/database.go')
-rw-r--r--internal/database/database.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/internal/database/database.go b/internal/database/database.go
index 312f83af..30963f02 100644
--- a/internal/database/database.go
+++ b/internal/database/database.go
@@ -194,7 +194,7 @@ func (db *DB) transactWithRetry(ctx context.Context, opts *sql.TxOptions, txFunc
defer derrors.Wrap(&err, "transactWithRetry(%v)", opts)
// Retry on serialization failure, up to some max.
// See https://www.postgresql.org/docs/11/transaction-iso.html.
- const maxRetries = 30
+ const maxRetries = 10
for i := 0; i <= maxRetries; i++ {
err = db.transact(ctx, opts, txFunc)
if isSerializationFailure(err) {