Skip to content

Commit

Permalink
Move rocksdb native library resource registration to a feature
Browse files Browse the repository at this point in the history
Always registers the correct native library as the logic runs on the
same architecture we are targeting (even when using containers).

Closes quarkusio#43319

(cherry picked from commit 53d2635)
  • Loading branch information
zakkak authored and gsmet committed Oct 18, 2024
1 parent 44df756 commit cff4148
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static io.quarkus.kafka.streams.runtime.KafkaStreamsPropertiesUtil.buildKafkaStreamsProperties;

import java.io.IOException;
import java.util.Properties;

import jakarta.inject.Singleton;
Expand All @@ -16,7 +15,6 @@
import org.apache.kafka.streams.processor.internals.StreamsPartitionAssignor;
import org.rocksdb.RocksDBException;
import org.rocksdb.Status;
import org.rocksdb.util.Environment;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
Expand All @@ -28,16 +26,16 @@
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.NativeImageFeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.JniRuntimeAccessBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem;
import io.quarkus.deployment.pkg.builditem.NativeImageRunnerBuildItem;
import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild;
import io.quarkus.kafka.streams.runtime.KafkaStreamsProducer;
import io.quarkus.kafka.streams.runtime.KafkaStreamsRecorder;
import io.quarkus.kafka.streams.runtime.KafkaStreamsRuntimeConfig;
import io.quarkus.kafka.streams.runtime.KafkaStreamsSupport;
import io.quarkus.kafka.streams.runtime.graal.KafkaStreamsFeature;
import io.quarkus.smallrye.health.deployment.spi.HealthBuildItem;

class KafkaStreamsProcessor {
Expand All @@ -53,12 +51,9 @@ FeatureBuildItem feature() {
void build(BuildProducer<ReflectiveClassBuildItem> reflectiveClasses,
BuildProducer<JniRuntimeAccessBuildItem> jniRuntimeAccessibleClasses,
BuildProducer<RuntimeReinitializedClassBuildItem> reinitialized,
BuildProducer<NativeImageResourceBuildItem> nativeLibs,
LaunchModeBuildItem launchMode,
NativeImageRunnerBuildItem nativeImageRunner) throws IOException {
LaunchModeBuildItem launchMode) {
registerClassesThatAreLoadedThroughReflection(reflectiveClasses, launchMode);
registerClassesThatAreAccessedViaJni(jniRuntimeAccessibleClasses);
addSupportForRocksDbLib(nativeLibs, nativeImageRunner);
enableLoadOfNativeLibs(reinitialized);
}

Expand Down Expand Up @@ -174,18 +169,6 @@ private void registerClassesThatAreAccessedViaJni(BuildProducer<JniRuntimeAccess
.produce(new JniRuntimeAccessBuildItem(true, false, false, RocksDBException.class, Status.class));
}

private void addSupportForRocksDbLib(BuildProducer<NativeImageResourceBuildItem> nativeLibs,
NativeImageRunnerBuildItem nativeImageRunnerFactory) {
// for RocksDB, either add linux64 native lib when targeting containers
if (nativeImageRunnerFactory.isContainerBuild()) {
nativeLibs.produce(new NativeImageResourceBuildItem("librocksdbjni-linux64.so"));
}
// otherwise the native lib of the platform this build runs on
else {
nativeLibs.produce(new NativeImageResourceBuildItem(Environment.getJniLibraryFileName("rocksdb")));
}
}

private void enableLoadOfNativeLibs(BuildProducer<RuntimeReinitializedClassBuildItem> reinitialized) {
reinitialized.produce(new RuntimeReinitializedClassBuildItem("org.rocksdb.RocksDB"));
}
Expand Down Expand Up @@ -236,4 +219,9 @@ void addHealthChecks(KafkaStreamsBuildTimeConfig buildTimeConfig, BuildProducer<
"io.quarkus.kafka.streams.runtime.health.KafkaStreamsStateHealthCheck",
buildTimeConfig.healthEnabled));
}

@BuildStep
NativeImageFeatureBuildItem kafkaStreamsFeature() {
return new NativeImageFeatureBuildItem(KafkaStreamsFeature.class.getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.quarkus.kafka.streams.runtime.graal;

import org.graalvm.nativeimage.hosted.Feature;
import org.graalvm.nativeimage.hosted.RuntimeResourceAccess;
import org.rocksdb.util.Environment;

public class KafkaStreamsFeature implements Feature {

@Override
public void afterRegistration(AfterRegistrationAccess access) {
String libraryFileName = Environment.getJniLibraryFileName("rocksdb");
RuntimeResourceAccess.addResource(Environment.class.getModule(), libraryFileName);
}

}

0 comments on commit cff4148

Please sign in to comment.