Skip to content
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

Fix the race condition of reflection scanning classes #9167

Merged

Conversation

Jackie-Jiang
Copy link
Contributor

@Jackie-Jiang Jackie-Jiang commented Aug 4, 2022

In #5446, we introduced reflection lock to solve the race condition of reflection library scanning the same jar from multiple threads (more details can be found in #5531).
Some new added reflection-based modules (SegmentLoader, Tuner) didn't protect the reflection with lock. This PR enhances the PinotReflectionUtils to support more use cases, and move the new modules to use it.

Copy link
Contributor

@walterddr walterddr left a comment

Choose a reason for hiding this comment

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

lgtm

}
}

/**
* Due to the multi-threading issue in org.reflections.vfs.ZipDir, we need to put a lock before calling the
* reflection related methods.
*
* @return
*/
public static Object getReflectionLock() {
Copy link
Contributor

@walterddr walterddr Aug 4, 2022

Choose a reason for hiding this comment

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

This is no longer needed i think or change the synchronize block above to also acquire via this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed to wrap the setup of swagger. Added runWithLock() as @klsince suggested, and deprecated this one

}
}

/**
* Due to the multi-threading issue in org.reflections.vfs.ZipDir, we need to put a lock before calling the
* reflection related methods.
*
* @return
*/
public static Object getReflectionLock() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: instead of return lock, may do

runWithLock(Runnable r) {
 sync(lock) {
  r.run()
 }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

@Jackie-Jiang Jackie-Jiang force-pushed the fix_reflections_race_condition branch from 1882325 to ba9d4e4 Compare August 5, 2022 03:47
@codecov-commenter
Copy link

Codecov Report

Merging #9167 (ba9d4e4) into master (e8a8684) will decrease coverage by 0.02%.
The diff coverage is 62.74%.

@@             Coverage Diff              @@
##             master    #9167      +/-   ##
============================================
- Coverage     69.99%   69.97%   -0.03%     
- Complexity     4682     4757      +75     
============================================
  Files          1848     1847       -1     
  Lines         98572    98541      -31     
  Branches      14967    14963       -4     
============================================
- Hits          68999    68951      -48     
- Misses        24723    24753      +30     
+ Partials       4850     4837      -13     
Flag Coverage Δ
integration1 26.29% <31.37%> (-0.05%) ⬇️
integration2 24.78% <31.37%> (-0.03%) ⬇️
unittests1 67.02% <48.64%> (-0.01%) ⬇️
unittests2 15.34% <19.14%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...g/apache/pinot/spi/utils/PinotReflectionUtils.java 42.85% <38.70%> (-57.15%) ⬇️
...pinot/broker/broker/BrokerAdminApiApplication.java 89.13% <100.00%> (-0.46%) ⬇️
...apache/pinot/common/function/FunctionRegistry.java 87.50% <100.00%> (-1.39%) ⬇️
.../controller/api/ControllerAdminApiApplication.java 86.66% <100.00%> (-0.64%) ⬇️
...not/controller/tuner/TableConfigTunerRegistry.java 81.48% <100.00%> (-3.37%) ⬇️
...apache/pinot/minion/MinionAdminApiApplication.java 87.17% <100.00%> (-0.63%) ⬇️
...ent/spi/loader/SegmentDirectoryLoaderRegistry.java 76.92% <100.00%> (-2.39%) ⬇️
...inot/server/starter/helix/AdminApiApplication.java 84.74% <100.00%> (-0.51%) ⬇️
...a/org/apache/pinot/query/parser/QueryRewriter.java 0.00% <0.00%> (-100.00%) ⬇️
...data/manager/realtime/DefaultSegmentCommitter.java 0.00% <0.00%> (-80.00%) ⬇️
... and 34 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@Jackie-Jiang Jackie-Jiang merged commit 0aeb42e into apache:master Aug 5, 2022
@Jackie-Jiang Jackie-Jiang deleted the fix_reflections_race_condition branch August 5, 2022 08:17
@walterddr
Copy link
Contributor

we need to cherry-pick this back to release 0.11 branch

walterddr pushed a commit to walterddr/pinot that referenced this pull request Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants