[JAVA-1786] Error running command when rs is not fully setup Created: 30/Apr/15 Updated: 05/May/15 Resolved: 05/May/15 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Dharshan Rangegowda | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Server 3.0.2 |
||
| Description |
|
Here is the situation The servers are setup for a replica set with a keyfile and replica name configured in the conf file I am trying to run a command on 127.0.0.1 to initialize the replica set. It fails with the following error
If I remove the replica set parameter from the conf file the commands work fine. I need to run commands in this mode because that is now I initialize the replica set. |
| Comments |
| Comment by Ross Lawley [ 05/May/15 ] | |||||||||||||||
|
For a successful replicaSet connection you must connect to an initialised replicaSet otherwise the driver will not be able to direct and reads or writes. This follows the Server Selection Specification. As the driver cannot find an authoritative server to direct the read or write command to the serverSelectionTimeout will trigger. You can run read commands when establishing a direct connection to a node and set the readPreference to allow either Primary or Secondary nodes. In this scenario you are explicitly providing the authoritative server by using a direct connection. As this is the intended behaviour and is accordance with the Server Selection Specification I am closing this ticket as "Works as Designed". For future, the best place for questions regarding MongoDB usage or the Java driver specifics is the mongodb-user mailinglist or stackoverflow as you will reach a boarder audience there. | |||||||||||||||
| Comment by Dharshan Rangegowda [ 05/May/15 ] | |||||||||||||||
|
Hi Jeff, I am not sure I understand. Even if there are multiple servers you should be able to execute the command. | |||||||||||||||
| Comment by Jeffrey Yemin [ 05/May/15 ] | |||||||||||||||
|
Hi Darshan, This is telling:
The fact that mode=MULTIPLE means that your application is passing a List of ServerAddress instances to the MongoClient constructor, instead of a single ServerAddress instance. Even if the List contains just a single element, the fact that it's a list will set mode=MULTIPLE and the command will fail, as Ross indicated earlier. | |||||||||||||||
| Comment by Dharshan Rangegowda [ 05/May/15 ] | |||||||||||||||
|
Here you go. I am just trying to run the command now - BasicDBObject cmd = new BasicDBObject("buildInfo", "1"); Another data point I forgot to mention is that I have SSL enabled.
| |||||||||||||||
| Comment by Ross Lawley [ 30/Apr/15 ] | |||||||||||||||
|
Can you provide more logging output to help diagnose? I was successfully able to connect to run the replSetInitiate command and have it initialize the replicaSet for me. Here is my sample code:
| |||||||||||||||
| Comment by Dharshan Rangegowda [ 30/Apr/15 ] | |||||||||||||||
|
Hi Ross, I am specifying a seed of 127.0.0.1, 127.0.0.1 (This was to get around the other issue I hit) and a readPreference of SecondaryPreferred. I specified a single server 127.0.0.1 and removed the read preference and I still see the same error. I run the BasicDBObject doc = new BasicDBObject("buildInfo", "1"); command before I do the initiate because we want to verify the version. | |||||||||||||||
| Comment by Ross Lawley [ 30/Apr/15 ] | |||||||||||||||
|
If you try to provide a seed list then or provide the replicaSet name then it is expected to fail. This is because the replicaSet is not configured and therefore can't be connected to for operations. From your single log message I can see the current view of the cluster is UNKNOWN and the nodes are of type REPLICA_SET_GHOST leading me to understand that the driver knows its talking to a replicaSet. The other cluster monitoring logs should provide more information about the state of the replicaSet from the drivers perspective. I was able to connect to an uninitialised replicaSet and successfully run the replSetInitiate command by directly connecting to a single node. How are you connecting? Removing the replicaSet parameter from the conf file will make the mongod run in standalone mode which is not what what you desire. Ross |