-
Notifications
You must be signed in to change notification settings - Fork 590
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(iceberg): fix jni context class loader #17478
Conversation
I am thinking that shall we instead always set the context loader after we do attach_current_thread of jni? |
It depends on whether the method needs to use |
Java libraries usually assume that the class loader is correctly set. So I think we'd better just always set the class loader when we do |
Sounds good. Do you have any idea how to implement it? |
We can unify all our call to
|
…ss_loader_for_jni_catalog
@wenym1 I finished the refactoring, PTAL again. |
// set context class loader for the thread | ||
// java.lang.Thread.currentThread() | ||
// .setContextClassLoader(java.lang.ClassLoader.getSystemClassLoader()); | ||
|
||
let thread = crate::call_static_method!( | ||
env, | ||
{Thread}, | ||
{Thread currentThread()} | ||
)?; | ||
|
||
let system_class_loader = crate::call_static_method!( | ||
env, | ||
{ClassLoader}, | ||
{ClassLoader getSystemClassLoader()} | ||
)?; | ||
|
||
crate::call_method!( | ||
env, | ||
thread, | ||
{void setContextClassLoader(ClassLoader)}, | ||
&system_class_loader | ||
)?; |
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.
java.lang.Thread.currentThread().setContextClassLoader(java.lang.ClassLoader.getSystemClassLoader());
would be called once after attaching a thread to jvm successfully and any jni related codes should be wrapped in execute_with_jni_env
.
if let Err(e) = result { | ||
let _ = response_tx.blocking_send(Err(e)); | ||
} |
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.
@wenym1 Do I correctly handle the error in this case?
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.
LGTM
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.
All tests are passed. LGTM
if let Err(e) = result { | ||
let _ = response_tx.blocking_send(Err(e)); | ||
} |
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.
LGTM
let mut env = jvm.get_env().with_context(|| "Failed to get jni env")?; | ||
// set context class loader for the thread | ||
// java.lang.Thread.currentThread() | ||
// .setContextClassLoader(java.lang.ClassLoader.getSystemClassLoader()); |
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.
dead code?
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.
This is the equivalent java code, I think it's for reference purpose.
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.
LGTM
I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
What's changed and what's your intention?
Checklist
./risedev check
(or alias,./risedev c
)Documentation
Release note
If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.