router: protect replicasets from modification #580
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The function vshard.router.routeall is not marked as internal API, but it returns router.replicasets table, which is used by the router itself. And also vshard.router.route returns a replicaset object that is used internally. If user modifies the returned from routeall or route table, then router is broken and cannot continue to work properly after that.
Now routeall returns a new copy of the replicaset array to user on each call. So user can do whatever he wants with this array, without affecting the internal behavior of the router.
Also, each of the replicasets that are returned from routeall or route is a wrapper over the internal replicaset table. This wrapper contains the private field _replicaset, the value of which is the internal replicaset table. User should not touch this field. This wrapper only gives user access to the public replicaset methods: call, callrw, callro, callbro, callre, callbre.
Closes #502
NO_DOC=