<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:56:51 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-2293] Collection caching in DBApiLayer.doGetCollection(&#8230;) is broken</title>
                <link>https://jira.mongodb.org/browse/JAVA-2293</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;&lt;tt&gt;DBApiLayer.doGetCollection(&#8230;)&lt;/tt&gt; looks up &lt;tt&gt;DBCollection&lt;/tt&gt; items from a cache based on name. However, &lt;tt&gt;DBCollection&lt;/tt&gt; exposes methods to mutate the state of the returned instance which makes those state changes propagate to other (potentially concurrent) clients requesting a collection.&lt;/p&gt;

&lt;p&gt;In practice that means that a client e.g. setting a read preference on the collection, is setting it globally for all other clients that want to work with the same collection, although they might want to use a different read preference.&lt;/p&gt;

&lt;p&gt;The client side workaround is effectively synchronizing the access to a collection and making sure &lt;b&gt;all&lt;/b&gt; mutable properties are &lt;b&gt;always&lt;/b&gt; set.&lt;/p&gt;

&lt;p&gt;The original issue &lt;a href=&quot;https://jira.spring.io/browse/DATAMONGO-1061&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;popped up&lt;/a&gt; with Spring Data MongoDB users that wanted to use different read preferences with different &lt;tt&gt;MongoTemplate&lt;/tt&gt; instance.&lt;/p&gt;</description>
                <environment></environment>
        <key id="313005">JAVA-2293</key>
            <summary>Collection caching in DBApiLayer.doGetCollection(&#8230;) is broken</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="2">Won&apos;t Fix</resolution>
                                        <assignee username="ross@mongodb.com">Ross Lawley</assignee>
                                    <reporter username="oliver.gierke">Oliver Gierke</reporter>
                        <labels>
                    </labels>
                <created>Wed, 31 Aug 2016 08:27:38 +0000</created>
                <updated>Mon, 19 Sep 2016 14:16:17 +0000</updated>
                            <resolved>Tue, 13 Sep 2016 01:41:57 +0000</resolved>
                                    <version>3.3.0</version>
                                                    <component>API</component>
                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="1387440" author="jeff.yemin" created="Mon, 19 Sep 2016 14:16:17 +0000"  >&lt;p&gt;Since findAndModify writes as well as reads, it always has to run on the primary.&lt;/p&gt;</comment>
                            <comment id="1387396" author="oliver.gierke" created="Mon, 19 Sep 2016 13:36:07 +0000"  >&lt;p&gt;Any suggestion what to do for e.g. &lt;tt&gt;findAndModify(&#8230;)&lt;/tt&gt; there doesn&apos;t seem to be an overload taking a read preference.&lt;/p&gt;</comment>
                            <comment id="1382975" author="jeff.yemin" created="Tue, 13 Sep 2016 10:49:59 +0000"  >&lt;p&gt;Yes, that&apos;s correct.  The DBCursor&apos;s properties don&apos;t get &quot;frozen&quot; until the application starts treating it as an Iterator by calling next() or hasNext() on it.&lt;/p&gt;</comment>
                            <comment id="1382910" author="oliver.gierke" created="Tue, 13 Sep 2016 07:47:53 +0000"  >&lt;p&gt;Thanks for the feedback, Jeff. Just to make sure I get you right: you&apos;re basically suggesting to set the read preference on the &lt;tt&gt;DBCursor&lt;/tt&gt; that e.g. a &lt;tt&gt;find(&#8230;)&lt;/tt&gt; operation returns? I so far didn&apos;t consider that an option as I assumed, that as soon as I get hold of a &lt;tt&gt;DBCursor&lt;/tt&gt; the query has actually been already executed and it&apos;s basically too late to tweak any preferences that might influence the execution of it. Am I right that you&apos;re suggesting that would be a reasonable workaround?&lt;/p&gt;</comment>
                            <comment id="1382813" author="jeff.yemin" created="Tue, 13 Sep 2016 01:41:57 +0000"  >&lt;p&gt;Closing as Won&apos;t Fix, but I will re-open if necessary based on subsequent comments.&lt;/p&gt;</comment>
                            <comment id="1373200" author="jeff.yemin" created="Wed, 31 Aug 2016 12:36:42 +0000"  >&lt;p&gt;Users may be relying on the fact that DBCollection instances are cached and the cached instances retain the property settings.  Changing this will break anyone relying on that.&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;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: #008200; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;// One part of the app&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&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;   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;client.getDB(&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;test&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;).getCollection(&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;test&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;).setReadPreference(secondary());&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&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;   width: auto; padding: 0;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&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;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: #008200; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;// some other part of the app with access to the client&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&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-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;client.getDB(&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;test&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;).getCollection(&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;test&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;).findOne();  &lt;/span&gt;&lt;span style=&quot;color: #008200; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;// assumes that read preference has been set appropriately somewhere else&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;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;I also don&apos;t think we should add an alternative getCollection method.  It would make reasoning about the behavior difficult, as one would not know, given a DBCollection instance of unknown provenance, whether it was shared or not.  And if we did do that, then for consistency we&apos;d have to do the same for DB instances. &lt;/p&gt;

&lt;p&gt;If MongoTemplate fully wraps the DBCollection, a possible workaround would be to set the read preference on the MongoTemplate and then specify it for every operation instead of as a default on the DBCollection.&lt;/p&gt;</comment>
                            <comment id="1373044" author="oliver.gierke" created="Wed, 31 Aug 2016 09:39:28 +0000"  >&lt;p&gt;There are, but for backwards compatibility reasons we can&apos;t move away from the existing APIs until a &quot;Spring Data 2.0&quot;. We already have bits of the migration in place but ultimately we&apos;re not going to release that before a Spring 5.0 in March 2017.&lt;/p&gt;

&lt;p&gt;I am kind of wondering what compatibility issues you imagine if the call returned a fresh &lt;tt&gt;DBCollection&lt;/tt&gt; for each invocation. Assuming &lt;tt&gt;equals(&#8230;)&lt;/tt&gt; and &lt;tt&gt;hashCode()&lt;/tt&gt; are implemented correctly, it shouldn&apos;t make any difference. It&apos;s of course up to you what to do with the issue but a decision not to do anything about it would basically render concurrent collection access with different read preferences unusable on that driver generation. I&apos;d be forced to close the upstream bug as works as designed then.&lt;/p&gt;</comment>
                            <comment id="1373030" author="ross@10gen.com" created="Wed, 31 Aug 2016 09:00:15 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=oliver.gierke&quot; class=&quot;user-hover&quot; rel=&quot;oliver.gierke&quot;&gt;oliver.gierke&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Thanks for the ticket, you&apos;re correct the &lt;tt&gt;DBCollection&lt;/tt&gt; is mutable and cached which I appreciate can cause complications.  The reasoning for the design decision is from before my time on the Java driver.  However, changing it would mean that it would break the existing behaviour that some users rely on.&lt;/p&gt;

&lt;p&gt;As the &lt;tt&gt;DB&lt;/tt&gt; and &lt;tt&gt;DBCollection&lt;/tt&gt; api&apos;s are deprecated (via the access point &lt;tt&gt;MongoClient#getDB&lt;/tt&gt;), I&apos;m leaning towards closing this ticket as &quot;Won&apos;t Fix&quot;.  Especially, as the newer &lt;tt&gt;MongoDatabase&lt;/tt&gt; and &lt;tt&gt;MongoCollection&lt;/tt&gt; API&apos;s (accessible via &lt;tt&gt;MongoClient#getDatabase&lt;/tt&gt;) are immutable and don&apos;t suffer from this issue.  Are there any plans to migrate to the new API&apos;s? A good motivation might be access to new features coming in forthcoming MongoDB releases will be accessible via the new API.&lt;/p&gt;

&lt;p&gt;Ross&lt;/p&gt;</comment>
                    </comments>
                    <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|hsp9q7:</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>