Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HA#realize(): avoid deadlocks via exclusive locking, i.e. SELECT ... FOR UPDATE #788

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pkg/icingadb/ha.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,11 @@ func (h *HA) realize(

if h.db.DriverName() == database.MySQL {
// The RDBMS may actually be a Percona XtraDB Cluster which doesn't
// support serializable transactions, but only their following equivalent:
// support serializable transactions, but only their equivalent SELECT ... LOCK IN SHARE MODE.
// We need even stronger locking to avoid deadlocks, so we use SELECT ... FOR UPDATE.
// See also: https://dev.mysql.com/doc/refman/5.7/en/innodb-locking-reads.html
isoLvl = sql.LevelRepeatableRead
selectLock = " LOCK IN SHARE MODE"
selectLock = " FOR UPDATE"
}

tx, errBegin := h.db.BeginTxx(ctx, &sql.TxOptions{Isolation: isoLvl})
Expand Down
Loading