Skip to content

Update tabletpicker to support cell pref and tablet order options#12282

Merged
rohit-nayak-ps merged 17 commits into
vitessio:mainfrom
slackhq:pbibra-refactor-tabletpicker
May 18, 2023
Merged

Update tabletpicker to support cell pref and tablet order options#12282
rohit-nayak-ps merged 17 commits into
vitessio:mainfrom
slackhq:pbibra-refactor-tabletpicker

Conversation

@pbibra

@pbibra pbibra commented Feb 8, 2023

Copy link
Copy Markdown
Contributor

Description

This PR adds options to the TabletPicker that allow for selecting cell preference in addition to changing default behavior to give priority to the local cell and any alias it belongs to. We are also introducing a new way to select tablet order which should eventually replace the in_order: hint currently included tabletTypesStr.

The following changes are made to the NewTabletPicker function signature (i.e. the TabletPicker's instantiation):

before:

func NewTabletPicker(ts *topo.Server, cells []string, keyspace, shard, tabletTypesStr string) (*TabletPicker, error) {

after:

func NewTabletPicker(
	ctx context.Context,
	ts *topo.Server,
	cells []string,
	localCell, keyspace, shard, tabletTypesStr string,
	options TabletPickerOptions,
) (*TabletPicker, error) {

Where ctx, localCell, option are all new parameters.

option is of type TabletPickerOptions and includes two fields, CellPref and TabletOrder.
CellPref -> "PreferLocalWithAlias" (default) or "OnlySpecified"
TabletOrder -> "Any" (default) or "InOrder"
The above are defined as enum strings.

The following illustrates the behavior with different option combinations. Assume the following setup:

localCell = us-east-1a
alias = region1 -> {us-east-1a, us-east-1b, us-east-1c}
`cells = {us-west-1a, us-west-1b}

tablets:

tablet-1-PRIMARY in us-east-1a
tablet-2-REPLICA in us-east-1a
tablet-3-PRIMARY in us-east-1b
tablet-4-REPLICA in us-east-1b
tablet-5-PRIMARY in us-west-1a
tablet-6-PRIMARY in us-west-1b
tablet-7-REPLICA in us-west-1b

When "PreferLocalWithAlias" is selected, localCell must be non-empty:

  1. With "Any" as the tablet order (or for backward compatibility the in order hint does not exist in the tabletTypeStr), the TabletPicker will first pick tablets in the localCell and subsequently pick tablets in any alias the local cell belongs to. Finally, it will pick tablets belonging to cells if any additional ones are specified. The tablet type in this scenario does not matter since "Any" was selected.

tabletTypeStr = REPLICA,PRIMARY
tablet priority possibility:

tablet-1-PRIMARY in us-east-1a
tablet-2-REPLICA in us-east-1a
tablet-3-PRIMARY in us-east-1b
tablet-4-REPLICA in us-east-1b
tablet-5-PRIMARY in us-west-1a
tablet-6-PRIMARY in us-west-1b
tablet-7-REPLICA in us-west-1b
  1. With "InOrder" as the tablet order (or for backward compatibility the in order hint exists in the tabletTypeStr), the TabletPicker will first pick tablets in the localCell that also respect the tablet type ordering and subsequently pick tablets in any alias the local cell belongs to with the tablet type order. Finally, it will pick tablets belonging to cells if any additional ones are specified. The tablet type in this scenario is respected within each grouping of tablets (i.e. local cell, alias, all others)

tabletTypeStr = in_order:REPLICA,PRIMARY
tablet priority possibility:

tablet-2-REPLICA in us-east-1a
tablet-1-PRIMARY in us-east-1a
tablet-4-REPLICA in us-east-1b
tablet-3-PRIMARY in us-east-1b
tablet-5-PRIMARY in us-west-1a 
tablet-7-REPLICA in us-west-1b
tablet-6-PRIMARY in us-west-1b

When "OnlySpecified" is selected as the cell preference:

  1. With "Any" as the tablet order (or for backward compatibility the in order hint does not exist in the tabletTypeStr), the TabletPicker will only pick tablets belonging to cells specified in the cells parameter. It will ignore tablet type ordering in this case.

tabletTypeStr = REPLICA,PRIMARY
tablet priority possibility:

tablet-6-PRIMARY in us-west-1b
tablet-7-REPLICA in us-west-1b
tablet-5-PRIMARY in us-west-1a 
  1. With "InOrder" as the tablet order (or for backward compatibility the in order hint exists in the tabletTypeStr), the TabletPicker will only pick tablets belonging to cells specified in the cells parameter, but will respect the tablet type ordering.

tabletTypeStr = in_order:REPLICA,PRIMARY
tablet priority possibility:

tablet-7-REPLICA in us-west-1b
tablet-6-PRIMARY in us-west-1b
tablet-5-PRIMARY in us-west-1a 

Related Issue(s)

Checklist

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
@vitess-bot

vitess-bot Bot commented Feb 8, 2023

Copy link
Copy Markdown
Contributor

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • If this is a change that users need to know about, please apply the release notes (needs details) label so that merging is blocked unless the summary release notes document is included.
  • If a test is added or modified, there should be a documentation on top of the test to explain what the expected behavior is what the test does.

If a new flag is being introduced:

  • Is it really necessary to add this flag?
  • Flag names should be clear and intuitive (as far as possible)
  • Help text should be descriptive.
  • Flag names should use dashes (-) as word separators rather than underscores (_).

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow should be required, the maintainer team should be notified.

Bug fixes

  • There should be at least one unit or end-to-end test.
  • The Pull Request description should include a link to an issue that describes the bug.

Non-trivial changes

  • There should be some code comments as to why things are implemented the way they are.

New/Existing features

  • Should be documented, either by modifying the existing documentation or creating new documentation.
  • New features should have a link to a feature request issue or an RFC that documents the use cases, corner cases and test cases.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • vtctl command output order should be stable and awk-able.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from VTop, if used there.

@vitess-bot vitess-bot Bot added NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says labels Feb 8, 2023
Signed-off-by: pbibra <pbibra@slack-corp.com>
@pbibra pbibra mentioned this pull request Feb 8, 2023
3 tasks
@rohit-nayak-ps rohit-nayak-ps added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: VReplication Component: TabletManager and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work labels Feb 8, 2023
@github-actions

Copy link
Copy Markdown
Contributor

This PR is being marked as stale because it has been open for 30 days with no activity. To rectify, you may do any of the following:

  • Push additional commits to the associated branch.
  • Remove the stale label.
  • Add a comment indicating why it is not stale.

If no action is taken within 7 days, this PR will be closed.

@github-actions github-actions Bot added the Stale Marks PRs as stale after a period of inactivity, which are then closed after a grace period. label Mar 11, 2023
@mattlord mattlord removed the Stale Marks PRs as stale after a period of inactivity, which are then closed after a grace period. label Mar 17, 2023
@mattlord mattlord self-assigned this Mar 17, 2023
@pbibra pbibra force-pushed the pbibra-refactor-tabletpicker branch 3 times, most recently from 278eabd to 799c5a6 Compare March 30, 2023 00:47
pbibra added 4 commits March 29, 2023 17:49
Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>
Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>
@mattlord mattlord removed the NeedsWebsiteDocsUpdate What it says label Apr 10, 2023
@pbibra pbibra marked this pull request as ready for review April 10, 2023 18:54
@mattlord mattlord changed the title [DRAFT] update tabletpicker to support cell pref and tablet order options Update tabletpicker to support cell pref and tablet order options Apr 10, 2023

@mattlord mattlord left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall it looks good! Mostly minor comments/suggestions.

Beyond that, I don't see where we've added any new unit or e2e tests for this new behavior (exists tests are using the equivalent of the old behavior). We should add unit tests for this new behavior and modify the e2e tests as well, at least to use the new default preference.

Comment thread changelog/17.0/17.0.0/summary.md Outdated
Comment thread changelog/17.0/17.0.0/summary.md Outdated
Comment thread changelog/17.0/17.0.0/summary.md Outdated
Comment thread changelog/17.0/17.0.0/summary.md Outdated
Comment thread go/vt/discovery/tablet_picker.go Outdated
Comment thread go/vt/discovery/tablet_picker.go Outdated
Comment thread go/vt/discovery/tablet_picker.go Outdated
Comment thread go/vt/discovery/tablet_picker.go Outdated
Comment thread go/vt/discovery/tablet_picker.go
Comment thread go/vt/discovery/tablet_picker.go
@pbibra

pbibra commented Apr 12, 2023

Copy link
Copy Markdown
Contributor Author

Overall it looks good! Mostly minor comments/suggestions.

Beyond that, I don't see where we've added any new unit or e2e tests for this new behavior (exists tests are using the equivalent of the old behavior). We should add unit tests for this new behavior and modify the e2e tests as well, at least to use the new default preference.

I did add some new unit tests in tablet_picker_test.go. Let me know if those look good! Good call out on the e2e tests though, I can look at adding some new ones there as well.

pbibra added 2 commits April 12, 2023 16:06
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>
Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>
@mattlord mattlord self-requested a review April 26, 2023 18:45

@mattlord mattlord left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is looking great, @pbibra! I have some minor comments that I think we can address pretty quickly. Please let m know if any of them are unclear. ❤️


- **[Major Changes](#major-changes)**
- **[Breaking Changes](#breaking-changes)**
- [Default Local Cell Preference for TabletPicker](#tablet-picker-cell-preference)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this needs to be in breaking changes. But I guess it doesn't hurt to increase awareness just in case we're missing some breaking case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I figured since we're changing default behavior it's good to advertise that? Let me know if there's another better place to do that

Comment thread go/vt/discovery/tablet_picker.go Outdated
Comment thread go/vt/discovery/tablet_picker.go Outdated
Comment thread go/vt/discovery/tablet_picker.go Outdated
Comment thread go/vt/discovery/tablet_picker.go Outdated
Comment thread go/vt/discovery/tablet_picker_test.go Outdated
Comment thread go/vt/discovery/tablet_picker_test.go Outdated
_, err = tp.PickForStreaming(ctx)
require.EqualError(t, err, "context has expired")
// if local preference is selected, tp cells include's the local cell's alias
require.Greater(t, globalTPStats.noTabletFoundError.Counts()["cell_cella.ks.0.replica"], int64(0))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And we assume in this case that we then use the alias?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes

Comment thread go/vt/discovery/tablet_picker_test.go Outdated
Comment on lines +451 to +469
tp, err := NewTabletPicker(context.Background(), te.topoServ, te.cells, "cell", te.keyspace, te.shard, "replica", TabletPickerOptions{CellPreference: "OnlySpecified"})
require.NoError(t, err)
delay := GetTabletPickerRetryDelay()
defer func() {
SetTabletPickerRetryDelay(delay)
}()
SetTabletPickerRetryDelay(11 * time.Millisecond)

ctx, cancel := context.WithTimeout(context.Background(), 20*time.Millisecond)
defer cancel()
// no tablets
_, err = tp.PickForStreaming(ctx)
require.EqualError(t, err, "context has expired")
// no tablets of the correct type
defer deleteTablet(t, te, addTablet(te, 200, topodatapb.TabletType_RDONLY, "cell", true, true))
ctx, cancel = context.WithTimeout(context.Background(), 20*time.Millisecond)
defer cancel()
_, err = tp.PickForStreaming(ctx)
require.EqualError(t, err, "context has expired")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's not obvious to me how we're testing OnlySpecified here? Am I missing something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is showing that if the OnlySpecified option is passed into the tablet picker, but no tablet exists of that specified type, then picker cannot select a tablet

pbibra added 4 commits April 30, 2023 18:43
Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: pbibra <pbibra@slack-corp.com>
Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
@mattlord mattlord removed the request for review from rsajwani May 1, 2023 15:01
pbibra added 3 commits May 1, 2023 16:32
Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>
@mattlord mattlord self-requested a review May 8, 2023 14:58

@mattlord mattlord left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! Thank you for all of the time you put into this, @pbibra !

@rohit-nayak-ps rohit-nayak-ps left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work! Thanks for this very useful contribution.

@rohit-nayak-ps rohit-nayak-ps merged commit 2dd3853 into vitessio:main May 18, 2023
DeathBorn pushed a commit to vinted/vitess that referenced this pull request Apr 11, 2024
…tessio#12282)

* update tabletpicker to support cell pref and tablet order options

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* add tablet picker options in vstream flags

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* add tablet picker tests

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* add summary docs

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* update proto

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>

* fix vreplication test

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>

* fix doc typos, add function comments, update error handling

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>

* fix tests and comments

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* fix local cell ref

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* update proto

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* add log line to debug test

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* add cell to vre test def

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* define vrepl engine for controller tests

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>

---------

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: pbibra <pbibra@slack-corp.com>
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>
Signed-off-by: Vilius Okockis <vilius.okockis@vinted.com>
DeathBorn pushed a commit to vinted/vitess that referenced this pull request Apr 12, 2024
…tessio#12282)

* update tabletpicker to support cell pref and tablet order options

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* add tablet picker options in vstream flags

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* add tablet picker tests

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* add summary docs

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* update proto

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>

* fix vreplication test

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>

* fix doc typos, add function comments, update error handling

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>

* fix tests and comments

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* fix local cell ref

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* update proto

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* add log line to debug test

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* add cell to vre test def

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* define vrepl engine for controller tests

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>

---------

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: pbibra <pbibra@slack-corp.com>
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>
Signed-off-by: Vilius Okockis <vilius.okockis@vinted.com>
@timvaillancourt timvaillancourt deleted the pbibra-refactor-tabletpicker branch May 29, 2024 00:23
timvaillancourt pushed a commit to slackhq/vitess that referenced this pull request May 29, 2024
…tessio#12282)

* update tabletpicker to support cell pref and tablet order options

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* add tablet picker options in vstream flags

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* add tablet picker tests

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* add summary docs

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* update proto

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>

* fix vreplication test

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>

* fix doc typos, add function comments, update error handling

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>

* fix tests and comments

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* fix local cell ref

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* update proto

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* add log line to debug test

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* add cell to vre test def

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>

* define vrepl engine for controller tests

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>

---------

Signed-off-by: Priya Bibra <pbibra@slack-corp.com>
Signed-off-by: pbibra <pbibra@slack-corp.com>
Signed-off-by: 'Priya Bibra' <pbibra@slack-corp.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: TabletManager Component: VReplication Type: Enhancement Logical improvement (somewhere between a bug and feature)

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

Feature Request: Add fallback to VTGate cell alias for VStreams with local cell preference

3 participants