Skip to content

[closes #4378] Add keyspace visibility filtering to vtgates#4420

Merged
demmer merged 14 commits intovitessio:masterfrom
tinyspeck:setassociative-#4378-add-keyspace-filtering
Dec 14, 2018
Merged

[closes #4378] Add keyspace visibility filtering to vtgates#4420
demmer merged 14 commits intovitessio:masterfrom
tinyspeck:setassociative-#4378-add-keyspace-filtering

Conversation

@setassociative
Copy link
Copy Markdown

@setassociative setassociative commented Dec 4, 2018

Closes #4378

Summary

This was added in order to support running up a vtgate within a cell that has a limited access to the keyspaces inside that cell. A new flag was introduced instead of modifying the existing tablet_filters behavior because bringing along the |<shard-or-keyrange> syntax didn't make sense based on the desired behavior. tablet_filters and keyspaces_to_watch were made mutually exclusive to prevent situations where the flags required different keyspaces which would have suggested a non-obvious behavior (or had to fail anyway).

Implementation

  1. Introduce a new filtering srvtopo.Server implementation that removes unwatched keyspaces from its results
  2. This new filtering server does not expose access to its supporting topo.Server to prevent corrupting global SrvVSchema (c.f. this explainer from @demmer)
  3. Updates callsites for GetSrvTopo to handle the error coming back

It additionally comes with a super thin implementation of a srvtopo.Server for tests.

Open Questions

With GetTopoServer now returning an error I updated vschema_manager.go to cache a single reference to the topo server instead of getting a new one on each use to minimize error handling.

In theory this could be problematic if the server pointer changes during this call but I wasn't able to identify any code that does that (and the get call isn't synchronized so it seems super unlikely).

Testing

Automated: Unit tests for the new filtering srvtopo.Server impl, vagrant-scriptsh/test.sh passes

Manual:

Using the vagrant setup I spun up a cluster with:

2 keyspaces: aaa_keyspace, test_keyspace
10 vttablets: 5 fronting each keyspace
1 vtgate, 1vtctld

  • when not watching a specific keyspace mysql cli showed both keyspaces on show vitess_keyspaces
  • when keyspaces_to_watch=test_keyspace was set only test_keyspace was returned for show vitess_keyspaces; select now() from dual; was functional

Richard Bailey added 2 commits December 4, 2018 14:28
### Summary
This was added in order to support spining up a vtgate within a cell that
has a limited access to the keyspaces inside that cell. It was added instead
of modifying the existing `filter_tablets` behavior because bringing in the
`|<shard-or-keyrange>` syntax didn't make sense based on the desired behavior.
`filter_tablets` and `keyspaces_to_watch` were made mutually exclusive to
prevent situations where the flags required different keyspaces which would
have implied a non-obvious behavior (or had to fail anyway).

Implementation was relatively straight-forward: I added a new srvtopo.Server
that can filter the keyspaces returned and passed to the callback for
WatchSrvVSchema as well as tests. If a call is made to get the underlying
topo.Server is returned, e.g., calls to a server Conn's ListDir will not be
have any filtering applied.

### Testing

Automated: Unit tests for the new filtering `srvtopo.Server` impl

Manual:

Using the vagrant setup I spun up a cluster with:

2 keyspaces: aaa_keyspace, test_keyspace
10 vttablets: 5 fronting each keyspace
1 vtgate, 1vtctld

- when not watching a specific keyspace showed both keyspaces on `show vitess_keyspaces`
- when `keyspaces_to_watch=test_keyspace` was set only `test_keyspace` was returned for `show vitess_keyspaces`; `select now() from dual;` was functional

Signed-off-by: Richard Bailey <rbailey@slack-corp.com>
Signed-off-by: Richard Bailey <rbailey@slack-corp.com>
Richard Bailey added 2 commits December 4, 2018 15:44
Signed-off-by: Richard Bailey <rbailey@slack-corp.com>
…gate.go.

Signed-off-by: Richard Bailey <rbailey@slack-corp.com>
Copy link
Copy Markdown
Member

@demmer demmer left a comment

Choose a reason for hiding this comment

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

Overall looking good -- some suggestions on naming and organization and maybe a better approach to testing

Richard Bailey added 2 commits December 5, 2018 18:38
Signed-off-by: Richard Bailey <rbailey@slack-corp.com>
@setassociative setassociative force-pushed the setassociative-#4378-add-keyspace-filtering branch from f3de7be to 950de57 Compare December 7, 2018 02:25
…ssthrough

Signed-off-by: Richard Bailey <rbailey@slack-corp.com>
@setassociative setassociative force-pushed the setassociative-#4378-add-keyspace-filtering branch from 950de57 to 461e7a0 Compare December 7, 2018 02:26
Signed-off-by: Richard Bailey <rbailey@slack-corp.com>
…at instead of real code so that tests are easier to reason about

Signed-off-by: Richard Bailey <rbailey@slack-corp.com>
@setassociative setassociative force-pushed the setassociative-#4378-add-keyspace-filtering branch from c85e082 to 744c6b5 Compare December 7, 2018 21:16
stop using init in filtering server test

Signed-off-by: Richard Bailey <rbailey@slack-corp.com>
Copy link
Copy Markdown
Member

@demmer demmer left a comment

Choose a reason for hiding this comment

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

Looking good overall - just the minor cleanup and one slightly more substantive change that I mentioned.

Richard Bailey added 4 commits December 13, 2018 13:03
…server.

tl;dr is that the TopoServer is only used for vschema updates but also assumes that it has a full copy of the vschema so using it like that would result in losing other keyspaces.

A full explanation as to why is in vitessio#4420 (comment)


Signed-off-by: Richard Bailey <rbailey@slack-corp.com>
…te being attached to a generic accessor function

Signed-off-by: Richard Bailey <rbailey@slack-corp.com>
Signed-off-by: Richard Bailey <rbailey@slack-corp.com>
Signed-off-by: Richard Bailey <rbailey@slack-corp.com>
@setassociative setassociative force-pushed the setassociative-#4378-add-keyspace-filtering branch from 9de060f to a72b957 Compare December 13, 2018 21:52
@setassociative
Copy link
Copy Markdown
Author

setassociative commented Dec 13, 2018

Pending CI passing this should be good to review again. I updated the summary to reflect the actual state of the change.

Copy link
Copy Markdown
Member

@demmer demmer left a comment

Choose a reason for hiding this comment

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

LGTM! Nice work

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.

2 participants