Skip to content

Conversation

@dazey3
Copy link
Contributor

@dazey3 dazey3 commented May 14, 2019

…DataRepository race condition

Signed-off-by: Will Dazey <dazeydev.3@gmail.com>
*/
Class<?>[] processRegisteredClasses(ClassLoader envLoader) {
if (_registered.isEmpty())
synchronized Class<?>[] processRegisteredClasses(ClassLoader envLoader) {
Copy link
Member

Choose a reason for hiding this comment

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

Any chance to avoid synchronization at method level?

Copy link
Contributor Author

@dazey3 dazey3 May 15, 2019

Choose a reason for hiding this comment

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

@ilgrosso I had written a possible implementation using read/write locks similar to my ValueMapDiscriminator impl, but so much of the code ended up being write locked that it almost seemed pointless to have that fine grained locking. Almost all the time, _registered is empty anyway, so little to no blocking will occur.
The issue really ends up being that all of processRegisteredClasses needs to block until it's done processing all of the classes out of the temporary array. I realize the temp array was added to reduce blocking on the _registered array in the first place, but that only opens a window for other threads to start initializing other caches WHILE the MetaDataRepository is still processing and building. If the ORM is sufficiently large (I was seeing this processing taking up to 700ms for my customer), it can stretch into application code as queries begin executing. During that time, reads are potentially dirty from MetaDataRepository._subs and we were seeing CNFE even though MetaDataRepository was STILL in the process of processing the class it threw a CNFE for.
That being said, if there is a strong performance concern from synchonizing the method (something that may not be as troubling nowadays with newer jdks), I can re-investigate implementing locks. This change was just infinitely cleaner and I have an interest for my customer to get this fixes as soon as possible.

Copy link
Member

Choose a reason for hiding this comment

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

@dazey3 I see: given what you say, method synchronization could be acceptable then - I was just wondering why...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ilgrosso I understand the concern and I appreciate all the review comments I can get! Thank you for taking a look.

@dazey3 dazey3 merged commit cd81d36 into apache:master May 16, 2019
@dazey3 dazey3 deleted the 2767_master branch May 16, 2019 18:42
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.

3 participants