зеркало из https://github.com/golang/pkgsite.git
internal/postgres: sort paths before insertion to avoid deadlock
Deadlock is rare but we have observed it when multiple versions of the same module are inserted concurrently. Change-Id: Idd28bd558009ff053ac198bdd310fa780af66f83 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/320750 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>
This commit is contained in:
Родитель
ef87a127e3
Коммит
a1d3aaa84a
|
@ -9,6 +9,7 @@ import (
|
|||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/lib/pq"
|
||||
|
@ -138,6 +139,8 @@ func upsertPaths(ctx context.Context, db *database.DB, paths []string) (pathToID
|
|||
}
|
||||
}
|
||||
if len(values) > 0 {
|
||||
// Sort to avoid deadlock.
|
||||
sort.Slice(values, func(i, j int) bool { return values[i].(string) < values[j].(string) })
|
||||
// Insert data into the paths table.
|
||||
pathCols := []string{"path"}
|
||||
returningPathCols := []string{"id", "path"}
|
||||
|
|
Загрузка…
Ссылка в новой задаче