<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 04:49:03 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-38473] Replace uses of UninterruptibleLockGuard and MODE_X collection locks with uses of a database sharding state mutex for movePrimary functions</title>
                <link>https://jira.mongodb.org/browse/SERVER-38473</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;We use UninterruptibleLockGuard in several places for movePrimaries. Since they acquire strong locks on normal databases and collections, they will be blocked by prepared transactions, causing deadlock on stepdown or shutdown.&lt;/p&gt;

&lt;p&gt;Here&apos;s a list of all the occurrences of UninterruptibleLockGuard for movePrimaries.&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;&lt;a href=&quot;https://github.com/mongodb/mongo/blob/dcf7e0dd89d34f58b592f1adb3d41e5edd6e2012/src/mongo/db/s/move_primary_source_manager.cpp#L251&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;src/mongo/db/s/move_primary_source_manager.cpp:251&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;https://github.com/mongodb/mongo/blob/dcf7e0dd89d34f58b592f1adb3d41e5edd6e2012/src/mongo/db/s/move_primary_source_manager.cpp#L352&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;src/mongo/db/s/move_primary_source_manager.cpp:352&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;We will employ a new &lt;tt&gt;DatabaseShardingStateLock&lt;/tt&gt; (similar to the &lt;tt&gt;CollectionShardingRuntimeLock&lt;/tt&gt;) to safeguard concurrent access to the database critical section.&lt;/p&gt;

&lt;p&gt;When leaving critical section no longer conflicts with prepared transactions, they can run after prepared transactions yield locks on stepdown or being killed on shutdown. See &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-38162&quot; title=&quot;Acquire ReplicationStateTransitionLock on shutdown in mode X&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-38162&quot;&gt;&lt;del&gt;SERVER-38162&lt;/del&gt;&lt;/a&gt; for the order of events on shutdown and &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-38282&quot; title=&quot;Reacquire locks for transactions on step-up and release them on step-down&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-38282&quot;&gt;&lt;del&gt;SERVER-38282&lt;/del&gt;&lt;/a&gt; for stepdown.&lt;/p&gt;

&lt;p&gt;The following function signature changes will allow us to relax the database locking to IX instead of X under the above &lt;tt&gt;UninterruptibleLockGuards&lt;/tt&gt;. Database locks highlighted in bold will have a proposed change. All other database locks remain unchanged.&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;enterCriticalSectionCatchUpPhase: Database X Lock, DSSLock X Lock&lt;/li&gt;
	&lt;li&gt;enterCriticalSectionCommitPhase: Database X Lock, DSSLock X Lock&lt;/li&gt;
	&lt;li&gt;extitCriticalSection: Database &lt;del&gt;X&lt;/del&gt; &lt;b&gt;IX&lt;/b&gt; Lock, DSSLock X Lock&lt;/li&gt;
	&lt;li&gt;getCriticalSectionSignal: Database IS Lock, DSSLock IS Lock&lt;/li&gt;
	&lt;li&gt;getDbVersion: Database IS or X Lock (situational), DSS IS Lock&lt;/li&gt;
	&lt;li&gt;setDbVersion (when setting dbVersion to a meaningful value): Database X Lock, DSS X Lock&lt;/li&gt;
	&lt;li&gt;setDbVersion (when setting dbVersion to boost::none, AKA &quot;clearing&quot; the dbVersion): Database &lt;del&gt;X&lt;/del&gt; &lt;b&gt;IX&lt;/b&gt; Lock, DSS X&lt;/li&gt;
	&lt;li&gt;checkDbVersion: Database IS or X Lock (situational), DSS IS Lock&lt;/li&gt;
	&lt;li&gt;getMovePrimarySourceManager: No Database Lock (reflects current usage), DSS IS Lock&lt;/li&gt;
	&lt;li&gt;setMovePrimarySourceManager: Database X Lock, DSS X Lock&lt;/li&gt;
	&lt;li&gt;clearMovePrimarySourceManager: Database &lt;del&gt;X&lt;/del&gt; &lt;b&gt;IX&lt;/b&gt; Lock, DSS X Lock&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;These situations can use relaxed locking as a result:&lt;/p&gt;

