This is an automated email from the ASF dual-hosted git repository.
richox pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/auron.git
The following commit(s) were added to refs/heads/master by this push:
new 58fa81fc [AURON #1602] Implement AuronAdaptor SPI discovery with Spark
provider (#1620)
58fa81fc is described below
commit 58fa81fcea550fa8070ee72e04a0d40cf448d849
Author: Thomas <[email protected]>
AuthorDate: Tue Nov 18 16:38:25 2025 +0800
[AURON #1602] Implement AuronAdaptor SPI discovery with Spark provider
(#1620)
---
.../java/org/apache/auron/jni/AuronAdaptor.java | 28 ++++++++++++----------
.../org/apache/auron/jni/AuronAdaptorProvider.java | 21 ++++++++++++++++
.../org/apache/auron/jni/AuronAdaptorTest.java | 13 ++++++----
.../apache/auron/jni/MockAuronAdaptorProvider.java | 24 +++++++++++++++++++
.../org.apache.auron.jni.AuronAdaptorProvider | 17 +++++++++++++
.../auron/jni/SparkAuronAdaptorProvider.java | 24 +++++++++++++++++++
.../org.apache.auron.jni.AuronAdaptorProvider | 17 +++++++++++++
.../scala/org/apache/spark/sql/auron/Shims.scala | 2 --
8 files changed, 128 insertions(+), 18 deletions(-)
diff --git a/auron-core/src/main/java/org/apache/auron/jni/AuronAdaptor.java
b/auron-core/src/main/java/org/apache/auron/jni/AuronAdaptor.java
index 07326670..463fb727 100644
--- a/auron-core/src/main/java/org/apache/auron/jni/AuronAdaptor.java
+++ b/auron-core/src/main/java/org/apache/auron/jni/AuronAdaptor.java
@@ -18,6 +18,7 @@ package org.apache.auron.jni;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.util.ServiceLoader;
import org.apache.auron.configuration.AuronConfiguration;
import org.apache.auron.functions.AuronUDFWrapperContext;
import org.apache.auron.memory.OnHeapSpillManager;
@@ -31,18 +32,7 @@ public abstract class AuronAdaptor {
/**
* The static instance of the AuronAdaptor.
*/
- private static AuronAdaptor INSTANCE = null;
-
- /**
- * Initializes a static instance of the AuronAdaptor.
- *
- * @param auronAdaptor The implementation of AuronAdaptor to be set as the
static instance.
- */
- public static synchronized void initInstance(AuronAdaptor auronAdaptor) {
- if (INSTANCE == null) {
- INSTANCE = auronAdaptor;
- }
- }
+ private static volatile AuronAdaptor INSTANCE = null;
/**
* Retrieves the static instance of the AuronAdaptor.
@@ -50,6 +40,20 @@ public abstract class AuronAdaptor {
* @return The current AuronAdaptor instance, or null if none has been set.
*/
public static AuronAdaptor getInstance() {
+ if (INSTANCE == null) {
+ synchronized (AuronAdaptor.class) {
+ if (INSTANCE == null) {
+ ServiceLoader<AuronAdaptorProvider> loader =
ServiceLoader.load(AuronAdaptorProvider.class);
+ for (AuronAdaptorProvider p : loader) {
+ INSTANCE = p.create();
+ break;
+ }
+ if (INSTANCE == null) {
+ throw new IllegalStateException("No
AuronAdaptorProvider found");
+ }
+ }
+ }
+ }
return INSTANCE;
}
diff --git
a/auron-core/src/main/java/org/apache/auron/jni/AuronAdaptorProvider.java
b/auron-core/src/main/java/org/apache/auron/jni/AuronAdaptorProvider.java
new file mode 100644
index 00000000..3abfbee1
--- /dev/null
+++ b/auron-core/src/main/java/org/apache/auron/jni/AuronAdaptorProvider.java
@@ -0,0 +1,21 @@
+/*
+ * 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.auron.jni;
+
+public interface AuronAdaptorProvider {
+ AuronAdaptor create();
+}
diff --git
a/auron-core/src/test/java/org/apache/auron/jni/AuronAdaptorTest.java
b/auron-core/src/test/java/org/apache/auron/jni/AuronAdaptorTest.java
index 90438acd..edf317c1 100644
--- a/auron-core/src/test/java/org/apache/auron/jni/AuronAdaptorTest.java
+++ b/auron-core/src/test/java/org/apache/auron/jni/AuronAdaptorTest.java
@@ -17,6 +17,7 @@
package org.apache.auron.jni;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.apache.auron.configuration.AuronConfiguration;
@@ -30,12 +31,16 @@ public class AuronAdaptorTest {
@Test
public void testRetrieveConfigWithAuronAdaptor() {
MockAuronAdaptor auronAdaptor = new MockAuronAdaptor();
- AuronAdaptor.initInstance(auronAdaptor);
- AuronAdaptor.getInstance().loadAuronLib();
- assertNotNull(AuronAdaptor.getInstance().getAuronConfiguration());
- AuronConfiguration auronConfig =
AuronAdaptor.getInstance().getAuronConfiguration();
+ assertNotNull(auronAdaptor.getAuronConfiguration());
+ AuronConfiguration auronConfig = auronAdaptor.getAuronConfiguration();
assertEquals(auronConfig.getInteger(AuronConfiguration.BATCH_SIZE),
10000);
assertEquals(auronConfig.getDouble(AuronConfiguration.MEMORY_FRACTION), 0.6,
0.0);
assertEquals(auronConfig.getString(AuronConfiguration.NATIVE_LOG_LEVEL),
"info");
}
+
+ @Test
+ public void testLoadAuronAdaptorInstanceViaSPI() {
+ AuronAdaptor adaptor = AuronAdaptor.getInstance();
+ assertInstanceOf(MockAuronAdaptor.class, adaptor, "SPI should discover
and instantiate MockAuronAdaptor");
+ }
}
diff --git
a/auron-core/src/test/java/org/apache/auron/jni/MockAuronAdaptorProvider.java
b/auron-core/src/test/java/org/apache/auron/jni/MockAuronAdaptorProvider.java
new file mode 100644
index 00000000..0782e47a
--- /dev/null
+++
b/auron-core/src/test/java/org/apache/auron/jni/MockAuronAdaptorProvider.java
@@ -0,0 +1,24 @@
+/*
+ * 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.auron.jni;
+
+public class MockAuronAdaptorProvider implements AuronAdaptorProvider {
+ @Override
+ public AuronAdaptor create() {
+ return new MockAuronAdaptor();
+ }
+}
diff --git
a/auron-core/src/test/resources/META-INF/services/org.apache.auron.jni.AuronAdaptorProvider
b/auron-core/src/test/resources/META-INF/services/org.apache.auron.jni.AuronAdaptorProvider
new file mode 100644
index 00000000..ed4907a0
--- /dev/null
+++
b/auron-core/src/test/resources/META-INF/services/org.apache.auron.jni.AuronAdaptorProvider
@@ -0,0 +1,17 @@
+#
+# 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.
+#
+org.apache.auron.jni.MockAuronAdaptorProvider
\ No newline at end of file
diff --git
a/spark-extension/src/main/java/org/apache/auron/jni/SparkAuronAdaptorProvider.java
b/spark-extension/src/main/java/org/apache/auron/jni/SparkAuronAdaptorProvider.java
new file mode 100644
index 00000000..0fb70bea
--- /dev/null
+++
b/spark-extension/src/main/java/org/apache/auron/jni/SparkAuronAdaptorProvider.java
@@ -0,0 +1,24 @@
+/*
+ * 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.auron.jni;
+
+public class SparkAuronAdaptorProvider implements AuronAdaptorProvider {
+ @Override
+ public AuronAdaptor create() {
+ return new SparkAuronAdaptor();
+ }
+}
diff --git
a/spark-extension/src/main/resources/META-INF/services/org.apache.auron.jni.AuronAdaptorProvider
b/spark-extension/src/main/resources/META-INF/services/org.apache.auron.jni.AuronAdaptorProvider
new file mode 100644
index 00000000..527b8a29
--- /dev/null
+++
b/spark-extension/src/main/resources/META-INF/services/org.apache.auron.jni.AuronAdaptorProvider
@@ -0,0 +1,17 @@
+#
+# 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.
+#
+org.apache.auron.jni.SparkAuronAdaptorProvider
\ No newline at end of file
diff --git
a/spark-extension/src/main/scala/org/apache/spark/sql/auron/Shims.scala
b/spark-extension/src/main/scala/org/apache/spark/sql/auron/Shims.scala
index 7ce1452a..fbac6a92 100644
--- a/spark-extension/src/main/scala/org/apache/spark/sql/auron/Shims.scala
+++ b/spark-extension/src/main/scala/org/apache/spark/sql/auron/Shims.scala
@@ -55,7 +55,6 @@ import org.apache.spark.storage.BlockManagerId
import org.apache.spark.storage.FileSegment
import org.apache.auron.{protobuf => pb}
-import org.apache.auron.jni.{AuronAdaptor, SparkAuronAdaptor}
abstract class Shims {
@@ -263,7 +262,6 @@ abstract class Shims {
object Shims {
lazy val get: Shims = {
- AuronAdaptor.initInstance(new SparkAuronAdaptor)
classOf[Shims].getClassLoader
.loadClass("org.apache.spark.sql.auron.ShimsImpl")
.newInstance()