<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:51:48 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-231] Failed to retrieve any result when using SlaveOK with all slaves are down</title>
                <link>https://jira.mongodb.org/browse/JAVA-231</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;Java driver 2.3.&lt;/p&gt;

&lt;p&gt;We have 3 mongo servers. Each has 48G with 24 CPUs. The servers are running with replica set.&lt;/p&gt;


&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;joseph.wang@lpsdb1.la2 ~&amp;#93;&lt;/span&gt;$ /usr/local/mongodb-linux-x86_64-1.6.3/bin/mongo localhost:4110&lt;br/&gt;
MongoDB shell version: 1.6.3&lt;br/&gt;
connecting to: localhost:4110/test&lt;br/&gt;
&amp;gt; rs.status()&lt;br/&gt;
{&lt;br/&gt;
        &quot;set&quot; : &quot;prod&quot;,&lt;br/&gt;
        &quot;date&quot; : &quot;Sat Dec 11 2010 13:04:28 GMT-0800 (PST)&quot;,&lt;br/&gt;
        &quot;myState&quot; : 1,&lt;br/&gt;
        &quot;members&quot; : [&lt;br/&gt;
                &lt;/p&gt;
{
                        &quot;_id&quot; : 0,
                        &quot;name&quot; : &quot;lpsdb1.la2.estalea.net:4110&quot;,
                        &quot;health&quot; : 1,
                        &quot;state&quot; : 1,
                        &quot;self&quot; : true
                }
&lt;p&gt;,&lt;br/&gt;
                &lt;/p&gt;
{
                        &quot;_id&quot; : 1,
                        &quot;name&quot; : &quot;mongo-prod-mem2.lps.la2.estalea.net:4110&quot;,
                        &quot;health&quot; : 1,
                        &quot;state&quot; : 2,
                        &quot;uptime&quot; : 11095,
                        &quot;lastHeartbeat&quot; : &quot;Sat Dec 11 2010 13:04:27 GMT-0800 (PST)&quot;
                }
&lt;p&gt;,&lt;/p&gt;
                {
                        &quot;_id&quot; : 2,
                        &quot;name&quot; : &quot;mongo-prod-mem3.lps.la2.estalea.net:4110&quot;,
                        &quot;health&quot; : 1,
                        &quot;state&quot; : 2,
                        &quot;uptime&quot; : 11178,
                        &quot;lastHeartbeat&quot; : &quot;Sat Dec 11 2010 13:04:26 GMT-0800 (PST)&quot;
                }
&lt;p&gt;        ],&lt;br/&gt;
        &quot;ok&quot; : 1&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;The connection pool was connecting to all three servers.  We manually brought down two slaves to see if we can get query result (as part of fault tolerance testing).&lt;br/&gt;
There were no update/writes. Just query. When 1 slave was down, we&apos;d no problem getting query result. When 2 slaves were down, we got no query result.&lt;br/&gt;
When a consumer query comes in, we fork out multiple threads, each responsible for fetch data from specific collection.&lt;/p&gt;

&lt;p&gt;MongoConnection.java shows our singleton connection pool code. &lt;br/&gt;
BaseTableQueryEngine.java shows our query to one of our collections.&lt;/p&gt;


&lt;p&gt;As you can see, we set slaveOk at the query level.&lt;/p&gt;

&lt;p&gt;				if (db != null) {&lt;br/&gt;
					DBCollection coll = db.getCollection(currentCollection);&lt;br/&gt;
					DBCursor cur = null;&lt;/p&gt;

&lt;p&gt;					cur = coll.find(dbQuery).addOption(&lt;br/&gt;
							Bytes.QUERYOPTION_SLAVEOK);&lt;/p&gt;

&lt;p&gt;					DBObject dbObject = db.getLastError();&lt;br/&gt;
					if (dbObject != null &amp;amp;&amp;amp; dbObject.get(&quot;err&quot;) != null) &lt;/p&gt;
{
						log.warn(&quot;BaseTableQueryEngine: Encounter error for query &quot; + dbQuery.toString());
						setSuccess(false);
					}

&lt;p&gt;					if (enable_debug) &lt;/p&gt;
{
						log.debug(&quot;BaseTableQueryEngine: Run query &quot;
								+ dbQuery.toString());
						log.debug(&quot;BaseTableQueryEngine: Found &quot;
								+ cur.count() + &quot; in &quot;
								+ (System.currentTimeMillis() - fStart));
					}
&lt;p&gt;					while (cur.hasNext()) {&lt;br/&gt;
						BasicDBObject dbo = (BasicDBObject) cur.next();&lt;br/&gt;
						BaseTableRow row = new BaseTableRow(dbo);&lt;br/&gt;
						if (row.isValid()) &lt;/p&gt;
{
							tuples.add(row.getTuple());
						}

&lt;p&gt;						long time = (timeout - (System.currentTimeMillis() - fStart));&lt;br/&gt;
						if (time &amp;lt; 0) &lt;/p&gt;
{
							break;
						}
&lt;p&gt;					}&lt;/p&gt;

&lt;p&gt;					if (enable_debug) &lt;/p&gt;
{
						log.debug(&quot;BaseTableQueryEngine: tuples &quot;
								+ tuples.size() + &quot; in time &quot;
								+ (System.currentTimeMillis() - fStart));
					}
&lt;p&gt;				}&lt;/p&gt;

</description>
                <environment>[&lt;a href=&apos;mailto:joseph.wang@lpsdb1.la2&apos;&gt;joseph.wang@lpsdb1.la2&lt;/a&gt; ~]$ uname -a&lt;br/&gt;
Linux lpsdb1.la2.estalea.net 2.6.18-194.17.4.el5 #1 SMP Mon Oct 25 15:50:53 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux&lt;br/&gt;
[&lt;a href=&apos;mailto:joseph.wang@lpsdb1.la2&apos;&gt;joseph.wang@lpsdb1.la2&lt;/a&gt; ~]$ ps auwww | grep mongo&lt;br/&gt;
knut      1400  0.0  0.0  83116  4728 pts/0    S+   Dec10   0:00 /usr/local/mongodb-linux-x86_64-1.6.3/bin/mongo localhost:4110&lt;br/&gt;
805       2044  0.0  0.0  61172   720 pts/2    S+   13:02   0:00 grep mongo&lt;br/&gt;
</environment>
        <key id="13934">JAVA-231</key>
            <summary>Failed to retrieve any result when using SlaveOK with all slaves are down</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="9">Done</resolution>
                                        <assignee username="antoine">Antoine Girbal</assignee>
                                    <reporter username="joseph.wang">Joseph Wang </reporter>
                        <labels>
                    </labels>
                <created>Sat, 11 Dec 2010 21:11:24 +0000</created>
                <updated>Thu, 17 Mar 2011 19:13:54 +0000</updated>
                            <resolved>Wed, 16 Feb 2011 01:39:00 +0000</resolved>
                                    <version>2.3</version>
                                    <fixVersion>2.5</fixVersion>
                                    <component>Cluster Management</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="23977" author="antoine" created="Wed, 16 Feb 2011 01:39:00 +0000"  >&lt;p&gt;I tested this case and was able to read fine from last slave, with 2 servers down from replica set.&lt;br/&gt;
I am assuming that this issue stemmed from other bugs fixed earlier.&lt;/p&gt;</comment>
                            <comment id="21363" author="antoine" created="Mon, 13 Dec 2010 14:47:17 +0000"  >&lt;p&gt;jar from trunk&lt;/p&gt;</comment>
                            <comment id="21362" author="antoine" created="Mon, 13 Dec 2010 14:40:18 +0000"  >&lt;p&gt;this is most likely related to bug&lt;br/&gt;
&lt;a href=&quot;http://jira.mongodb.org/browse/JAVA-225&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;http://jira.mongodb.org/browse/JAVA-225&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;basically the Java driver was ignoring the slaveOk option when looking for a master.&lt;br/&gt;
Joseph, could you try with latest driver from trunk (I will also attach a jar you can use).&lt;br/&gt;
Note that builds from trunk should only be used for testing.&lt;/p&gt;</comment>
                            <comment id="21345" author="scotthernandez" created="Sun, 12 Dec 2010 15:51:53 +0000"  >&lt;p&gt;SlaveOk means that queries can be sent to the slave, not they must be, IMO.&lt;/p&gt;</comment>
                            <comment id="21339" author="joseph.wang" created="Sun, 12 Dec 2010 05:06:35 +0000"  >&lt;p&gt;if there is a way to determine that all slaves are down, i don&apos;t mind reissuing the query w/o slave_ok s.t. it will get to primary/master.&lt;/p&gt;</comment>
                            <comment id="21338" author="eliot" created="Sun, 12 Dec 2010 04:46:41 +0000"  >&lt;p&gt;Correct - slave_ok means reads hit slaves, and writes hit master.&lt;br/&gt;
slave_ok is only relevant for reads.&lt;/p&gt;

&lt;p&gt;the correct thing is probably to read from the master if all slaves are down.&lt;/p&gt;

&lt;p&gt;the only issue is if you do queries that are really slow and you assume is going to happen on slave&lt;/p&gt;</comment>
                            <comment id="21337" author="joseph.wang" created="Sun, 12 Dec 2010 00:59:26 +0000"  >&lt;p&gt;My understanding from 2.2 driver fix was that SlaveOK meant querying slave for query, but still hit master for write/update.&lt;/p&gt;

&lt;p&gt;When all slaves are down, we need to have an option to specify hitting master. &lt;br/&gt;
1) From the getLastError(), how do we determine if all slaves are done. If we can detect this condition, I can remove SlaveOK.?&lt;br/&gt;
2) If we cannot determine if all slaves are down, is there an option that I can specify to say it is acceptable to hit master?&lt;/p&gt;</comment>
                            <comment id="21336" author="eliot" created="Sun, 12 Dec 2010 00:44:13 +0000"  >&lt;p&gt;Its a tad unclear.&lt;br/&gt;
