nodece commented on code in PR #4738:
URL: https://github.com/apache/bookkeeper/pull/4738#discussion_r3055168622


##########
native-io/src/main/java/org/apache/bookkeeper/common/util/nativeio/NativeIOLibraryPath.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.bookkeeper.common.util.nativeio;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import org.apache.commons.lang3.SystemUtils;
+
+/**
+ * Resolves the path of the native-io shared library inside the JAR.
+ *
+ * <p>The {@code cargo-zigbuild} Maven profile embeds two variants:
+ * <pre>
+ *   lib/rust/linux-x86_64-gnu/libnative-io.so   (glibc, amd64)
+ *   lib/rust/linux-aarch64-gnu/libnative-io.so  (glibc, arm64)
+ * </pre>
+ *
+ * <p>An explicit override path can be set via the system property
+ * {@code bookkeeper.native.io.library.path} or the environment variable
+ * {@code BOOKKEEPER_NATIVE_IO_LIBRARY_PATH}.
+ */
+final class NativeIOLibraryPath {
+
+    static final String LIBRARY_PATH_ENV = "BOOKKEEPER_NATIVE_IO_LIBRARY_PATH";
+    static final String LIBRARY_PATH_PROPERTY = 
"bookkeeper.native.io.library.path";
+
+    private NativeIOLibraryPath() {
+    }
+
+    /**
+     * Returns an explicit path from system property / env, or {@code null}.
+     */
+    static String configuredLibraryPath() {
+        return configuredLibraryPath(
+                System.getProperty(LIBRARY_PATH_PROPERTY),
+                System.getenv(LIBRARY_PATH_ENV));
+    }
+
+    static String configuredLibraryPath(String propertyValue, String envValue) 
{
+        String v = trimToNull(propertyValue);
+        return v != null ? v : trimToNull(envValue);
+    }
+
+    /**
+     * Returns the ordered list of JAR-resource paths to try for the current
+     * platform and architecture. The first path that successfully loads wins.
+     */
+    static List<String> currentPlatformLibraryCandidates() {
+        return buildCandidates(
+                SystemUtils.IS_OS_LINUX,
+                System.getProperty("os.name"),
+                System.getProperty("os.arch"));
+    }
+
+    static List<String> libraryCandidates(String osName, String osArch) {
+        return buildCandidates(SystemUtils.IS_OS_LINUX, osName, osArch);
+    }
+
+    private static List<String> buildCandidates(boolean isLinux, String 
osName, String osArch) {
+        List<String> paths = new ArrayList<>();
+        if (isLinux) {
+            addLinuxCandidates(paths, osArch);
+        } else {
+            throw new IllegalStateException("OS not supported by Native-IO 
utils: " + osName);
+        }

Review Comment:
   Native IO only works fine on Linux.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to