Skip to content

Add support for colon separator of keyspace:shard#2685

Merged
michael-berlin merged 4 commits intovitessio:masterfrom
HubSpot:support_colon_for_target
Mar 27, 2017
Merged

Add support for colon separator of keyspace:shard#2685
michael-berlin merged 4 commits intovitessio:masterfrom
HubSpot:support_colon_for_target

Conversation

@bbeaudreault
Copy link
Copy Markdown
Contributor

}

func parseKeyspaceShard(param string) []string {
rp := regexp.MustCompile("[:/]")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

regexp is probably overkill for this. Given that this will be a high QPS call, prefer using https://golang.org/pkg/strings/#LastIndexAny instead.

@sougou
Copy link
Copy Markdown
Contributor

sougou commented Mar 27, 2017

We'll wait for @michael-berlin to look at this also.

@bbeaudreault
Copy link
Copy Markdown
Contributor Author

Thanks, I changed to LastIndexAny. I also removed the test which fails on a path with multiple slashes, because with LastIndexAny it's harder to determine that. Not sure how strict you want to be about that case. I can add it back and go a different route if you'd like

@bbeaudreault
Copy link
Copy Markdown
Contributor Author

@michael-berlin @sougou updated per conversation in slack

Copy link
Copy Markdown
Contributor

@michael-berlin michael-berlin left a comment

Choose a reason for hiding this comment

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

LGTM after my two comments are addressed.

// parseKeyspaceOptionalShard parses a "keyspace/shard" or "keyspace:shard" string
// and extracts the parts. If a shard is not specified, it's
// returned as empty string. We need to support : and / in vtgate because some clients
// can't support our default of slash. Everywhere else we only support /
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Missing period in the last sentence after /.

keyspace: "ks",
shard: "",
}, {
keyspaceShard: "/-80",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest that we remove the test cases where one of the parts is empty.

IMO this is outside of the "specification" and therefore the behaviour for such an input should not be defined. But by having it in the test, we're implicitly defining it and making it part of our "specification". For example, we may consider to error on this input in the future.

Therefore, I prefer if you delete this case and the cases ks/, ks: and :-80.

@bbeaudreault
Copy link
Copy Markdown
Contributor Author

@michael-berlin fixed up, thanks

@michael-berlin
Copy link
Copy Markdown
Contributor

Thanks! :)

@michael-berlin michael-berlin merged commit b54ac73 into vitessio:master Mar 27, 2017
@bbeaudreault bbeaudreault deleted the support_colon_for_target branch March 28, 2017 18:52
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.

4 participants