Skip to content

Commit 9ec4a2e

Browse files
committed
Add JNI for IngestExternalFileOptions::link_files
Add linkFiles() and setLinkFiles() methods to the Java API to expose the link_files option for hard linking SST files during ingestion.
1 parent 07c8774 commit 9ec4a2e

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

java/rocksjni/ingest_external_file_options.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,30 @@ Java_org_rocksdb_IngestExternalFileOptions_setWriteGlobalSeqno(
185185
options->write_global_seqno = jwrite_global_seqno == JNI_TRUE;
186186
}
187187

188+
/*
189+
* Class: org_rocksdb_IngestExternalFileOptions
190+
* Method: linkFiles
191+
* Signature: (J)Z
192+
*/
193+
JNIEXPORT jboolean JNICALL Java_org_rocksdb_IngestExternalFileOptions_linkFiles(
194+
JNIEnv*, jclass, jlong jhandle) {
195+
auto* options =
196+
reinterpret_cast<ROCKSDB_NAMESPACE::IngestExternalFileOptions*>(jhandle);
197+
return options->link_files == JNI_TRUE;
198+
}
199+
200+
/*
201+
* Class: org_rocksdb_IngestExternalFileOptions
202+
* Method: setLinkFiles
203+
* Signature: (JZ)V
204+
*/
205+
JNIEXPORT void JNICALL Java_org_rocksdb_IngestExternalFileOptions_setLinkFiles(
206+
JNIEnv*, jclass, jlong jhandle, jboolean jlink_files) {
207+
auto* options =
208+
reinterpret_cast<ROCKSDB_NAMESPACE::IngestExternalFileOptions*>(jhandle);
209+
options->link_files = jlink_files == JNI_TRUE;
210+
}
211+
188212
/*
189213
* Class: org_rocksdb_IngestExternalFileOptions
190214
* Method: disposeInternal

java/src/main/java/org/rocksdb/IngestExternalFileOptions.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,35 @@ public IngestExternalFileOptions setWriteGlobalSeqno(
201201
return this;
202202
}
203203

204+
/**
205+
* Returns true if files will be hard linked instead of copied.
206+
* <p>
207+
* See {@link #setLinkFiles(boolean)}.
208+
*
209+
* @return true if files will be hard linked, false otherwise.
210+
*/
211+
public boolean linkFiles() {
212+
return linkFiles(nativeHandle_);
213+
}
214+
215+
/**
216+
* Set to true to hard link ingested files to the DB directory instead of
217+
* copying them. This preserves the original file links after ingestion.
218+
* <p>
219+
* Only one of {@link #setMoveFiles(boolean)} and {@link #setLinkFiles(boolean)}
220+
* can be set to true at the same time.
221+
* <p>
222+
* Default: false
223+
*
224+
* @param linkFiles true to hard link files instead of copying
225+
*
226+
* @return the reference to the current IngestExternalFileOptions.
227+
*/
228+
public IngestExternalFileOptions setLinkFiles(final boolean linkFiles) {
229+
setLinkFiles(nativeHandle_, linkFiles);
230+
return this;
231+
}
232+
204233
private static native long newIngestExternalFileOptions();
205234
private static native long newIngestExternalFileOptions(final boolean moveFiles,
206235
final boolean snapshotConsistency, final boolean allowGlobalSeqNo,
@@ -226,4 +255,6 @@ private static native void setAllowBlockingFlush(
226255
private static native void setIngestBehind(final long handle, final boolean ingestBehind);
227256
private static native boolean writeGlobalSeqno(final long handle);
228257
private static native void setWriteGlobalSeqno(final long handle, final boolean writeGlobalSeqNo);
258+
private static native boolean linkFiles(final long handle);
259+
private static native void setLinkFiles(final long handle, final boolean linkFiles);
229260
}

java/src/test/java/org/rocksdb/IngestExternalFileOptionsTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,13 @@ public void writeGlobalSeqno() {
104104
assertThat(options.writeGlobalSeqno()).isTrue();
105105
}
106106
}
107+
108+
@Test
109+
public void linkFiles() {
110+
try (final IngestExternalFileOptions options = new IngestExternalFileOptions()) {
111+
assertThat(options.linkFiles()).isFalse();
112+
options.setLinkFiles(true);
113+
assertThat(options.linkFiles()).isTrue();
114+
}
115+
}
107116
}

0 commit comments

Comments
 (0)