The general contract of slave_ok is that only slaves will be used.&lt;br/&gt;
So I&apos;m not 100% sure what the right thing is here.&lt;br/&gt;
Either is probably technically ok - most important is that its well documented and consistent across all drivers.&lt;/p&gt;</comment>
                            <comment id="21335" author="joseph.wang" created="Sat, 11 Dec 2010 22:17:48 +0000"  >&lt;p&gt;Yes, that will be desirable. If no slave is available, query from the primary/master even if SLAVE_OK is set at the query/db/collection level.&lt;/p&gt;</comment>
                            <comment id="21334" author="scotthernandez" created="Sat, 11 Dec 2010 22:15:37 +0000"  >&lt;p&gt;It seems like if the non-master pool is empty then the master should be used, yes?&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="10657" name="BaseTableQueryEngine.java" size="3741" author="joseph.wang" created="Sat, 11 Dec 2010 21:11:24 +0000"/>
                            <attachment id="10656" name="MongoConnnection.java" size="3046" author="joseph.wang" created="Sat, 11 Dec 2010 21:11:24 +0000"/>
                            <attachment id="10663" name="mongo.jar" size="229264" author="antoine" created="Mon, 13 Dec 2010 14:47:17 +0000"/>
                    </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|hrgipb:</customfieldvalue>

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