&lt;ol&gt;
	&lt;li&gt;On the source node for movePrimary, if we can&apos;t commit the moved primary, &lt;a href=&quot;https://github.com/mongodb/mongo/blob/dcf7e0dd89d34f58b592f1adb3d41e5edd6e2012/src/mongo/db/s/move_primary_source_manager.cpp#L251&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;we check if the node has stepped down&lt;/a&gt;. If it has stepped down, we must set the database version to &lt;tt&gt;boost::none&lt;/tt&gt; to indicate that the we now do not know the authoritative version. Since setting the database version to &lt;tt&gt;boost::none&lt;/tt&gt; is semantically equivalent to &quot;clearing&quot; the database version, we can now use a Database IX Lock instead of a Database X Lock when doing so. The DSSLock in exclusive mode will prevent concurrent changes to the database version.&lt;/li&gt;
	&lt;li&gt;On the source node for movePrimary, we must clear state variables on cleanup. This includes clearing the &lt;tt&gt;movePrimarySourceManager&lt;/tt&gt; and &lt;tt&gt;criticalSection&lt;/tt&gt; variables. We may now use a Database IX Lock instead of a Database X Lock, since the DSSLock in exclusive mode will prevent concurrent changes to the database sharding state&apos;s in-memory variables.&lt;/li&gt;
&lt;/ol&gt;
</description>
                <environment></environment>
        <key id="647750">SERVER-38473</key>
            <summary>Replace uses of UninterruptibleLockGuard and MODE_X collection locks with uses of a database sharding state mutex for movePrimary functions</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</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="13201">Fixed</resolution>
                                        <assignee username="blake.oler@mongodb.com">Blake Oler</assignee>
                                    <reporter username="siyuan.zhou@mongodb.com">Siyuan Zhou</reporter>
                        <labels>
                            <label>prepare_interruptibility</label>
                            <label>uninterruptibleLockGuardRemoval</label>
                    </labels>
                <created>Fri, 7 Dec 2018 22:17:31 +0000</created>
                <updated>Sun, 29 Oct 2023 22:25:59 +0000</updated>
                            <resolved>Tue, 5 Feb 2019 19:33:11 +0000</resolved>
                                                    <fixVersion>4.1.8</fixVersion>
                                    <component>Sharding</component>
                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="2138830" author="xgen-internal-githook" created="Tue, 5 Feb 2019 21:06:30 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Blake Oler&apos;, &apos;email&apos;: &apos;blake.oler@mongodb.com&apos;, &apos;username&apos;: &apos;BlakeIsBlake&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-38473&quot; title=&quot;Replace uses of UninterruptibleLockGuard and MODE_X collection locks with uses of a database sharding state mutex for movePrimary functions&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-38473&quot;&gt;&lt;del&gt;SERVER-38473&lt;/del&gt;&lt;/a&gt; Fix lint&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/5647fa34c70e1d7d255fcd85840115e95d81466b&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/5647fa34c70e1d7d255fcd85840115e95d81466b&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="2138651" author="xgen-internal-githook" created="Tue, 5 Feb 2019 19:29:13 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Blake Oler&apos;, &apos;email&apos;: &apos;blake.oler@mongodb.com&apos;, &apos;username&apos;: &apos;BlakeIsBlake&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-38473&quot; title=&quot;Replace uses of UninterruptibleLockGuard and MODE_X collection locks with uses of a database sharding state mutex for movePrimary functions&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-38473&quot;&gt;&lt;del&gt;SERVER-38473&lt;/del&gt;&lt;/a&gt; Create DatabaseShardingStateLock to ensure concurrency around DatabaseShardingState usage&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/75d64b2e170abf1d22058e3afffdaf872a4c067c&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/75d64b2e170abf1d22058e3afffdaf872a4c067c&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="504146">SERVER-33577</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18555" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname># of Sprints</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>3.0</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10038"><![CDATA[Fully Compatible]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Tue, 29 Jan 2019 18:55:50 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        5 years, 1 week, 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_10857" key="com.pyxis.greenhopper.jira:gh-epic-link">
                        <customfieldname>Epic Link</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>PM-1317</customfieldvalue>
                        </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>luke.bonanomi@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            5 years, 1 week, 1 day ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>blake.oler@mongodb.com</customfieldvalue>
            <customfieldvalue>xgen-internal-githook</customfieldvalue>
            <customfieldvalue>siyuan.zhou@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|huf81j:</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</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_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="2725">Sharding 2019-01-14</customfieldvalue>
    <customfieldvalue id="2726">Sharding 2019-01-28</customfieldvalue>
    <customfieldvalue id="2786">Sharding 2019-02-11</customfieldvalue>

                        </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|hueuav:</customfieldvalue>

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