<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:37:25 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-640] ReadPreference and Commands such as Count</title>
                <link>https://jira.mongodb.org/browse/CSHARP-640</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;The later releases of the C# driver have added support for Read Preference and we&apos;ve had great success using that in our environment. One aspect of the implementation around Command queries surprised us though. In previous versions, commands such as Count were forced to run against the primary and I&apos;m pleased to see that&apos;s been addressed, but now with a read preference of Primary Preferred all of our &apos;secondary ok&apos; commands like counts seem to always go to the secondary if one is available.&lt;/p&gt;

&lt;p&gt;Is this the desired/intended behaviour? To me, it doesn&apos;t seem correct or at least not intuitive. If I&apos;ve said &quot;I want everything to go to the primary, unless it&apos;s not available&quot; why don&apos;t counts respect this? If the data on the secondary isn&apos;t wanted or shouldn&apos;t be trusted for a read why would it be ok to count potentially stale data?  I understand the semantic difference that they&apos;re &apos;commands&apos; but it seems the change in the driver was intended to recognise these as safe/more innocuous/query type commands which could/should respect the read preference we&apos;re providing.&lt;/p&gt;

&lt;p&gt;Thank you for all your hard work on the latest drivers. Since 1.6 we&apos;ve seen a tremendous improvement in the handling of changes to replica set config/failovers. All much more graceful. Well done!&lt;/p&gt;</description>
                <environment></environment>
        <key id="58630">CSHARP-640</key>
            <summary>ReadPreference and Commands such as Count</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</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="andrew.fladmark@t101.com">Andrew Fladmark</reporter>
                        <labels>
                            <label>question</label>
                    </labels>
                <created>Fri, 7 Dec 2012 12:16:15 +0000</created>
                <updated>Fri, 5 Apr 2019 13:59:11 +0000</updated>
                            <resolved>Tue, 11 Dec 2012 15:33:30 +0000</resolved>
                                    <version>1.6</version>
                    <version>1.6.1</version>
                    <version>1.7</version>
                                    <fixVersion>1.8</fixVersion>
                                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="209207" author="andrew.fladmark@t101.com" created="Fri, 7 Dec 2012 19:34:50 +0000"  >&lt;p&gt;My apologies for not making that clearer sooner. I think what lead me to think of the C# driver in this case is that prior to the implementation of Read Preference, all counts were always run against the master. When we updated to 1.6.1 and simultaneously upgraded the MongoSes to 2.2 the counts shifted to the secondaries... seemingly in response to and yet in defiance of the specified read preference. &lt;/p&gt;

&lt;p&gt;According to the documentation at &lt;a href=&quot;http://docs.mongodb.org/manual/applications/replication/:&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://docs.mongodb.org/manual/applications/replication/:&lt;/a&gt; &quot;mongos currently does not route commands using read preferences; clients send all commands to shards&#8217; primaries. See &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-7423&quot; title=&quot;Support commands for read preference&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-7423&quot;&gt;&lt;del&gt;SERVER-7423&lt;/del&gt;&lt;/a&gt;.&quot;&lt;/p&gt;

&lt;p&gt;So, apparently, full support is being worked on for 2.3 and the situation we have should be impossible. I&apos;ll have a check for any existing issues on MongoS and refile there. &lt;/p&gt;

&lt;p&gt;Thank you very much for your help Robert. It is greatly appreciated.&lt;/p&gt;</comment>
                            <comment id="209150" author="rstam" created="Fri, 7 Dec 2012 18:23:33 +0000"  >&lt;p&gt;Sorry, that was a typo. I was using a ReadPreference of PrimaryPreferred also.&lt;/p&gt;

&lt;p&gt;I didn&apos;t realize you were using a sharded environment. In that case, it&apos;s really up to mongos to decide where to send the commands. The C# driver&apos;s role in this case is to forward the desired ReadPreference to mongos.&lt;/p&gt;

&lt;p&gt;Can you file a new JIRA ticket against mongos?&lt;/p&gt;</comment>
                            <comment id="209090" author="andrew.fladmark@t101.com" created="Fri, 7 Dec 2012 17:12:13 +0000"  >&lt;p&gt;Hi Robert,&lt;/p&gt;

&lt;p&gt;We&apos;re using PrimaryPreferred, not ReadPrimary in this instance (I can&apos;t confirm if it occurs with Primary only). I&apos;ve enabled Database Profiling on the collection on the secondary and I get about 400 a second of these type of queries which I believe are counts?&lt;/p&gt;

