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

Make sure ufs to only once load a native shared library #14058

Open
wants to merge 4 commits into
base: master-2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ public List<T> findAllWithRecorder(String path, S conf, Recorder recorder) {
}

List<T> factories = new ArrayList<>(mFactories);
List<T> eligibleFactories = select(path, conf, factories);
Copy link
Contributor

Choose a reason for hiding this comment

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

You mean the first time findAll invoked, the mFactories should be empty, and this method will run like original logic, later new findAll will not load the extension or lib jar at all? So please show the effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean the first time findAll invoked, the mFactories should be empty, and this method will run like original logic, later new findAll will not load the extension or lib jar at all? So please show the effect.

Yes, the new 'findAll' will not dynamicly load the ext or lib jar after the first load done. However, we can restart the alluxio master or worker to load the new updated jar.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please highlight add this important limitation to the related issue or the description of this PR. It would be better if you write an approach description shortly to let reviewer know your solution and make it easy to review this PR

if (!eligibleFactories.isEmpty()) {
return eligibleFactories;
}

factories.clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't understand why we can prevent loading native shared lib multiple times by calling clear here.
can you elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i don't understand why we can prevent loading native shared lib multiple times by calling clear here.
can you elaborate?

At this line, we did not find any supported factories from the list of factories. So we clear it to avoid to twicely check them wether support or not.

String libDir = PathUtils.concatPath(conf.getString(PropertyKey.HOME), "lib");
String extensionDir = conf.getString(PropertyKey.EXTENSIONS_DIR);
scanLibs(factories, libDir);
Expand All @@ -159,6 +165,7 @@ public List<T> findAllWithRecorder(String path, S conf, Recorder recorder) {
recorder.record("alluxio.underfs.version is not set by user");
}

eligibleFactories = select(path, conf, factories);
for (T factory : factories) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is select duplicate with the following for loop

// if `getVersion` returns null set the version to "unknown"
String version = UNKNOWN_VERSION;
Expand All @@ -178,6 +185,7 @@ public List<T> findAllWithRecorder(String path, S conf, Recorder recorder) {
+ "isn't eligible for path {}", factory.getClass().getSimpleName(), version, path);
}
}

if (eligibleFactories.isEmpty()) {
String message = String.format("No factory implementation supports the path %s", path);
recorder.record(message);
Expand Down Expand Up @@ -320,4 +328,25 @@ private void unregister(T factory, List<T> factories) {
LOG.debug("Unregistered factory implementation {} - {}", factory.getClass(), factory);
factories.remove(factory);
}

/**
* Selects all the factories that support the given path from the given list of factories.
*
* @param path path
* @param conf configuration of the extension
* @param factories list of factories
* @return list of factories that support the given path which may be an empty list
*/
private List<T> select(String path, S conf, List<T> factories) {
Preconditions.checkNotNull(path, "path may not be null");

List<T> eligibleFactories = new ArrayList<>();
for (T factory : factories) {
if (factory.supportsPath(path, conf)) {
LOG.debug("Factory implementation {} is eligible for path {}", factory, path);
eligibleFactories.add(factory);
}
}
return eligibleFactories;
}
}
1 change: 0 additions & 1 deletion underfs/cephfs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<groupId>io.github.opendataio</groupId>
<artifactId>libcephfs</artifactId>
<version>0.0.1</version>
<scope>provided</scope>
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the purpose you remove the provided scope, you want to include the libcephfs and related share lib into the ufs shaded with dependencies jar?

Copy link
Contributor Author

@jhonxue jhonxue Sep 22, 2021

Choose a reason for hiding this comment

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

What's the purpose you remove the provided scope, you want to include the libcephfs and related share lib into the ufs shaded with dependencies jar?

Yes, this pr will solve the problem about the libcephfs_jni.so is already loaded in another classloader, so libcephfs can be included.

</dependency>

<!-- Internal dependencies -->
Expand Down