MM-38419: Split UPSERT statement into 2 (#19536)

The UPSERT statement was taking unexplained gap
locks, due to which the import was somehow failing.
I still don't know exactly how this is happening.

But splitting the UPSERT into 2 different statements
in the same transaction changes the locking semantics,
and avoids the deadlock.

Naturally, this proves that even our retrylayer
is sometimes ineffective against some problems.

```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2022-02-11 13:54:47 +05:30
коммит произвёл GitHub
родитель 01a3ed0d3e
Коммит 446306a274

Просмотреть файл

@@ -540,14 +540,17 @@ func (s SqlChannelStore) upsertPublicChannelT(transaction *sqlxTxWrapper, channe
PublicChannels(Id, DeleteAt, TeamId, DisplayName, Name, Header, Purpose)
VALUES
(:id, :deleteat, :teamid, :displayname, :name, :header, :purpose)
ON DUPLICATE KEY UPDATE
DeleteAt = :deleteat,
`, vals)
if err != nil && IsUniqueConstraintError(err, []string{"PRIMARY"}) {
_, err = transaction.NamedExec(`UPDATE PublicChannels
SET deleteAt = :deleteat,
TeamId = :teamid,
DisplayName = :displayname,
Name = :name,
Header = :header,
Purpose = :purpose;
`, vals)
Purpose = :purpose
WHERE Id=:id`, vals)
}
} else {
_, err = transaction.NamedExec(`
INSERT INTO