-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
NIFI-7825: Support native library loading via absolute path #4540
Conversation
dce824d
to
e6e655f
Compare
# It is needed when a custom jar (eg. JDBC driver) has been configured on a component in the flow and this custom jar depends on a native library | ||
# and tries to load it by its absolute path (java.lang.System.load(String filename) method call). | ||
# Use this Java Agent only if you get "Native Library ... already loaded in another classloader" errors otherwise! | ||
#java.arg.18=-javaagent:./lib/aspectjweaver-${aspectj.version}.jar |
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.
Do we have any concerns about aspectjweaver being directly in the lib directory which puts in on the classpath of every single NAR? Wondering if it should be separated like lib/aspectj/
which would not be added to NiFi's normal classpath, but I don't know enough to say if it still works correctly then.
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.
The agent does not require aspectjweaver.jar
on the classpath so lib/aspectj
directory could work.
If there are concerns about having this jar on the system classpath, I can try out that solution too.
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.
I think if we can do the lib/aspectj
approach then that is the best option, anything we can do to avoid introducing additional dependencies to the system classpath is good.
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.
I double checked it and unfortunately the aspect class in nifi-nar-utils.jar
depends on aspectjrt.jar
.
As nifi-nar-utils.jar
is located in the lib folder and loaded by the system classloader, aspectjrt.jar
must be on the system classpath too.
And I did not want to separate the 2 AspectJ jars so I put aspectjweaver.jar
to the lib folder.
Options:
- leave it as it is now (both
aspectjrt.jar
andaspectjweaver.jar
in thelib
folder) - leave
aspectjrt.jar
inlib
and moveaspectjweaver.jar
tolib/aspectj
- find another place for the aspect class and move its
aspectjrt.jar
dependency there, moveaspectjweaver.jar
tolib/aspectj
Option 2 seems to me a bit weird structure and one of the AspectJ jars is still on the system classpath.
Option 3 could work but I would keep the native library loading stuff (AbstractNativeLibHandlingClassLoader
and LoadNativeLibAspect
) in the same module.
So I would still vote for option 1.
These jars have no effect if they are not referenced in our code / the agent is not turned on.
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.
Well it does have an effect... If the jars are in lib then they are on the classpath of every NAR, so if someone makes a custom NAR that bundles a different version of aspectj, then there will be two versions on the classpath, and there is nothing the NAR can do to avoid the one in lib.
I would actually vote for option 3... create a new module like nifi-nar-aspect-utils
or whatever we want to call it, and put the dependency there along with LoadNativeLibAspect
, then lib/aspectj
can contain nifi-nar-aspect-utils
jar and the aspectj jars. Would that work?
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.
It has been revealed that aspectjrt
does not needed at runtime, only aspectjweaver
(which is loaded directly by the agent, not from classpath).
So I removed aspectjrt.ajr
from lib
and moved aspectjweaver.jar
to lib/aspectj
subdirectory.
In this way, there are no AspectJ libraries on the system classpath by default (when the agent is turned off).
When the agent is turned on, it is being loaded by the system classloader (even if aspectjweaver.jar
is not on the system classpath). So there might be collision between different versions in this case. I believe it is acceptable because only the "agent turned on" case affected.
Use an AspectJ aspect and agent to intercept the load native library calls at runtime, copy the native library file to temp folder and proceed with the newly created file in order to provide classloader isolation.
… jar to lib/aspectj subdirectory.
Latest changes look good, thanks! Will merge |
Use an AspectJ aspect and agent to intercept the load native library calls at runtime, copy the native library file to temp folder and proceed with the newly created file in order to provide classloader isolation. Remove AspectJ jars from lib directory, move the necessary jar to lib/aspectj subdirectory. This closes apache#4540. Signed-off-by: Bryan Bende <bbende@apache.org>
Use an AspectJ aspect and agent to intercept the load native library calls at runtime, copy the native library file to temp folder and proceed with the newly created file in order to provide classloader isolation. Remove AspectJ jars from lib directory, move the necessary jar to lib/aspectj subdirectory. This closes apache#4540. Signed-off-by: Bryan Bende <bbende@apache.org>
Use an AspectJ aspect and agent to intercept the load native library calls at runtime, copy the native library file to temp folder and proceed with the newly created file in order to provide classloader isolation. Remove AspectJ jars from lib directory, move the necessary jar to lib/aspectj subdirectory. This closes apache#4540. Signed-off-by: Bryan Bende <bbende@apache.org> (cherry picked from commit 3dd024f)
Use an AspectJ aspect and agent to intercept the load native library calls at runtime, copy the native library file to temp folder and proceed with the newly created file in order to provide classloader isolation. Remove AspectJ jars from lib directory, move the necessary jar to lib/aspectj subdirectory. This closes apache#4540. Signed-off-by: Bryan Bende <bbende@apache.org>
Use an AspectJ aspect and agent to intercept the load native library calls
at runtime, copy the native library file to temp folder and proceed with
the newly created file in order to provide classloader isolation.
https://issues.apache.org/jira/browse/NIFI-7825
Thank you for submitting a contribution to Apache NiFi.
Please provide a short description of the PR here:
Description of PR
Enables X functionality; fixes bug NIFI-YYYY.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
For all changes:
Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
Has your PR been rebased against the latest commit within the target branch (typically
main
)?Is your initial contribution a single, squashed commit? Additional commits in response to PR reviewer feedback should be made on this branch and pushed to allow change tracking. Do not
squash
or use--force
when pushing to allow for clean monitoring of changes.For code changes:
mvn -Pcontrib-check clean install
at the rootnifi
folder?LICENSE
file, including the mainLICENSE
file undernifi-assembly
?NOTICE
file, including the mainNOTICE
file found undernifi-assembly
?.displayName
in addition to .name (programmatic access) for each of the new properties?For documentation related changes:
Note:
Please ensure that once the PR is submitted, you check GitHub Actions CI for build issues and submit an update to your PR as soon as possible.