<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:37:14 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>[CSHARP-574] Secondary Reads shouldn&apos;t use a Primary if a Secondary is available</title>
                <link>https://jira.mongodb.org/browse/CSHARP-574</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;UPDATE:&lt;br/&gt;
  The code base currently takes primary ping times into consideration when using a secondary preferred read preference, which causes the below issue. In addition, we plan to make the acceptable latency (currently at 15ms) configurable.&lt;/p&gt;

&lt;p&gt;ORIGINAL:&lt;/p&gt;

&lt;p&gt;I have 3 Amazon EC2 instances setup.  Machine A runs Windows 2008 R2 using the 1.6 C# Driver. The Mongo systems are running on Ubuntu 12.&lt;br/&gt;
Machine A: web site (US-West zone)&lt;br/&gt;
Machine B: Mongo 2.2.0 primary (US-West zone)&lt;br/&gt;
Machine C: Mongo 2.2.0 secondary (US-East zone)&lt;/p&gt;

&lt;p&gt;The only way I&apos;m able to get queries to connect to the secondary, is if I set the readPreference to secondary.  Setting to secondaryPreferred always picks the primary so my primary gets overloaded and the secondary is never used.&lt;/p&gt;

&lt;p&gt;The bug seems to come from MultipleInstanceMongoServerProxy.Connect().  When ConnectInstance is called, it starts connections to both servers.  The primary connects right away, but since this function only sleeps for 20 milliseconds, the secondary (in another amazon zone) doesn&apos;t get a chance to finish completing by the time the loops runs again.  So ChooseServerInstance gets called with only the primary connected, so the secondary is not in the list by the time ReadPreference.ChooseServerInstanec is called.&lt;/p&gt;

&lt;p&gt;I saw this behavior happen in the debugger.&lt;/p&gt;
</description>
                <environment>Windows 2008 R2</environment>
        <key id="50911">CSHARP-574</key>
            <summary>Secondary Reads shouldn&apos;t use a Primary if a Secondary is available</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</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="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="mballou">Michael Ballou</reporter>
                        <labels>
                    </labels>
                <created>Wed, 19 Sep 2012 21:37:20 +0000</created>
                <updated>Tue, 6 Sep 2016 14:19:22 +0000</updated>
                            <resolved>Fri, 19 Oct 2012 17:37:04 +0000</resolved>
                                    <version>1.6</version>
                                    <fixVersion>1.8</fixVersion>
                                                        <votes>0</votes>
                                    <watches>5</watches>
                                                                                                                <comments>
                            <comment id="1377189" author="xgen-internal-githook" created="Tue, 6 Sep 2016 14:19:22 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Craig Wilson&apos;, &apos;username&apos;: &apos;craiggwilson&apos;, &apos;email&apos;: &apos;craiggwilson@gmail.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-574&quot; title=&quot;Secondary Reads shouldn&amp;#39;t use a Primary if a Secondary is available&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-574&quot;&gt;&lt;del&gt;CSHARP-574&lt;/del&gt;&lt;/a&gt;: minor changes.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/10gen/sqlproxy/commit/baca05fab070c41728eeb68364a8090e290c3f76&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/10gen/sqlproxy/commit/baca05fab070c41728eeb68364a8090e290c3f76&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="183119" author="auto" created="Tue, 6 Nov 2012 18:00:27 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-10-19T16:31:48Z&apos;, u&apos;email&apos;: u&apos;robert@10gen.com&apos;, u&apos;name&apos;: u&apos;rstam&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-574&quot; title=&quot;Secondary Reads shouldn&amp;#39;t use a Primary if a Secondary is available&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-574&quot;&gt;&lt;del&gt;CSHARP-574&lt;/del&gt;&lt;/a&gt;: SecondaryAcceptableLatency was missing from MongoUrl.&lt;/p&gt;

&lt;p&gt;Conflicts:&lt;br/&gt;
	MongoDB.DriverUnitTests/MongoUrlTests.cs&lt;br/&gt;
