Skip to content

Allow setting key/value in a metadata stored in the topology#5103

Merged
tirsen merged 1 commit intovitessio:masterfrom
kalfonso:kalfonso.190814-set-vitess-metadata
Aug 28, 2019
Merged

Allow setting key/value in a metadata stored in the topology#5103
tirsen merged 1 commit intovitessio:masterfrom
kalfonso:kalfonso.190814-set-vitess-metadata

Conversation

@kalfonso
Copy link
Contributor

@kalfonso kalfonso commented Aug 16, 2019

This PR allows setting key/value metadata in the topology leveraging "set" & "show" SQL statements.

Signed-off-by: Karel Alfonso Sague kalfonso@squareup.com

@kalfonso
Copy link
Contributor Author

@sougou @demmer @tirsen this is an initial cut of using "SET" statement to manage metadata values. Looking for feedback on this. I've commented in the PR about alternative options to manage topology backed metadata

@kalfonso kalfonso force-pushed the kalfonso.190814-set-vitess-metadata branch 6 times, most recently from cdfdfac to aa73834 Compare August 20, 2019 05:58
@kalfonso kalfonso force-pushed the kalfonso.190814-set-vitess-metadata branch from aa73834 to d4f59c0 Compare August 21, 2019 04:12
@kalfonso kalfonso changed the title WIP: Allow setting key/value in a metadata stored in the topology Allow setting key/value in a metadata stored in the topology Aug 21, 2019
@kalfonso kalfonso force-pushed the kalfonso.190814-set-vitess-metadata branch from d4f59c0 to 99eb8b7 Compare August 21, 2019 05:54
@kalfonso kalfonso marked this pull request as ready for review August 21, 2019 05:54
@kalfonso kalfonso requested a review from sougou as a code owner August 21, 2019 05:54
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd add a little comment at the end like // Can never fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

Use a switch here now that you have >1 case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

Is testify not used in Vitess? :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems to be used only in one test go/vt/vtgate/engine/ordered_aggregate_test.go

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I just introduced it, and used it on the code I was working on at the time. You can and should definitely use it. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Used in the new tests

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd use len(metadata) as the capacity here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh I didn't know the variables keyword. I assume this is "standard"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, wanted to keep same syntax

SHOW [GLOBAL | SESSION] VARIABLES
    [LIKE 'pattern' | WHERE expr]

https://dev.mysql.com/doc/refman/8.0/en/show-variables.html

Copy link
Collaborator

Choose a reason for hiding this comment

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

You're still passing in the keyspace here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you're not using ksName?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

@kalfonso kalfonso force-pushed the kalfonso.190814-set-vitess-metadata branch 3 times, most recently from a8b2f6c to de15fda Compare August 23, 2019 03:37
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dweitzman I've made changes to use vschemaacl to authorize specific users to execute "set vitess_metadata" actions. This works for our current requirements but a separate PR will separate this into its own metadataacl definition. Trying to keeps this PR small

@kalfonso kalfonso force-pushed the kalfonso.190814-set-vitess-metadata branch from de15fda to a25abf2 Compare August 23, 2019 06:03
Copy link
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 this LGTM -- one minor comment but I'm happy with this syntax and approach.

Copy link
Member

Choose a reason for hiding this comment

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

Are we 100% sure this is a compatible conversion from the LIKE syntax to regexp? Itt's fine for this use case but if there's a more robust and generic way to do this, we might get some mileage out of making it a common function in the Vitess code base.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I found this link with examples of the LIKE syntax: https://www.w3schools.com/sql/sql_like.asp

I we also need to support _.

I agree that extracting a "LIKE to regexp" converter into a separate file and a more shared place and then writing specific unit tests for that would be nice. I'm not sure we need to make that 100% compliant in this PR though. We can iterate on that once we have it in a central place with a nice suite of unit tests.

Copy link
Member

Choose a reason for hiding this comment

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

Yep -- totally agree 100%

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracted functionality to separate file with unit tests. Also supporting '_' character and escaping using ""

@kalfonso kalfonso force-pushed the kalfonso.190814-set-vitess-metadata branch 3 times, most recently from 40b7aef to 3bc0486 Compare August 26, 2019 13:55
Signed-off-by: Karel Alfonso Sague <kalfonso@squareup.com>
@kalfonso kalfonso force-pushed the kalfonso.190814-set-vitess-metadata branch from 3bc0486 to 453d54b Compare August 26, 2019 14:26
@tirsen tirsen merged commit ad6099c into vitessio:master Aug 28, 2019
Copy link
Contributor

@sougou sougou left a comment

Choose a reason for hiding this comment

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

We also need the ability to delete metadata. How about we treat an empty value as a delete?

KeyspacesPath = "keyspaces"
ShardsPath = "shards"
TabletsPath = "tablets"
MetadataPath = "vitess_metadata"
Copy link
Contributor

Choose a reason for hiding this comment

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

Hope it's not too late. This should be just metadata, just like we didn't prefix the other paths with vitess_.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not too late. This is the path in zk right? Yes I agree this should be just metadata not vitess_metadata. The syntax should be SET @@vitess_metadata though just like all of our other SQL extensions. Right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. We don't want collisions in the variable name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed in this PR: #5141

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.

6 participants