Skip to content

Commit b7cf5f0

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 b7cf5f0

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

java/rocksjni/ingest_external_file_options.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,31 @@ 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
194+
Java_org_rocksdb_IngestExternalFileOptions_linkFiles(JNIEnv*, jclass,
195+
jlong jhandle) {
196+
auto* options =
197+
reinterpret_cast<ROCKSDB_NAMESPACE::IngestExternalFileOptions*>(jhandle);
198+
return options->link_files == JNI_TRUE;
199+
}
200+
201+
/*
202+
* Class: org_rocksdb_IngestExternalFileOptions
203+
* Method: setLinkFiles
204+
* Signature: (JZ)V
205+
*/
206+
JNIEXPORT void JNICALL Java_org_rocksdb_IngestExternalFileOptions_setLinkFiles(
207+
JNIEnv*, jclass, jlong jhandle, jboolean jlink_files) {
208+
auto* options =
209+
reinterpret_cast<ROCKSDB_NAMESPACE::IngestExternalFileOptions*>(jhandle);
210+
options->link_files = jlink_files == JNI_TRUE;
211+
}
212+
188213
/*
189214
* Class: org_rocksdb_IngestExternalFileOptions
190215
* 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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,14 @@ public void writeGlobalSeqno() {
104104
assertThat(options.writeGlobalSeqno()).isTrue();
105105
}
106106
}
107+
108+
@Test
109+
public void linkFiles() {
110+
try (final IngestExternalFileOptions options =
111+
new IngestExternalFileOptions()) {
112+
assertThat(options.linkFiles()).isFalse();
113+
options.setLinkFiles(true);
114+
assertThat(options.linkFiles()).isTrue();
115+
}
116+
}
107117
}

0 commit comments

Comments
 (0)