Branch: x2.0&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/ea5cf57e3ec21dcfd6c71efcb2e4320f0260b5d6&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/ea5cf57e3ec21dcfd6c71efcb2e4320f0260b5d6&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="177202" author="auto" created="Fri, 19 Oct 2012 17:25:13 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-10-19T09:31:48-07:00&apos;, u&apos;email&apos;: u&apos;robert@10gen.com&apos;, u&apos;name&apos;: u&apos;rstam&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-574&quot; title=&quot;Secondary Reads shouldn&amp;#39;t use a Primary if a Secondary is available&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-574&quot;&gt;&lt;del&gt;CSHARP-574&lt;/del&gt;&lt;/a&gt;: SecondaryAcceptableLatency was missing from MongoUrl.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/e577aac7f59548817a6e51c22cd79022fefee319&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/e577aac7f59548817a6e51c22cd79022fefee319&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="177182" author="rstam" created="Fri, 19 Oct 2012 16:25:56 +0000"  >&lt;p&gt;Still need to add SecondaryAcceptableLatency to MongoUrl.&lt;/p&gt;</comment>
                            <comment id="168442" author="auto" created="Wed, 26 Sep 2012 20:48:05 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-09-24T12:50:36-07:00&apos;, u&apos;email&apos;: u&apos;robert@10gen.com&apos;, u&apos;name&apos;: u&apos;rstam&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-574&quot; title=&quot;Secondary Reads shouldn&amp;#39;t use a Primary if a Secondary is available&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-574&quot;&gt;&lt;del&gt;CSHARP-574&lt;/del&gt;&lt;/a&gt;: special case single matching instance and put lock around call to Random.Next.&lt;br/&gt;
Branch: x2.0&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/061a30bcab4dad03e62bf55d8ff04a92e0452dd7&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/061a30bcab4dad03e62bf55d8ff04a92e0452dd7&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="168441" author="auto" created="Wed, 26 Sep 2012 20:48:03 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-09-20T07:48:56-07:00&apos;, u&apos;email&apos;: u&apos;robert@10gen.com&apos;, u&apos;name&apos;: u&apos;rstam&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-574&quot; title=&quot;Secondary Reads shouldn&amp;#39;t use a Primary if a Secondary is available&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-574&quot;&gt;&lt;del&gt;CSHARP-574&lt;/del&gt;&lt;/a&gt;: refactor so callers of GetMatchingInstances decide which instances should be matched against.&lt;br/&gt;
Branch: x2.0&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/efbacdfb92f2825e3649991578317018de3ff766&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/efbacdfb92f2825e3649991578317018de3ff766&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="168440" author="auto" created="Wed, 26 Sep 2012 20:48:01 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-09-20T05:47:27-07:00&apos;, u&apos;email&apos;: u&apos;robert@10gen.com&apos;, u&apos;name&apos;: u&apos;rstam&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-574&quot; title=&quot;Secondary Reads shouldn&amp;#39;t use a Primary if a Secondary is available&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-574&quot;&gt;&lt;del&gt;CSHARP-574&lt;/del&gt;&lt;/a&gt;: reduce possibility of lock contention and move matching logic out of ConnectedInstanceCollection and into ReplicaSetMongoServerProxy.&lt;br/&gt;
Branch: x2.0&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/a33ae01666c331d140565d5d05ae0936bc8ed2e1&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/a33ae01666c331d140565d5d05ae0936bc8ed2e1&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="168439" author="auto" created="Wed, 26 Sep 2012 20:48:00 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-09-19T22:47:38-07:00&apos;, u&apos;email&apos;: u&apos;robert@10gen.com&apos;, u&apos;name&apos;: u&apos;rstam&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-574&quot; title=&quot;Secondary Reads shouldn&amp;#39;t use a Primary if a Secondary is available&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-574&quot;&gt;&lt;del&gt;CSHARP-574&lt;/del&gt;&lt;/a&gt;: refactor the ReadPreference implementation and fix some issues.&lt;br/&gt;
Branch: x2.0&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/74d21a5f1f6231d7bdabd7f7b50c2b89b77a9698&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/74d21a5f1f6231d7bdabd7f7b50c2b89b77a9698&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="167759" author="auto" created="Tue, 25 Sep 2012 14:30:20 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-09-24T12:50:36-07:00&apos;, u&apos;email&apos;: u&apos;robert@10gen.com&apos;, u&apos;name&apos;: u&apos;rstam&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-574&quot; title=&quot;Secondary Reads shouldn&amp;#39;t use a Primary if a Secondary is available&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-574&quot;&gt;&lt;del&gt;CSHARP-574&lt;/del&gt;&lt;/a&gt;: special case single matching instance and put lock around call to Random.Next.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/34bbb5b97739a4d2fdcdc56f8b56627274ced2d8&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/34bbb5b97739a4d2fdcdc56f8b56627274ced2d8&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="167758" author="auto" created="Tue, 25 Sep 2012 14:30:18 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-09-20T07:48:56-07:00&apos;, u&apos;email&apos;: u&apos;robert@10gen.com&apos;, u&apos;name&apos;: u&apos;rstam&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-574&quot; title=&quot;Secondary Reads shouldn&amp;#39;t use a Primary if a Secondary is available&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-574&quot;&gt;&lt;del&gt;CSHARP-574&lt;/del&gt;&lt;/a&gt;: refactor so callers of GetMatchingInstances decide which instances should be matched against.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/dc4ece4c3706111739024da8ec9b11a7c89996fc&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/dc4ece4c3706111739024da8ec9b11a7c89996fc&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="167757" author="auto" created="Tue, 25 Sep 2012 14:30:17 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-09-20T05:47:27-07:00&apos;, u&apos;email&apos;: u&apos;robert@10gen.com&apos;, u&apos;name&apos;: u&apos;rstam&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-574&quot; title=&quot;Secondary Reads shouldn&amp;#39;t use a Primary if a Secondary is available&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-574&quot;&gt;&lt;del&gt;CSHARP-574&lt;/del&gt;&lt;/a&gt;: reduce possibility of lock contention and move matching logic out of ConnectedInstanceCollection and into ReplicaSetMongoServerProxy.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/3f74e5cc0a5bd6df7c86415805c1a3fea74e0ab7&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/3f74e5cc0a5bd6df7c86415805c1a3fea74e0ab7&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="167756" author="auto" created="Tue, 25 Sep 2012 14:30:15 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-09-19T22:47:38-07:00&apos;, u&apos;email&apos;: u&apos;robert@10gen.com&apos;, u&apos;name&apos;: u&apos;rstam&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-574&quot; title=&quot;Secondary Reads shouldn&amp;#39;t use a Primary if a Secondary is available&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-574&quot;&gt;&lt;del&gt;CSHARP-574&lt;/del&gt;&lt;/a&gt;: refactor the ReadPreference implementation and fix some issues.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/8549cb72f04f511aa470618cc5510ad2a00b3fa5&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/8549cb72f04f511aa470618cc5510ad2a00b3fa5&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="166183" author="craiggwilson" created="Thu, 20 Sep 2012 00:28:23 +0000"  >&lt;p&gt;Mike,  this is actually a bug in our system.  When you use secondary preferred, we should actually be ignoring the primary if a secondary is available.  I retitled and edited the description of the Jira.&lt;/p&gt;

