-
Notifications
You must be signed in to change notification settings - Fork 54
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
Use a local keyword registry to make validate thread-safe #103
Conversation
Introduce a keyword registry struct so that most operations are not acting upon a global package variable. I have preserved existing behaviors (such as applying the default schema to the global keyword registry), and kept global functions such as RegistrKeyword. If breaking changes are allowed, then we could remove the locks and keyword registry copying which would simplify this patch quite a bit. Signed-off-by: Carolyn Van Slyck <[email protected]>
a1c05f4
to
b7bc812
Compare
Again, very appreciated. This will take a bit more time to review as I have to be more thorough with it and do some testing, but at a glance looks like a step in the right direction. |
@Arqu Just checking if you've had a chance to look at this and had any feedback? |
Sorry, been pretty booked for the past while. I'll aim to have a go at it within the next 10 days. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the patience, this is exceptional and brings us much closer to being fully thread safe. Before merging, if you could just address the golint issues
draft2019_09_keywords.go:14:1: exported method KeywordRegistry.DefaultIfEmpty should have comment or be unexported
keyword.go:31:6: exported type KeywordRegistry should have comment or be unexported
keyword.go:55:1: exported method KeywordRegistry.Copy should have comment or be unexported
And I'm happy to merge as is.
Signed-off-by: Carolyn Van Slyck <[email protected]>
4ede4ee
to
39ced0c
Compare
Oh great! I'm excited to not have to have a fork of jsonschema anymore! 🎉 I just pushed a fix for the golint errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you soo much for the work here, seems like this will help a lot of folks out!
The PR fixing thread safety when registering a custom keyword has been merged so I'm removing the fork and going back to using the upstream repository. See qri-io/jsonschema#103 Signed-off-by: Carolyn Van Slyck <[email protected]>
This makes validating a schema thread-safe. I was focused on fixing that call path specifically, and not addressing thread-safety throughout the entire code base, so there is may be more global variables being used elsewhere. This PR introduces a a struct to represent a keyword registry, and loading of the registry and validation occurs in instances of a keyword registry, avoiding the use of global package variables.
This is the patch that we have been using for https://github.com/getporter/porter for 6+ months to be able to validate a schema in a thread-safe manner when registering custom validators.
I was mostly interested in getting this to work without making any backwards incompatible changes to this library's existing API. For example, I kept the package level functions that manipulate package variables, such as
RegisterKeyword
, which requires the use of locks. If you are okay with making a breaking change, and removing global state, that would simplify the patch quite a bit.This is a fix for #80 , but is limited to validation. There are probably more spots that would need to be refactored as well.