<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:51:39 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-169] Inserts fails during a replica set failover</title>
                <link>https://jira.mongodb.org/browse/JAVA-169</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;Problem:&lt;br/&gt;
Three member replica set. I have code that is inserting into a collection, the connection string has been configured with the three members&lt;/p&gt;

&lt;p&gt;        MongoOptions mo = new MongoOptions();&lt;br/&gt;
        mo.connectionsPerHost = MAX_THREADS + 5;&lt;br/&gt;
        mo.autoConnectRetry = true;&lt;/p&gt;

&lt;p&gt;       String addresses = args&lt;span class=&quot;error&quot;&gt;&amp;#91;0&amp;#93;&lt;/span&gt;;&lt;/p&gt;

&lt;p&gt;        while (addresses.contains(&quot;,&quot;)) &lt;/p&gt;
{
        	String next[] = addresses.split(&quot;,&quot;);
        	connectionList.add(createAddress(next[0]));
        	addresses = next[1];
        }

&lt;p&gt;        connectionList.add(createAddress(addresses));&lt;/p&gt;

&lt;p&gt;        Mongo mongo = new Mongo( connectionList , mo );&lt;/p&gt;

&lt;p&gt;When I cause the current primary to step down (rs.stepDown()), the Java driver throws the following&lt;/p&gt;

&lt;p&gt;Exception in thread &quot;Thread-1&quot; com.mongodb.MongoException: not talking to master and retries used up&lt;br/&gt;
	at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:206)&lt;br/&gt;
	at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:208)&lt;br/&gt;
	at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:208)&lt;br/&gt;
	at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:223)&lt;br/&gt;
	at com.mongodb.DBCollection.findOne(DBCollection.java:486)&lt;br/&gt;
	at com.mongodb.DBCollection.findOne(DBCollection.java:475)&lt;br/&gt;
	at com.mongodb.DB.command(DB.java:137)&lt;br/&gt;
	at com.mongodb.DB.getLastError(DB.java:283)&lt;br/&gt;
	at InsertSpeed$RunnerInsert.run(InsertSpeed.java:72)&lt;/p&gt;

&lt;p&gt;Not sure if there is something else that can be set in order to continue the insert process during the take over event.&lt;/p&gt;

&lt;p&gt;Workaround:&lt;br/&gt;
When going through the mongos process (in a sharded + repl set deployment), can the connection is to the mongos process then this exception does not occur.&lt;/p&gt;

&lt;p&gt;Business Case:&lt;br/&gt;
Reliability&lt;br/&gt;
User Expereince&lt;/p&gt;</description>
                <environment>db version v1.7.1-pre-, pdfile version 4.5&lt;br/&gt;
git hash: eb74c84814a1f0aceb7cd335e1296d419550ae23&lt;br/&gt;
sys info: Linux domU-12-31-39-06-79-A1 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_41</environment>
        <key id="13211">JAVA-169</key>
            <summary>Inserts fails during a replica set failover</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="alvin">Alvin Richards</reporter>
                        <labels>
                    </labels>
                <created>Tue, 28 Sep 2010 22:49:59 +0000</created>
                <updated>Thu, 9 Jan 2014 14:24:21 +0000</updated>
                            <resolved>Wed, 23 Feb 2011 05:46:35 +0000</resolved>
                                    <version>2.1</version>
                                                    <component>Cluster Management</component>
                                        <votes>1</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="24509" author="antoine" created="Wed, 23 Feb 2011 05:46:35 +0000"  >&lt;p&gt;as per previous explanation, this works as expected.&lt;br/&gt;
Please reopen if you believe we can improve further.&lt;/p&gt;</comment>
                            <comment id="24108" author="antoine" created="Thu, 17 Feb 2011 07:50:02 +0000"  >&lt;p&gt;Tony:&lt;br/&gt;
reason for this is because if you have slaveOk=true, then the reads will go to slaves and master does not get updated.&lt;br/&gt;
Once the write operation happens, it goes to what driver believes is master and fails once, then driver will update master.&lt;/p&gt;

&lt;p&gt;If slaveOk=false, then any read happening will try to go to master and fail, but then automatically retry after updating master.&lt;br/&gt;
In turn, following writes wont fail.&lt;/p&gt;

&lt;p&gt;It would be too expensive to check if a server is still master before every writes.&lt;br/&gt;
So instead we let potentially 1 write fail and update the master.&lt;br/&gt;
The exception should be handled by app to retry write.&lt;br/&gt;
Note that this caveat is usually avoided by:&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;if also doing reads with slaveok=false, which will update master&lt;/li&gt;
	&lt;li&gt;every 5s the bg thread will also update it&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Alvin:&lt;br/&gt;
As for exception &quot;not talking to master and retries used up&quot;.&lt;br/&gt;
That only happens on a read with slaveok=false.&lt;br/&gt;
Driver automatically retries read twice but it is possible that the replica set takes time to elect a new master.&lt;br/&gt;
In that case this error may occur.&lt;br/&gt;
Workaround is use slaveok=true, or catch exception and retry after a wait time.&lt;/p&gt;</comment>
                            <comment id="23651" author="hhubris" created="Fri, 11 Feb 2011 02:51:02 +0000"  >&lt;p&gt;I was seeing a similar problem with Mongo server 1.6.5 and Java client library 2.4.&lt;/p&gt;

&lt;p&gt;The full email log can be seen here: &lt;a href=&quot;http://groups.google.com/group/mongodb-user/browse_thread/thread/42a12735b26e5be3&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://groups.google.com/group/mongodb-user/browse_thread/thread/42a12735b26e5be3&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In a nutshell, connecting to a 3 node replica set with slaveOk() set caused this issue:&lt;/p&gt;

&lt;p&gt;Caused by: com.mongodb.MongoException: not master&lt;br/&gt;
	at com.mongodb.DBTCPConnector._checkWriteError(DBTCPConnector.java:136)&lt;br/&gt;
	at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:157)&lt;br/&gt;
	at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:141)&lt;br/&gt;
	at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:225)&lt;br/&gt;
	at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:180)&lt;br/&gt;
	at com.mongodb.DBCollection.insert(DBCollection.java:72)&lt;br/&gt;
	at com.mongodb.DBCollection.save(DBCollection.java:537)&lt;br/&gt;
	at com.mongodb.DBCollection.save(DBCollection.java:517)&lt;/p&gt;


&lt;p&gt;On any write after I manually made the master step down.&lt;/p&gt;

&lt;p&gt;Commenting out slaveOk() worked around the problem.&lt;/p&gt;</comment>
                            <comment id="18920" author="jeff_y" created="Tue, 5 Oct 2010 17:11:59 +0000"  >&lt;p&gt;I&apos;m getting that exception using github trunk, by the way (while testing slaveOk()), and it didn&apos;t recover.&lt;/p&gt;</comment>
                            <comment id="18916" author="eliot" created="Tue, 5 Oct 2010 17:02:43 +0000"  >&lt;p&gt;the find case should be fixed in 2.2&lt;br/&gt;
note you will get 1 failure - then it will fail over.&lt;/p&gt;</comment>
                            <comment id="18914" author="jeff_y" created="Tue, 5 Oct 2010 16:55:33 +0000"  >&lt;p&gt;Also happening on find:&lt;/p&gt;


&lt;p&gt;com.mongodb.MongoException: not talking to master and retries used up&lt;br/&gt;
                at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:222)&lt;br/&gt;
                at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:224)&lt;br/&gt;
                at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:224)&lt;br/&gt;
                at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:256)&lt;br/&gt;
                at com.mongodb.DBCollection.findOne(DBCollection.java:467)&lt;br/&gt;
                at com.mongodb.DBCollection.findOne(DBCollection.java:456)&lt;br/&gt;
                at com.mongodb.DB.command(DB.java:141)&lt;br/&gt;
                at com.mongodb.DBCollection.getCount(DBCollection.java:642)&lt;br/&gt;
                at com.mongodb.DBCursor.size(DBCursor.java:553)&lt;/p&gt;

&lt;p&gt;Nothing to do but restart Java process?&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                                        </inwardlinks>
                                    </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|hrhcuv:</customfieldvalue>

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