<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 04:50:07 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-38810] Use the Client mutex or the SessionCatalog mutex for concurrency control of the TransactionParticipant</title>
                <link>https://jira.mongodb.org/browse/SERVER-38810</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;This ticket is for implementing the TransactionParticipant concurrency control change to look like this:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;Changing the state of the TP requires the session to be checked out and the client mutex&lt;/li&gt;
	&lt;li&gt;Observing the state of the TP can be done in on two occasions:
	&lt;ul&gt;
		&lt;li&gt;Without any locks, if the session is checked out by the reader thread&lt;/li&gt;
		&lt;li&gt;With the session catalog mutex + if currently checked-out by another thread, using the client mutex of that thread.&lt;/li&gt;
	&lt;/ul&gt;
	&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;This rule can also be expressed as: When the Session holding the TransactionParticipant is checked-out, use the OperationContext concurrency rules (i.e., the Client mutex); When it is not checked-out only use the SessionCatalog&#8217;s mutex.&lt;/p&gt;

&lt;p&gt;Prepare transaction in this case becomes:&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;Check-out session&lt;/li&gt;
	&lt;li&gt;Take client mutex and check for interruption&lt;/li&gt;
	&lt;li&gt;Set the state of the TP to &#8220;prepared&#8221;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Session invalidation and killAllExpiredTranasctions becomes:&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;In scanSessions, under the session catalog mutex, if session is checked-out currently, take the client mutex, otherwise don&#8217;t lock anything else&lt;/li&gt;
	&lt;li&gt;Check if the state is &#8220;prepared&#8221; and if so, skip this session&lt;/li&gt;
	&lt;li&gt;Check-out for kill any sessions, which weren&#8217;t skipped and call abortTransaction on them which must not be allowed to fail&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Session invalidation on stepDown and shutDown becomes:&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;In scanSessions, under the session catalog mutex, if session is checked-out currently, take the client mutex, otherwise don&#8217;t lock anything else&lt;/li&gt;
	&lt;li&gt;Unconditionally interrupt any operation contexts using this session&lt;/li&gt;
	&lt;li&gt;Check-out for kill all sessions and unconditionally force them to free their resources, which must not be allowed to fail&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;All TP methods, which require the session to be checked-out will be changed to not accept OperationContext anymore, but to take it from the parent Session object and all methods which expose observable state will be changed to either acquire the client mutex or to accept a WithLock to indicate that they should be run under the client mutex.&lt;br/&gt;
In order to reduce the confusion, there will only be two abort-related methods left on the TP:&lt;br/&gt;
abortTransaction - used for the regular abort path, direct write to the config.transactions and for killAllExpiredTransactions. Executes the entire abort sequence, updates metrics.&lt;br/&gt;
releaseTransactionResources - used for stepDown and shutDown. Releases the transaction&#8217;s resources unconditionally and makes the TP look as if it was just created&lt;/p&gt;</description>
                <environment></environment>
        <key id="664425">SERVER-38810</key>
            <summary>Use the Client mutex or the SessionCatalog mutex for concurrency control of the TransactionParticipant</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</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="schwerin@mongodb.com">Andy Schwerin</assignee>
                                    <reporter username="kaloian.manassiev@mongodb.com">Kaloian Manassiev</reporter>
                        <labels>
                    </labels>
                <created>Wed, 2 Jan 2019 19:26:09 +0000</created>
                <updated>Sun, 29 Oct 2023 22:25:25 +0000</updated>
                            <resolved>Fri, 15 Feb 2019 16:51:13 +0000</resolved>
                                                    <fixVersion>4.1.9</fixVersion>
                                    <component>Internal Code</component>
                                        <votes>0</votes>
                                    <watches>6</watches>
                                                                                                                <comments>
                            <comment id="2153426" author="xgen-internal-githook" created="Fri, 15 Feb 2019 16:50:22 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Andy Schwerin&apos;, &apos;email&apos;: &apos;schwerin@mongodb.com&apos;, &apos;username&apos;: &apos;amschwerin&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-38810&quot; title=&quot;Use the Client mutex or the SessionCatalog mutex for concurrency control of the TransactionParticipant&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-38810&quot;&gt;&lt;del&gt;SERVER-38810&lt;/del&gt;&lt;/a&gt; Use Session&apos;s concurrency control rules instead of internal mutexes in TransactionParticipant&lt;/p&gt;

&lt;p&gt;This type simplifies and clarifies concurrency control in TransactionParticipant by:&lt;/p&gt;

&lt;p&gt;(1) Removing TP&apos;s own mutexes and using the Session concurrency control rules,&lt;br/&gt;
instead. That is, certain state is only accessible when the Session is checked&lt;br/&gt;
out, and requires no further locking. Other state is observable either while&lt;br/&gt;
holding the client lock or while having checked out the Session. The latter type&lt;br/&gt;
of state is modifiable only when having checked out the session and locked the&lt;br/&gt;
client.&lt;/p&gt;

&lt;p&gt;(2) Separating the two types of state in (1) into separate sub-structures in&lt;br/&gt;
TransactionParticipant, to make it clear who can access what state,&lt;/p&gt;

&lt;p&gt;(3) Putting all methods formerly on TransactionParticipant onto new member&lt;br/&gt;
classes, TransactionParticipant::Participant and&lt;br/&gt;
TransactionParticipant::Observer. The latter can only read the observable state&lt;br/&gt;
from (1) above, and the participant may read or modify all of the state.&lt;/p&gt;

