Skip to content
Merged
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
13 changes: 13 additions & 0 deletions java/dataset/src/main/cpp/jni_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "arrow/dataset/file_base.h"
#include "arrow/filesystem/localfs.h"
#include "arrow/filesystem/path_util.h"
#include "arrow/filesystem/s3fs.h"
#include "arrow/engine/substrait/util.h"
#include "arrow/ipc/api.h"
#include "arrow/util/iterator.h"
Expand Down Expand Up @@ -569,6 +570,18 @@ JNIEXPORT void JNICALL Java_org_apache_arrow_dataset_jni_JniWrapper_releaseBuffe
JNI_METHOD_END()
}

/*
* Class: org_apache_arrow_dataset_jni_JniWrapper
* Method: ensureS3Finalized
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_org_apache_arrow_dataset_jni_JniWrapper_ensureS3Finalized(
JNIEnv* env, jobject) {
JNI_METHOD_START
JniAssertOkOrThrow(arrow::fs::EnsureS3Finalized());
JNI_METHOD_END()
}

/*
* Class: org_apache_arrow_dataset_file_JniWrapper
* Method: makeFileSystemDatasetFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void ensureLoaded() {
return;
}
loadRemaining();
ensureS3FinalizedOnShutdown();
}

private synchronized void loadRemaining() {
Expand Down Expand Up @@ -109,4 +110,8 @@ private String getNormalizedArch() {
}
return arch;
}

private void ensureS3FinalizedOnShutdown() {
Runtime.getRuntime().addShutdownHook(new Thread(() -> { JniWrapper.get().ensureS3Finalized(); }));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,10 @@ private JniWrapper() {
* @param bufferId the native pointer of the arrow::Buffer instance.
*/
public native void releaseBuffer(long bufferId);

/**
* Ensure the S3 APIs are shutdown, but only if not already done. If the S3 APIs are unintialized,
* then this is a noop.
*/
public native void ensureS3Finalized();
}