-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SERVER-84089 Check for collation when retrying bulk write upsert (#29…
…487) GitOrigin-RevId: 80db4dc55be1361b119f257e3d133392fecee09c
- Loading branch information
1 parent
dc1671f
commit 4682e5f
Showing
5 changed files
with
83 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
jstests/core/write/update/upsert_duplicate_key_retry_collation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* When two concurrent identical upsert operations are performed, for which a unique index exists on | ||
* the query values, it is possible that they will both attempt to perform an insert with one of | ||
* the two failing on the unique index constraint. This test confirms that we respect collation | ||
* when deciding to retry the error. | ||
* | ||
* @tags: [assumes_unsharded_collection] | ||
*/ | ||
|
||
const testColl = db.upsert_duplicate_key_retry_collation; | ||
|
||
{ // Test index without collation, query with collation | ||
testColl.drop(); | ||
assert.commandWorked(testColl.createIndex({x: 1}, {unique: true})); | ||
assert.commandWorked(testColl.insertMany([{_id: 0, x: "UNIQUE"}, {_id: 1, x: "unique"}])); | ||
|
||
assert.throwsWithCode(() => { | ||
testColl.updateOne({x: "unique"}, | ||
{$set: {x: "unique"}}, | ||
{upsert: true, collation: {locale: "en", strength: 1}}); | ||
testColl.updateOne({x: "unique"}, | ||
{$set: {x: "UNIQUE"}}, | ||
{upsert: true, collation: {locale: "en", strength: 1}}); | ||
}, ErrorCodes.DuplicateKey); | ||
} | ||
|
||
{ // Test index with collation, query without collation | ||
testColl.drop(); | ||
assert.commandWorked( | ||
testColl.createIndex({x: 1}, {unique: true, collation: {locale: "en", strength: 2}})); | ||
assert.commandWorked(testColl.insertMany([{_id: 0, x: "UNIQUE"}])); | ||
|
||
assert.throwsWithCode( | ||
() => testColl.updateOne({x: "unique"}, {$set: {x: "Unique"}}, {upsert: true}), | ||
ErrorCodes.DuplicateKey); | ||
} | ||
|
||
{ // Test index and query with different collation strength | ||
testColl.drop(); | ||
assert.commandWorked( | ||
testColl.createIndex({x: 1}, {unique: true, collation: {locale: "en", strength: 3}})); | ||
assert.commandWorked(testColl.insertMany([{_id: 0, x: "UNIQUË"}, {_id: 1, x: "UNIQUE"}])); | ||
|
||
assert.throwsWithCode(() => { | ||
testColl.updateOne({x: "UNIQUE"}, | ||
{$set: {x: "UNIQUE"}}, | ||
{upsert: true, collation: {locale: "en", strength: 1}}); | ||
testColl.updateOne({x: "UNIQUE"}, | ||
{$set: {x: "UNIQUË"}}, | ||
{upsert: true, collation: {locale: "en", strength: 1}}); | ||
}, ErrorCodes.DuplicateKey); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters