[JAVA-740] Exception is thrown when replSetReconfig command is sent Created: 22/Jan/13  Updated: 11/Sep/19  Resolved: 22/Jan/13

Status: Closed
Project: Java Driver
Component/s: Cluster Management
Affects Version/s: 2.10.1
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Alex Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

JDK 1.6 with Ubuntu 12.04



 Description   

Hello I am using Mongo Java Driver 2.10.1 and I am trying to reconfigure a replica set configuration by using Mongo Java Driver.

Initially I have four Mongo servers started up with next configuration:

{
      "_id" : "rs-test",
      "version" : 1,
       members : [
           {_id : 0, host : "localhost:27017"},
           {_id : 1, host : "localhost:27018"},
           {_id : 2, host : "localhost:27019"},
	   {_id : 3, host : "localhost:27020"}
       ]
}

Then I have my test which tries to reconfig this replica set by sending next document:

{
      "_id" : "rs-test",
      "version" : 2,
       members : [
           {_id : 0, host : "localhost:27017"},
           {_id : 1, host : "localhost:27018"},
           {_id : 2, host : "localhost:27019"},
	   {_id : 3, host : "localhost:27020", arbiterOnly: true}
       ]
}
 

And Java code:

MongoClient mongoClient = new MongoClient("localhost", 27017);
		
BasicDBObject basicDBObject = new BasicDBObject();
basicDBObject.put("replSetReconfig",JSON.parse(DOCUMENT));
		
DB db = mongoClient.getDB("admin");
CommandResult command = db.command(basicDBObject);
		
System.out.println(command);

And then next exception is returned:

emptying DBPortPool to localhost/127.0.0.1:27017 b/c of error
java.io.EOFException
	at org.bson.io.Bits.readFully(Bits.java:48)
	at org.bson.io.Bits.readFully(Bits.java:33)
	at org.bson.io.Bits.readFully(Bits.java:28)
	at com.mongodb.Response.<init>(Response.java:40)
	at com.mongodb.DBPort.go(DBPort.java:124)
	at com.mongodb.DBPort.call(DBPort.java:74)
	at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:286)
	at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:257)
	at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:310)
	at com.mongodb.DB.command(DB.java:274)
	at com.mongodb.DB.command(DB.java:256)
	at com.mongodb.DB.command(DB.java:313)
	at com.mongodb.DB.command(DB.java:211)
	at MyTest.test(MyTest.java:32)
	at MyTest.main(MyTest.java:40)
Exception in thread "main" com.mongodb.MongoException$Network: can't call something : localhost/127.0.0.1:27017/admin
	at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:295)
	at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:257)
	at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:310)
	at com.mongodb.DB.command(DB.java:274)
	at com.mongodb.DB.command(DB.java:256)
	at com.mongodb.DB.command(DB.java:313)
	at com.mongodb.DB.command(DB.java:211)
	at MyTest.test(MyTest.java:32)
	at MyTest.main(MyTest.java:40)
Caused by: java.io.EOFException
	at org.bson.io.Bits.readFully(Bits.java:48)
	at org.bson.io.Bits.readFully(Bits.java:33)
	at org.bson.io.Bits.readFully(Bits.java:28)
	at com.mongodb.Response.<init>(Response.java:40)
	at com.mongodb.DBPort.go(DBPort.java:124)
	at com.mongodb.DBPort.call(DBPort.java:74)
	at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:286)
	... 8 more

If I go to mongo shell and I type rs.conf() at first time an errno:2 is also shown but then tries to reconnect again and then it works as expected and shows that server with id 3 is hidden. So it seems like command is send successful. Is there any way to avoid that Mongo Driver throws an exception? Maybe me as a user of Mongo Java Driver should implement a recovery function? (basically catching the exception and not propagating it?).

Also I have tried by registering all servers in MongoClient but same exception is thrown.

Thank you very much in advance for your help.



 Comments   
Comment by Scott Hernandez (Inactive) [ 22/Jan/13 ]

This is expected behavior from the server since a replSetReconfig will sometimes (at this point pretty much all the time) cause all connection to be reset. The driver will reconnect automatically, after a bit.

Generated at Thu Feb 08 08:52:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.