Closed serejja closed 8 years ago
It makes sense from reading your PR - interestingly I can't get the data race to trigger on OSX/x64 - could be luck or it could be an OSX specific deal. But I think it does make sense to put locks around the map for safety.
I think long term, there's actually a better situation we can end up with which involves less locking... or at minimum more granular locking. It's something I mentioned in my third point of this comment - the ability for the user to tell the library to 'compile' the schema and then on the compiled schema perform all optimizations, because at that point the schema is now immutable and you can compute optimized bits (like enum type maps) without worrying the user can change the value or using some special attribute like the enum's name which is not guaranteed to be unique. Also many things can be compiled in advance without locking.
I have prototyped it here: https://github.com/crast/avro/commit/immutable-schema but it doesn't have enough tests so I haven't submitted a PR yet.
Cool, I've taken a look at your changes and definitely makes sense to me, willing to try it out and merge once you post a PR :)
Thanks!
Yea, I like testify and thought of rewriting existing tests using testify too
Existing reflectMap in datum_utils yields data races when run with
-race
flag.This PR introduces RWMutex to allow for multiple readers when the reflectMap is just being read, but locks exclusively on updates.
@crast would like to hear your opinion on this. You added this optimization some time ago but the situation here is quite similar to #69