Skip to content

Commit

Permalink
Add ingest internal file option to link files
Browse files Browse the repository at this point in the history
New option literally appeared when I rebased to PR previous updates. Add linkFiles option now.
  • Loading branch information
alanpaxton committed Sep 7, 2024
1 parent 22ff2dd commit f567ac5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
24 changes: 24 additions & 0 deletions java/rocksjni/ingest_external_file_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<ROCKSDB_NAMESPACE::IngestExternalFileOptions*>(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<ROCKSDB_NAMESPACE::IngestExternalFileOptions*>(jhandle);
options->link_files = jlink_files == JNI_TRUE;
}

/*
* Class: org_rocksdb_IngestExternalFileOptions
* Method: disposeInternal
Expand Down
28 changes: 28 additions & 0 deletions java/src/main/java/org/rocksdb/IngestExternalFileOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
11 changes: 11 additions & 0 deletions java/src/test/java/org/rocksdb/IngestExternalFileOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

0 comments on commit f567ac5

Please sign in to comment.