From f567ac509ca0001acc7671804bc2945cccf22a60 Mon Sep 17 00:00:00 2001 From: Alan Paxton Date: Fri, 6 Sep 2024 14:05:20 +0100 Subject: [PATCH] Add ingest internal file option to link files New option literally appeared when I rebased to PR previous updates. Add linkFiles option now. --- java/rocksjni/ingest_external_file_options.cc | 24 ++++++++++++++++ .../rocksdb/IngestExternalFileOptions.java | 28 +++++++++++++++++++ .../IngestExternalFileOptionsTest.java | 11 ++++++++ 3 files changed, 63 insertions(+) diff --git a/java/rocksjni/ingest_external_file_options.cc b/java/rocksjni/ingest_external_file_options.cc index c7022b9bd844..e9b7f2a092bc 100644 --- a/java/rocksjni/ingest_external_file_options.cc +++ b/java/rocksjni/ingest_external_file_options.cc @@ -291,6 +291,30 @@ Java_org_rocksdb_IngestExternalFileOptions_setFailIfNotLastLevel( jfail_if_not_bottommost_level == JNI_TRUE; } +/* + * Class: org_rocksdb_IngestExternalFileOptions + * Method: linkFiles + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_rocksdb_IngestExternalFileOptions_linkFiles( + JNIEnv*, jclass, jlong jhandle) { + auto* options = + reinterpret_cast(jhandle); + return options->link_files == JNI_TRUE; +} + +/* + * Class: org_rocksdb_IngestExternalFileOptions + * Method: setLinkFiles + * Signature: (JZ)V + */ +JNIEXPORT void JNICALL Java_org_rocksdb_IngestExternalFileOptions_setLinkFiles( + JNIEnv*, jclass, jlong jhandle, jboolean jlink_files) { + auto* options = + reinterpret_cast(jhandle); + options->link_files = jlink_files == JNI_TRUE; +} + /* * Class: org_rocksdb_IngestExternalFileOptions * Method: disposeInternal diff --git a/java/src/main/java/org/rocksdb/IngestExternalFileOptions.java b/java/src/main/java/org/rocksdb/IngestExternalFileOptions.java index df0c97cdba3c..d955a4fc4017 100644 --- a/java/src/main/java/org/rocksdb/IngestExternalFileOptions.java +++ b/java/src/main/java/org/rocksdb/IngestExternalFileOptions.java @@ -344,6 +344,31 @@ public IngestExternalFileOptions setFailIfNotLastLevel(final boolean failIfNotLa return this; } + /** + * True if the files will be linked instead of copying them. + * Same as moveFiles except that input files will NOT be unlinked. + * Only one of `moveFiles` and `linkFiles` can be set at the same time. + * + * @return true if files will be moved + */ + public boolean linkFiles() { + return linkFiles(nativeHandle_); + } + + /** + * Can be set to true to link the files instead of copying them. + * Same as moveFiles except that input files will NOT be unlinked. + * Only one of `moveFiles` and `linkFiles` can be set at the same time. + * + * @param linkFiles true if files should be linked instead of copied + * + * @return the reference to the current IngestExternalFileOptions. + */ + public IngestExternalFileOptions setLinkFiles(final boolean linkFiles) { + setLinkFiles(nativeHandle_, linkFiles); + return this; + } + private static native long newIngestExternalFileOptions(); private static native long newIngestExternalFileOptions(final boolean moveFiles, final boolean snapshotConsistency, final boolean allowGlobalSeqNo, @@ -381,4 +406,7 @@ private static native void setVerifyFileChecksum( private static native boolean failIfNotLastLevel(final long handle); private static native void setFailIfNotLastLevel( final long handle, final boolean failIfNotLastLevel); + + private static native boolean linkFiles(final long handle); + private static native void setLinkFiles(final long handle, final boolean linkFiles); } diff --git a/java/src/test/java/org/rocksdb/IngestExternalFileOptionsTest.java b/java/src/test/java/org/rocksdb/IngestExternalFileOptionsTest.java index 5aab039a4f49..7a327a66bc2a 100644 --- a/java/src/test/java/org/rocksdb/IngestExternalFileOptionsTest.java +++ b/java/src/test/java/org/rocksdb/IngestExternalFileOptionsTest.java @@ -146,4 +146,15 @@ public void failIfNotLastLevel() { assertThat(options.failIfNotLastLevel()).isFalse(); } } + + @Test + public void linkFiles() { + try (final IngestExternalFileOptions options = new IngestExternalFileOptions()) { + assertThat(options.linkFiles()).isFalse(); + assertThat(options.setLinkFiles(true)).isEqualTo(options); + assertThat(options.linkFiles()).isTrue(); + assertThat(options.setLinkFiles(false)).isEqualTo(options); + assertThat(options.linkFiles()).isFalse(); + } + } }