<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:58:29 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>[JAVA-2967] Dirty reads outside the transaction</title>
                <link>https://jira.mongodb.org/browse/JAVA-2967</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;I am using mongodb 4.0 with latest drivers version 3.8.1&lt;/p&gt;

&lt;p&gt;Within a transaction, when a value is changed and is not committed yet, outside the transaction we expect to not see that change. This expectation is not happening.&lt;/p&gt;

&lt;p&gt;I have written a simple &lt;a href=&quot;https://github.com/arunkjn/mongodbtransactiontest/blob/master/src/test/java/io/github/arunkjn/mongodbtransactiontest/ITCacheServiceTest.java&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;test case&lt;/a&gt; to demonstrate this.&lt;/p&gt;

&lt;p&gt;&#160;Here is the link to the entire project containing integration test to demonstrate this. It is running mongodb in a docker container, so depends on docker being installed.&lt;br/&gt;
&lt;a href=&quot;https://github.com/arunkjn/mongodbtransactiontest&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/arunkjn/mongodbtransactiontest&lt;/a&gt;&lt;/p&gt;</description>
                <environment>Docker for Mac.&lt;br/&gt;
</environment>
        <key id="602012">JAVA-2967</key>
            <summary>Dirty reads outside the transaction</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="9">Done</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="arunkjn">Arun Kumar Jain</reporter>
                        <labels>
                    </labels>
                <created>Mon, 10 Sep 2018 11:36:38 +0000</created>
                <updated>Wed, 11 Sep 2019 19:14:08 +0000</updated>
                            <resolved>Tue, 11 Sep 2018 18:41:50 +0000</resolved>
                                    <version>3.8.1</version>
                                                    <component>Transaction Management</component>
                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="2002881" author="jeff.yemin" created="Fri, 14 Sep 2018 11:50:30 +0000"  >&lt;p&gt;The sample code &lt;a href=&quot;https://docs.mongodb.com/master/core/transactions/#transactions-and-mongodb-drivers&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;here&lt;/a&gt; has no explicit abort because each attempt to run the transaction uses a different ClientSession, and closing the ClientSession automatically aborts any uncommitted transaction.  If you are trying to re-use the ClientSession for each attempt, you will have to explicitly abort.&lt;/p&gt;</comment>
                            <comment id="2002738" author="arunkjn" created="Fri, 14 Sep 2018 06:54:26 +0000"  >&lt;p&gt;One thing I observed is that when using java driver, when gettig a Transient Transaction error and retrying the transaction, we have to explicitly abort it. Otherwise we get a &apos;IllegalStateException - transaction already in progress&apos; when we start it on retry.&lt;/p&gt;

&lt;p&gt;If we dont explicitly abort and dont start as well when retrying, we get transaction aborted on server error. This is not in sync with the javascript examples given at &lt;a href=&quot;https://docs.mongodb.com/master/reference/method/Session.startTransaction/#Session.startTransaction&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://docs.mongodb.com/master/reference/method/Session.startTransaction/#Session.startTransaction&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I can demonstrate this with a test case if you need. Please let me know. &lt;/p&gt;</comment>
                            <comment id="2002721" author="arunkjn" created="Fri, 14 Sep 2018 06:18:47 +0000"  >&lt;p&gt;Thanks Jeff. It is definitely enlightening and cleared a lot of questions for me.&lt;/p&gt;</comment>
                            <comment id="1999815" author="jeff.yemin" created="Tue, 11 Sep 2018 18:41:42 +0000"  >&lt;p&gt;Hi Arun,&lt;/p&gt;

&lt;p&gt;Transactions in MongoDB use &lt;a href=&quot;https://en.wikipedia.org/wiki/Snapshot_isolation&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;snapshot isolation&lt;/a&gt;, which don&apos;t prevent stale reads. This is not specific to MongoDB. Most modern databases work this way.&lt;/p&gt;

&lt;p&gt;Here&apos;s a part of a presentation which talks about conflicts, specifically around reads: &lt;a href=&quot;https://www.youtube.com/watch?v=3x_Pf9rQGCo&amp;amp;t=905s&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://www.youtube.com/watch?v=3x_Pf9rQGCo&amp;amp;t=905s&lt;/a&gt;. You may find it illuminating.&lt;/p&gt;

&lt;p&gt;We think though that we can do a better job explaining this in our online documentation, so &lt;a href=&quot;https://jira.mongodb.org/browse/DOCS-12048&quot; title=&quot;Update Transaction Docs: How to avoid stale reads in transactions&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DOCS-12048&quot;&gt;&lt;del&gt;DOCS-12048&lt;/del&gt;&lt;/a&gt; has been created to address that.&lt;/p&gt;

&lt;p&gt;I&apos;m going to close this ticket now, as the driver and server are working as designed, but please let us know if we can be of further assistance. Thanks for the feedback.&lt;/p&gt;</comment>
                            <comment id="1999062" author="arunkjn" created="Tue, 11 Sep 2018 08:18:21 +0000"  >&lt;p&gt;Thanks Jeff. I have updated the code with another &lt;a href=&quot;https://github.com/arunkjn/mongodbtransactiontest/blob/master/src/test/java/io/github/arunkjn/mongodbtransactiontest/ITCacheServiceTest.java#L107&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;test case&lt;/a&gt; which checks for stale read inside transaction which will lead to a dirty write. Currently this test case is not passing.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="1997655" author="jeff.yemin" created="Mon, 10 Sep 2018 12:25:06 +0000"  >&lt;p&gt;Yes, that&apos;s correct: all operations within the transaction should be passed the &lt;tt&gt;ClientSession&lt;/tt&gt; instance on which the transaction is started.&lt;/p&gt;

&lt;p&gt;This is documented in the &lt;a href=&quot;https://docs.mongodb.com/master/core/transactions/#transactions-and-mongodb-drivers&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;manual&lt;/a&gt;, which is linked to from&#160;the &lt;a href=&quot;http://mongodb.github.io/mongo-java-driver/3.8/whats-new/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;What&apos;s New&lt;/a&gt; section of the Java driver documentation.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="1997649" author="arunkjn" created="Mon, 10 Sep 2018 12:14:24 +0000"  >&lt;p&gt;Hi Jeff,&lt;/p&gt;

&lt;p&gt;Yes doing that solves the problem for me. I feel this should be documented better at &lt;a href=&quot;http://mongodb.github.io/mongo-java-driver/3.8/driver/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://mongodb.github.io/mongo-java-driver/3.8/driver/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, all the collection operations which have to be included in the transaction similarly need session object?&lt;/p&gt;</comment>
                            <comment id="1997642" author="jeff.yemin" created="Mon, 10 Sep 2018 11:52:58 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=arunkjn&quot; class=&quot;user-hover&quot; rel=&quot;arunkjn&quot;&gt;arunkjn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The update operation doesn&apos;t happen within the transaction unless you pass the &lt;tt&gt;ClientSession&lt;/tt&gt; to the &lt;tt&gt;replaceOne&lt;/tt&gt; call &lt;a href=&quot;https://github.com/arunkjn/mongodbtransactiontest/blob/master/src/test/java/io/github/arunkjn/mongodbtransactiontest/ITCacheServiceTest.java#L64&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;here&lt;/a&gt;, as in:&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;collection.replaceOne(session, Filters.eq(&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;arun&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;), person2&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;&#160;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="602793">DOCS-12048</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hty1dr:</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>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>