<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:22:56 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[SERVER-10350] Atomicity of Upserts on multi field unique index</title>
                <link>https://jira.mongodb.org/browse/SERVER-10350</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;We&apos;re getting a handful of live exceptions resulting from concurrent upserts, with the same query, complaining about unique index violations. It was my understanding that the upsert process would be atomic, with respect to the decision to update or insert, and therefore the &apos;winner&apos; of the obvious race condition would perform an insert and second place would update the new document.&lt;/p&gt;

&lt;p&gt;An example of the exception:&lt;/p&gt;

&lt;p&gt;com.mongodb.MongoException$DuplicateKey: { &lt;br/&gt;
&quot;serverUsed&quot; : &quot;localhost/127.0.0.1:27018&quot; , &lt;br/&gt;
&quot;singleShard&quot; :  removed, &lt;br/&gt;
&quot;err&quot; : &quot;E11000 duplicate key error index: index-name  dup key: &lt;/p&gt;
{ key-entry }
&lt;p&gt;&quot; , &lt;br/&gt;
&quot;code&quot; : 11000 , &lt;br/&gt;
&quot;n&quot; : 0 , &lt;br/&gt;
&quot;lastOp&quot; : &lt;/p&gt;
{ &quot;$ts&quot; : 1374832745 , &quot;$inc&quot; : 4}
&lt;p&gt; , &lt;br/&gt;
&quot;connectionId&quot; : 26451 , &lt;br/&gt;
&quot;ok&quot; : 1.0}&lt;/p&gt;


&lt;p&gt;The unique index in this case is a composite of four fields, one guid, the others are shorter strings all contained within a sub-document. The query element of the upsert consists solely of the unique index fields, the update is a document containing a single field $inc and a $set for half a dozen other fields. I would post an example, but i&apos;ve been unable to recreate the issue with test code. The database is not under significant load (~100 updates per second, ~4% locked, rarely a single item in either write or read queues), the concurrent queries would be coming from separate clients, so not the same connection pool. The upserts are operating within an &quot;ensureConnection&quot; block (java driver), so we can check a variety of write concerns.&lt;/p&gt;

&lt;p&gt;It&apos;s my understanding this shouldn&apos;t be happening. Is there any extra information you need to help confirm this issue and track it down?&lt;/p&gt;</description>
                <environment>Red Hat Enterprise Linux Server release 6.3 (Santiago)&lt;br/&gt;
Linux 2.6.32-279.22.1.el6.x86_64 #1 SMP Sun Jan 13 09:21:40 EST 2013 x86_64 x86_64 x86_64 GNU/Linux</environment>
        <key id="83606">SERVER-10350</key>
            <summary>Atomicity of Upserts on multi field unique index</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="3">Duplicate</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="tcoupland">Tom Coupland</reporter>
                        <labels>
                    </labels>
                <created>Fri, 26 Jul 2013 14:31:52 +0000</created>
                <updated>Mon, 14 Sep 2015 18:04:33 +0000</updated>
                            <resolved>Fri, 20 Jun 2014 11:45:28 +0000</resolved>
                                    <version>2.4.4</version>
                                                    <component>Concurrency</component>
                    <component>Write Ops</component>
                                        <votes>0</votes>
                                    <watches>6</watches>
                                                                                                                <comments>
                            <comment id="391825" author="dan@10gen.com" created="Tue, 30 Jul 2013 14:38:05 +0000"  >&lt;p&gt;I&apos;ve added a documentation request to clarify the behavior here: &lt;a href=&quot;https://jira.mongodb.org/browse/DOCS-1759&quot; title=&quot;Clarify behavior of upsert operations when the query field has a unique index&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DOCS-1759&quot;&gt;&lt;del&gt;DOCS-1759&lt;/del&gt;&lt;/a&gt;.&lt;/p&gt;</comment>
                            <comment id="390769" author="tcoupland" created="Mon, 29 Jul 2013 08:35:24 +0000"  >&lt;p&gt;So in summery: concurrent upserts are not safe, you need a try/catch block around them to retry on a DuplicateKey exception.&lt;/p&gt;

&lt;p&gt;I think that discussion needs to be referenced here: docs.mongodb.org/manual/core/create/#crud-create-update. To be honest i think this issue should be explained in a red border so it&apos;s clear that this is not an atomic operation.&lt;/p&gt;

&lt;p&gt;Thanks for the fast feedback Andy.&lt;/p&gt;</comment>
                            <comment id="389494" author="schwerin" created="Fri, 26 Jul 2013 17:24:40 +0000"  >&lt;p&gt;There are cases when the server could declare a winner, as the reporter suggests.  In essence, those are the cases in which the server can describe a serial order over updates to the index region / index / index entry being modified.  Determining when such a serialization actually exists or could exist requires further study. &lt;/p&gt;</comment>
                            <comment id="389471" author="schwerin" created="Fri, 26 Jul 2013 17:01:51 +0000"  >&lt;p&gt;&lt;a href=&quot;http://docs.mongodb.org/manual/reference/command/findAndModify/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://docs.mongodb.org/manual/reference/command/findAndModify/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The discussion near the bottom of this document starting with &quot;When the findAndModify command includes the upsert: true&quot; is relevant to update as well as findAndModify.  A workaround for this behavior is described.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="143209">SERVER-14322</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="83976">DOCS-1759</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="170592">SERVER-16261</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="110513">SERVER-12694</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>4.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Fri, 26 Jul 2013 17:01:51 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        10 years, 29 weeks, 1 day ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[]]></customfieldvalue>


                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_10057" key="com.atlassian.jira.toolkit:lastusercommented">
                        <customfieldname>Last comment by Customer</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>true</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>ramon.fernandez@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            10 years, 29 weeks, 1 day ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10000" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Old_Backport</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10000"><![CDATA[No]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10032" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                        <customfieldname>Operating System</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10020"><![CDATA[Linux]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>schwerin@mongodb.com</customfieldvalue>
            <customfieldvalue>dan@mongodb.com</customfieldvalue>
            <customfieldvalue>tcoupland</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrmlfj:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrg2db:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>7212</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_23361" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Requested By</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_22870" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Triagers</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hs9rkn:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                    </customfields>
    </item>
</channel>
</rss>