Commit ef492be
committed
Issue #747: fix flaky MS SQL MERGE upsert PRIMARY KEY violation with WITH (HOLDLOCK)
The JDBC backend performs the SQL Server upsert via MERGE ... WHEN NOT MATCHED
THEN INSERT. Under READ_COMMITTED, SQL Server's MERGE is not atomic: two
concurrent sessions can both evaluate NOT MATCHED for the same key and both
attempt the INSERT, producing a duplicate PRIMARY KEY error. This is the race
that intermittently fails PluggableBackendImplTestCase.test_issue_496_2 (8
threads upserting the same key).
Add the WITH (HOLDLOCK) (SERIALIZABLE range-lock) table hint to the MERGE
target so the existence check and the insert are atomic with respect to other
sessions, serializing concurrent upserts of the same key.1 parent a6216bf commit ef492be
1 file changed
Lines changed: 2 additions & 2 deletions
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
389 | 389 | | |
390 | 390 | | |
391 | 391 | | |
392 | | - | |
393 | | - | |
| 392 | + | |
| 393 | + | |
394 | 394 | | |
395 | 395 | | |
396 | 396 | | |
| |||
0 commit comments