&lt;p&gt;The two types introduced by (3) are designed to enforce proper concurrency&lt;br/&gt;
control by limiting access of their methods to the underlying&lt;br/&gt;
TransactionParticipant member variables. The observer type has a private o()&lt;br/&gt;
method which its other methods are required by convention to use in order to&lt;br/&gt;
obtain read-only access to the Observable state of the&lt;br/&gt;
TransactionParticipant. The participant type has the o() method plus an&lt;br/&gt;
o(WithLock) method that allows mutation of the state while holding the client&lt;br/&gt;
lock, and a p() method which allows reading and writing of the private state&lt;br/&gt;
with no other locks. Please see the implementation in&lt;br/&gt;
transaction_participant.cpp for examples.&lt;/p&gt;

&lt;p&gt;It is worth noting that with this change, locking the Client is not needed often&lt;br/&gt;
and never for long, and there is no need for separate mutexes for participant&lt;br/&gt;
state and monitoring state.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/1d246814a058073f0c26981fff5fe67c16af3593&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/1d246814a058073f0c26981fff5fe67c16af3593&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="2112953" author="xgen-internal-githook" created="Fri, 11 Jan 2019 21:21:25 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;username&apos;: &apos;kaloianm&apos;, &apos;email&apos;: &apos;kaloian.manassiev@mongodb.com&apos;, &apos;name&apos;: &apos;Kaloian Manassiev&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-38810&quot; title=&quot;Use the Client mutex or the SessionCatalog mutex for concurrency control of the TransactionParticipant&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-38810&quot;&gt;&lt;del&gt;SERVER-38810&lt;/del&gt;&lt;/a&gt; Temporarily do not hold the client lock in ObservableSession in order to avoid deadlock&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/1bd1b3644378b76e5ff42bb8c6bee8a640e9a866&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/1bd1b3644378b76e5ff42bb8c6bee8a640e9a866&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="2111542" author="xgen-internal-githook" created="Thu, 10 Jan 2019 20:02:56 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;username&apos;: &apos;amschwerin&apos;, &apos;email&apos;: &apos;schwerin@mongodb.com&apos;, &apos;name&apos;: &apos;Andy Schwerin&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-38810&quot; title=&quot;Use the Client mutex or the SessionCatalog mutex for concurrency control of the TransactionParticipant&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-38810&quot;&gt;&lt;del&gt;SERVER-38810&lt;/del&gt;&lt;/a&gt; Simplify correct usage of locking in Session/SessionCatalog.&lt;/p&gt;

&lt;p&gt;This patch introduces two new types for gaining access to sessions in&lt;br/&gt;
the session catalog, based on the context of the access. It leaves a&lt;br/&gt;
third way to access sessions, which is via&lt;br/&gt;
OperationContextSession::get().&lt;/p&gt;

&lt;p&gt;The new types are ObservableSession and SessionToKill. With this&lt;br/&gt;
change, a thread may access a session in one of three ways:&lt;/p&gt;

&lt;p&gt;(1) by binding the session to an OperationContext for regular use, by&lt;br/&gt;
instantiation of OperationContextSession or&lt;br/&gt;
MongoDOperationContextSession, as before.&lt;/p&gt;

&lt;p&gt;(2) In the callback passed to SessionCatalog::scanSessions, in which&lt;br/&gt;
case the callback is passed an ObservableSession that represents&lt;br/&gt;
looking at a Session while the SessionCatalog mutex is locked and&lt;br/&gt;
while the bound OperationContext&apos;s client mutex is held, if the&lt;br/&gt;
session is currently checked out via methods (1) or (3).&lt;/p&gt;

&lt;p&gt;(3) By calling SessionCatalog::checkOutSessionForKill, which returns a&lt;br/&gt;
KillableSession. This is used for cleaning a session up after it is&lt;br/&gt;
marked for kill.&lt;/p&gt;

&lt;p&gt;This patch eliminates Session::_mutex, which is no longer required, as&lt;br/&gt;
the SessionCatalog::_mutex and the Client provide all necessary mutual&lt;br/&gt;
exclusion for the Session type itself.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/facdcf14cfec192876a373fc49163769215327d8&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/facdcf14cfec192876a373fc49163769215327d8&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10011">
                    <name>Depends</name>
                                            <outwardlinks description="depends on">
                                                        </outwardlinks>
                                                                <inwardlinks description="is depended on by">
                                                        </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="1447507">SERVER-50400</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="698759">SERVER-39610</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="698771">SERVER-39613</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="698772">SERVER-39614</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="698777">SERVER-39615</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>3.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18555" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname># of Sprints</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>4.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>Fri, 4 Jan 2019 21:04:20 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        4 years, 51 weeks, 5 days ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[<s><a href='https://jira.mongodb.org/browse/WRITING-3447'>WRITING-3447</a></s>]]></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-1032</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>
                            4 years, 51 weeks, 5 days ago
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_16465" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Linked BF Score</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>0.0</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>schwerin@mongodb.com</customfieldvalue>
            <customfieldvalue>xgen-internal-githook</customfieldvalue>
            <customfieldvalue>kaloian.manassiev@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hui0l3:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hu81fr:</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>
    <customfieldvalue id="2787">Sharding 2019-02-25</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|huhmuf:</customfieldvalue>

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