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: Reduce deadlocks via exclusive locking (SELECT ... FOR UPDATE) #830

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions pkg/icingadb/ha.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,15 @@ 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.
// However, in order to reduce the deadlocks on both sides, it is necessary to obtain an exclusive lock
// on the selected rows. This can be achieved by utilising the SELECT ... FOR UPDATE command.
// Nevertheless, deadlocks may still occur, when the "icingadb_instance" table is empty, i.e. when
// there's no available row to be locked exclusively.
//
// 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