Skip to content

router: protect replicasets from modification #580

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sergepetrenko
Copy link
Contributor

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=

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=<undocumented part>
@sergepetrenko sergepetrenko force-pushed the gh-502-protect-replicaset-from-modification branch from 5aaf32d to 3e0f75f Compare August 8, 2025 15:10
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.

router: protect routeall() and others from modification
2 participants