&lt;p&gt;Keep in mind in this case that all your reads are going to go all the way across the country to get information.&lt;/p&gt;

&lt;p&gt;Our suggestion in the immediate case is to make your US-East secondary the hidden member and your hidden US-West secondary live.  I would actually suggest this action regardless because of the above mentioned latency of always going across country.&lt;/p&gt;</comment>
                            <comment id="166166" author="mballou" created="Wed, 19 Sep 2012 22:43:57 +0000"  >&lt;p&gt;Thanks Craig.&lt;br/&gt;
I do have a 3rd member in the West, but it&apos;s a smaller instance and its configured as hidden with 0 priority.  &lt;/p&gt;

&lt;p&gt;You are correct on the ping times.  The West coast mongo pings are less than 1ms.  The East coast times are 84ms. Given that, it is outside the 15 millisecond window and is never chosen.&lt;/p&gt;

&lt;p&gt;I don&apos;t see a huge demand for this behavior.  It&apos;s really only useful when spreading data to multiple data-centers for redundancy, but the proper way would be for me to have multiple replicas in each zone.  I&apos;m in the process of setting up more replicas in the west as a result.&lt;/p&gt;

&lt;p&gt;Maybe just a comment in the release notes/readme would suffice so someone else can benefit from that knowledge.  Or some kind of driver logging that can show why a particular server is chosen.&lt;/p&gt;</comment>
                            <comment id="166159" author="craiggwilson" created="Wed, 19 Sep 2012 21:57:59 +0000"  >&lt;p&gt;That is true about the initial connect where we will return as soon as we possibly can to get you up and running.  However, connect is only used once.  The rest of the time ChooseServerInstance is used...&lt;/p&gt;

&lt;p&gt;The driver maintains a list of average ping times for each instance it is connected to.  The way all the drivers implement this particular algorithm is the same.  In the case where multiple instances are possible (secondary, and secondary preferred).  Basically, we find all the servers matching both the read preference and the tags if any are specified, and then randomly choose an instance from those within 15 milliseconds of lowest ping time.  You can see this behavior here: &lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/blob/master/Driver/Core/ReadPreference.cs#L399&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/blob/master/Driver/Core/ReadPreference.cs#L399&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Do you only have a 2 member replica set?  Given your setup, I am not surprised that your secondary never gets hit as the request has to travel all the way across the country.  We could make this functionality pluggable, but that doesn&apos;t exist at this point in time.  What are your thoughts?&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|hriafj:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>20335</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>