&lt;p&gt;/* 0 */&lt;br/&gt;
{&lt;br/&gt;
  &quot;ts&quot; : ISODate(&quot;2012-12-07T16:45:27.767Z&quot;),&lt;br/&gt;
  &quot;op&quot; : &quot;command&quot;,&lt;br/&gt;
  &quot;ns&quot; : &quot;ourdb.$cmd&quot;,&lt;br/&gt;
  &quot;command&quot; : {&lt;br/&gt;
    &quot;count&quot; : &quot;OurCollection&quot;,&lt;br/&gt;
    &quot;query&quot; : &lt;/p&gt;
{
      &quot;pid&quot; : 1320633,
      &quot;vi&quot; : true
    }
&lt;p&gt;  },&lt;br/&gt;
  &quot;ntoreturn&quot; : 1,&lt;br/&gt;
  &quot;keyUpdates&quot; : 0,&lt;br/&gt;
  &quot;numYield&quot; : 0,&lt;br/&gt;
  &quot;lockStats&quot; : {&lt;br/&gt;
    &quot;timeLockedMicros&quot; : &lt;/p&gt;
{
      &quot;r&quot; : NumberLong(739),
      &quot;w&quot; : NumberLong(0)
    }
&lt;p&gt;,&lt;br/&gt;
    &quot;timeAcquiringMicros&quot; : &lt;/p&gt;
{
      &quot;r&quot; : NumberLong(33610),
      &quot;w&quot; : NumberLong(2)
    }
&lt;p&gt;  },&lt;br/&gt;
  &quot;responseLength&quot; : 48,&lt;br/&gt;
  &quot;millis&quot; : 0,&lt;br/&gt;
  &quot;client&quot; : &quot;192.168.xx.xxx&quot;,&lt;br/&gt;
  &quot;user&quot; : &quot;&quot;&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;A similar trace on the primary reveals no such counts, just regular get and update queries as expect. The primary is likewise doing 400/s of those. If I shutdown the secondary, the counts do move over to the primary, but when both are online I&apos;m unable to get anything but this situation. I&apos;ve tried reversing the roles of the servers and the load reverses accordingly.&lt;/p&gt;

&lt;p&gt;This is a sharded collection of two replica sets. We have 2 servers and and an arbiter in each set. All the servers involved (config, mongoSes, and mongoDs are running 2.2.2 on Amazon Linux and/or Centos.  We&apos;re running the 1.7 version of the C# driver today, but we&apos;ve only just upgraded from 1.6.1. Both showed the behaviour consistently.&lt;/p&gt;

&lt;p&gt;We also have a non-sharded replica set which I&apos;ve just checked and it doesn&apos;t seem to be exhibiting this behaviour (the primary is handling 200 queries and 200 commands per second there with no queries and maybe 10 commands a second on the secondary). Could this be an issue with the MongoS servers not respecting or not receiving the ReadPreference or is this maybe desired for some reason I&apos;m not aware of in a sharded situation?&lt;/p&gt;

&lt;p&gt;I&apos;m happy to produce a simplified chunk of code including our settings if its needed.&lt;/p&gt;</comment>
                            <comment id="209067" author="rstam" created="Fri, 7 Dec 2012 16:38:31 +0000"  >&lt;p&gt;I tried to reproduce this and for me the count commands are going to the Primary (not the Secondary) when using a read preference of ReadPrimary.&lt;/p&gt;

&lt;p&gt;Let me know if you have any more details on how to reproduce.&lt;/p&gt;</comment>
                            <comment id="209002" author="rstam" created="Fri, 7 Dec 2012 15:41:37 +0000"  >&lt;p&gt;How are you determining that your count commands are going to a secondary when your read preference is PrimaryPreferred?&lt;/p&gt;

&lt;p&gt;Does it make any difference whether you call Count on MongoCollection or MongoCursor?&lt;/p&gt;

&lt;p&gt;There is code in the driver to force most commands to be sent to the primary (commands that aren&apos;t specifically identified as being OK to send to secondaries), but I don&apos;t see any code that would force any commands to be sent to a secondary.&lt;/p&gt;

&lt;p&gt;If you can provide some code to reproduce it would be helpful (just to make sure we are looking at the same scenario).&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="58681">SERVER-7876</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|hrkyl3:</customfieldvalue>

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