Skip to content

PHPC-361: Manager::getServers() should omit unknown servers #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2015

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Aug 14, 2015

@bjori
Copy link
Contributor

bjori commented Aug 14, 2015

I'm pretty sure we decided against that.

getServers() was supposed to return you the currently known servers.
If there hasn't been any op yet, then we don't know of any...

@jmikola
Copy link
Member Author

jmikola commented Aug 17, 2015

I didn't recall any discussion about it. Before this patch, the behavior I observed was that getServers() returns Server objects based on the hosts inferred from the URI itself. Those will have an unknown state and it's also possible that their hints won't be usable later on. I think users might be more baffled by the fact that we'd create Server objects for them that may not be usable.

This is distinct from the situation where we might return a Server for a replica set node that ends up being removed from the set (or shut down) before the user attempts to execute an operation on it directly. At least in that case, the Server object did have some known state and an isMaster record.

@bjori
Copy link
Contributor

bjori commented Aug 17, 2015

See https://jira.mongodb.org/browse/PHPC-194

You describe yourself the difference of selectServer() and getServers(), seemingly firm on getServers() behaving correctly.

@jmikola
Copy link
Member Author

jmikola commented Aug 17, 2015

@bjori: To quote that ticket:

This is mainly because Manager construction is lazy and Manager::getServers() would return an empy array before initialization time.

At some point, this must have changed. intern->client->topology->description.servers might have been an empty set before, but it currently consists of one or more unknown server structs.

As an aside, such a server selection should be possible to implement in userland given a ReadPreference and manually calling Manager::getServers() and sorting through the info (i.e. isMaster results) and latency for all servers; however, that would require a userland implementation to kickstart SDAM with a ping if the collection of servers was empty.

I suppose this PR is essentially adding that SDAM kickstart process we'd need to implement a userland selection process.

@bjori
Copy link
Contributor

bjori commented Aug 17, 2015

Subject: Implement Manager::selectServer() method to wrap SDAM server selection

This may require two new features in libmongoc:

  • Manually trigger SDAM initialization
  • Allow querying SDAM's server selection and obtaining a server hint (outside of doing an actual operation)

And thats exactly what we did.

This was all argued from the standpoint of getServers() behaving correctly.
If getServers() now does half of this, does it then make sense to remove selectServer() ?
The $readPreference argument could be merged to getServers()?

@jmikola
Copy link
Member Author

jmikola commented Aug 18, 2015

If getServers() now does half of this, does it then make sense to remove selectServer() The $readPreference argument could be merged to getServers()?

There's benefit in selectServer() returning a single Server and raising exceptions when server selection fails. That API was ideal for the needs of PHPLIB.

I do see how getServers() could be employed for userland server selection (e.g. with a custom round-robin algorithm), irrespective of whether the extension method took a read preference. That said, I see it more as a diagnostic tool, akin to getConnections() in the legacy driver. If we made it more like selectServer(), then there'd be the question of whether failing to find any Server(s) would throw or simply return an empty array.

@jmikola
Copy link
Member Author

jmikola commented Aug 18, 2015

Per discussion in IRC, I've revised PHPC-361 to state that getServers() should be changed to merely filter out servers in unknown states instead of performing full discovery. This keeps the method passive and removes functional overlap with selectServer().

I'll revise this PR after the 1.0.0-alpha release.

@jmikola jmikola changed the title PHPC-361: Manager::getServers() should ensure initial discovery PHPC-361: Manager::getServers() should not return unknown servers Aug 24, 2015
@jmikola jmikola changed the title PHPC-361: Manager::getServers() should not return unknown servers PHPC-361: Manager::getServers() should omit unknown servers Aug 25, 2015
@jmikola
Copy link
Member Author

jmikola commented Aug 25, 2015

Ready to be reviewed again.

Pinging
Known servers: 3
Found server: %s:%d
Found replica set server type: %r(4|5|6)%r
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if only we had realized the usefulness of %r()%r for the MongoLog tests!

@bjori
Copy link
Contributor

bjori commented Aug 28, 2015

No mongos test?

lgtm

@derickr
Copy link
Contributor

derickr commented Sep 1, 2015

LGTM too, but have a look at that mongos test that @bjori mentions :-)

@jmikola
Copy link
Member Author

jmikola commented Sep 1, 2015

Created PHPC-402 to look into the shard cluster testing. We don't currently have a persistent cluster environment in the MO VM.

As it relates to this PR, I don't see any reason why it wouldn't return mongos connections, so I'll merge as-is and we'll follow this up in the other ticket.

@jmikola jmikola merged commit a2c88be into mongodb:master Sep 1, 2015
jmikola added a commit that referenced this pull request Sep 1, 2015
@jmikola jmikola deleted the phpc-361 branch September 1, 2015 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants