Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IngestExternalFileOptions update Java API to include several recently added option, in parity with C++ #12999

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
130 changes: 125 additions & 5 deletions java/rocksjni/ingest_external_file_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,8 @@ void Java_org_rocksdb_IngestExternalFileOptions_setIngestBehind(
* Method: writeGlobalSeqno
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL
Java_org_rocksdb_IngestExternalFileOptions_writeGlobalSeqno(JNIEnv*, jclass,
jlong jhandle) {
jboolean Java_org_rocksdb_IngestExternalFileOptions_writeGlobalSeqno(
JNIEnv*, jclass, jlong jhandle) {
auto* options =
reinterpret_cast<ROCKSDB_NAMESPACE::IngestExternalFileOptions*>(jhandle);
return options->write_global_seqno == JNI_TRUE;
Expand All @@ -177,14 +176,135 @@ Java_org_rocksdb_IngestExternalFileOptions_writeGlobalSeqno(JNIEnv*, jclass,
* Method: setWriteGlobalSeqno
* Signature: (JZ)V
*/
JNIEXPORT void JNICALL
Java_org_rocksdb_IngestExternalFileOptions_setWriteGlobalSeqno(
void Java_org_rocksdb_IngestExternalFileOptions_setWriteGlobalSeqno(
JNIEnv*, jclass, jlong jhandle, jboolean jwrite_global_seqno) {
auto* options =
reinterpret_cast<ROCKSDB_NAMESPACE::IngestExternalFileOptions*>(jhandle);
options->write_global_seqno = jwrite_global_seqno == JNI_TRUE;
}

/*
* Class: org_rocksdb_IngestExternalFileOptions
* Method: verifyChecksumsBeforeIngest
* Signature: (J)Z
*/
jboolean Java_org_rocksdb_IngestExternalFileOptions_verifyChecksumsBeforeIngest(
JNIEnv*, jclass, jlong jhandle) {
auto* options =
reinterpret_cast<ROCKSDB_NAMESPACE::IngestExternalFileOptions*>(jhandle);
return options->verify_checksums_before_ingest ? JNI_TRUE : JNI_FALSE;
}

/*
* Class: org_rocksdb_IngestExternalFileOptions
* Method: setVerifyChecksumsBeforeIngest
* Signature: (JZ)V
*/
void Java_org_rocksdb_IngestExternalFileOptions_setVerifyChecksumsBeforeIngest(
JNIEnv*, jclass, jlong jhandle, jboolean jverify_checksums_before_ingest) {
auto* options =
reinterpret_cast<ROCKSDB_NAMESPACE::IngestExternalFileOptions*>(jhandle);
options->verify_checksums_before_ingest =
jverify_checksums_before_ingest == JNI_TRUE;
}

/*
* Class: org_rocksdb_IngestExternalFileOptions
* Method: verifyChecksumsReadaheadSize
* Signature: (J)Z
*/
jlong Java_org_rocksdb_IngestExternalFileOptions_verifyChecksumsReadaheadSize(
JNIEnv*, jclass, jlong jhandle) {
auto* options =
reinterpret_cast<ROCKSDB_NAMESPACE::IngestExternalFileOptions*>(jhandle);
return options->verify_checksums_readahead_size;
}

/*
* Class: org_rocksdb_IngestExternalFileOptions
* Method: setVerifyChecksumsReadaheadSize
* Signature: (JZ)V
*/
void Java_org_rocksdb_IngestExternalFileOptions_setVerifyChecksumsReadaheadSize(
JNIEnv*, jclass, jlong jhandle, jlong jverify_checksums_readahead_size) {
auto* options =
reinterpret_cast<ROCKSDB_NAMESPACE::IngestExternalFileOptions*>(jhandle);
options->verify_checksums_readahead_size = jverify_checksums_readahead_size;
}

/*
* Class: org_rocksdb_IngestExternalFileOptions
* Method: verifyFileChecksum
* Signature: (J)Z
*/
jboolean Java_org_rocksdb_IngestExternalFileOptions_verifyFileChecksum(
JNIEnv*, jclass, jlong jhandle) {
auto* options =
reinterpret_cast<ROCKSDB_NAMESPACE::IngestExternalFileOptions*>(jhandle);
return options->verify_file_checksum ? JNI_TRUE : JNI_FALSE;
}

/*
* Class: org_rocksdb_IngestExternalFileOptions
* Method: setVerifyFileChecksum
* Signature: (JZ)V
*/
void Java_org_rocksdb_IngestExternalFileOptions_setVerifyFileChecksum(
JNIEnv*, jclass, jlong jhandle, jboolean jverify_file_checksum) {
auto* options =
reinterpret_cast<ROCKSDB_NAMESPACE::IngestExternalFileOptions*>(jhandle);
options->verify_file_checksum = jverify_file_checksum == JNI_TRUE;
}

/*
* Class: org_rocksdb_IngestExternalFileOptions
* Method: failIfNotLastLevel
* Signature: (J)Z
*/
jboolean Java_org_rocksdb_IngestExternalFileOptions_failIfNotLastLevel(
JNIEnv*, jclass, jlong jhandle) {
auto* options =
reinterpret_cast<ROCKSDB_NAMESPACE::IngestExternalFileOptions*>(jhandle);
return options->fail_if_not_bottommost_level ? JNI_TRUE : JNI_FALSE;
}

/*
* Class: org_rocksdb_IngestExternalFileOptions
* Method: setFailIfNotLastLevel
* Signature: (JZ)V
*/
void Java_org_rocksdb_IngestExternalFileOptions_setFailIfNotLastLevel(
JNIEnv*, jclass, jlong jhandle, jboolean jfail_if_not_bottommost_level) {
auto* options =
reinterpret_cast<ROCKSDB_NAMESPACE::IngestExternalFileOptions*>(jhandle);
options->fail_if_not_bottommost_level =
jfail_if_not_bottommost_level == JNI_TRUE;
}

/*
* Class: org_rocksdb_IngestExternalFileOptions
* Method: linkFiles
* Signature: (J)Z
*/
jboolean Java_org_rocksdb_IngestExternalFileOptions_linkFiles(JNIEnv*, jclass,
jlong jhandle) {
auto* options =
reinterpret_cast<ROCKSDB_NAMESPACE::IngestExternalFileOptions*>(jhandle);
return options->link_files ? JNI_TRUE : JNI_FALSE;
}

/*
* Class: org_rocksdb_IngestExternalFileOptions
* Method: setLinkFiles
* Signature: (JZ)V
*/
void 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
183 changes: 183 additions & 0 deletions java/src/main/java/org/rocksdb/IngestExternalFileOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,174 @@ public IngestExternalFileOptions setWriteGlobalSeqno(
return this;
}

/**
* True iff the option to verify the checksums of each block of the
* external SST file before ingestion has been set.
*
* @return true iff the option to verify the checksums of each block of the
* external SST file before ingestion has been set.
*/
public boolean verifyChecksumsBeforeIngest() {
return verifyChecksumsBeforeIngest(nativeHandle_);
}

/**
* Set to true if you would like to verify the checksums of each block of the
* external SST file before ingestion.
* <p>
* Warning: setting this to true causes slowdown in file ingestion because
* the external SST file has to be read.
* <p>
* Default: false
*
* @param verifyChecksumsBeforeIngest true if you would like to verify the checksums of each block
* of the
* external SST file before ingestion.
*
* @return the reference to the current IngestExternalFileOptions.
*/
public IngestExternalFileOptions setVerifyChecksumsBeforeIngest(
final boolean verifyChecksumsBeforeIngest) {
setVerifyChecksumsBeforeIngest(nativeHandle_, verifyChecksumsBeforeIngest);
return this;
}

/**
* When verify_checksums_before_ingest = true, RocksDB uses default
* readahead setting to scan the file while verifying checksums before
* ingestion
* <p>
* Users can override the default value using this option.
* Using a large readahead size (&gt; 2MB) can typically improve the performance
* of forward iteration on spinning disks.
*
* @return the current value of readahead size (0 if it has not been set)
*/
public long verifyChecksumsReadaheadSize() {
return verifyChecksumsReadaheadSize(nativeHandle_);
}

/**
* When verify_checksums_before_ingest = true, RocksDB uses default
* readahead setting to scan the file while verifying checksums before
* ingestion
* <p>
* Users can override the default value using this option.
* Using a large readahead size (&gt; 2MB) can typically improve the performance
* of forward iteration on spinning disks.
*
* @param verifyChecksumsReadaheadSize the value of readahead size to set
*
* @return the reference to the current IngestExternalFileOptions.
*/
public IngestExternalFileOptions setVerifyChecksumsReadaheadSize(
final long verifyChecksumsReadaheadSize) {
setVerifyChecksumsReadaheadSize(nativeHandle_, verifyChecksumsReadaheadSize);
return this;
}

/**
* Set to TRUE if user wants to verify the sst file checksum of ingested
* files. The DB checksum function will generate the checksum of each
* ingested file (if file_checksum_gen_factory is set) and compare the
* checksum function name and checksum with the ingested checksum information.
*
* @return true iff the option to verify the sst file checksum of ingested files is set
*/
public boolean verifyFileChecksum() {
return verifyFileChecksum(nativeHandle_);
}

/**
* Set to TRUE if user wants to verify the sst file checksum of ingested
* files. The DB checksum function will generate the checksum of each
* ingested file (if file_checksum_gen_factory is set) and compare the
* checksum function name and checksum with the ingested checksum information.
* <p>
* If this option is set to True: 1) if DB does not enable checksum
* (file_checksum_gen_factory == nullptr), the ingested checksum information
* will be ignored; 2) If DB enable the checksum function, we calculate the
* sst file checksum after the file is moved or copied and compare the
* checksum and checksum name. If checksum or checksum function name does
* not match, ingestion will be failed. If the verification is successful,
* checksum and checksum function name will be stored in Manifest.
* If this option is set to FALSE, 1) if DB does not enable checksum,
* the ingested checksum information will be ignored; 2) if DB enable the
* checksum, we only verify the ingested checksum function name and we
* trust the ingested checksum. If the checksum function name matches, we
* store the checksum in Manifest. DB does not calculate the checksum during
* ingestion. However, if no checksum information is provided with the
* ingested files, DB will generate the checksum and store in the Manifest.
*
* @param verifyFileChecksum true iff user wants to verify the sst file checksum of ingested files
*
* @return the reference to the current IngestExternalFileOptions.
*/
public IngestExternalFileOptions setVerifyFileChecksum(final boolean verifyFileChecksum) {
setVerifyFileChecksum(nativeHandle_, verifyFileChecksum);
return this;
}

/**
* Set to TRUE if user wants file to be ingested to the last level. An
* error of Status::TryAgain() will be returned if a file cannot fit in the
* last level when calling {@link RocksDB#ingestExternalFile(List, IngestExternalFileOptions)}
* or {@link RocksDB#ingestExternalFile(ColumnFamilyHandle, List, IngestExternalFileOptions)}.
* The user should clear
* the last level in the overlapping range before re-attempt.
* <p>
* @return true iff failIfNotLastLevel option has been set
*/
public boolean failIfNotLastLevel() {
return failIfNotLastLevel(nativeHandle_);
}

/**
* Set to TRUE if user wants file to be ingested to the last level. An
* error of Status::TryAgain() will be returned if a file cannot fit in the
* last level when calling
* DB::IngestExternalFile()/DB::IngestExternalFiles(). The user should clear
* the last level in the overlapping range before re-attempt.
* <p>
* ingestBehind takes precedence over failIfNotLastLevel.
* <p>
* This method is named for "last" instead of "bottommost" (in the C++ API)
* as that API notes that "bottommost" is obsolete/confusing terminology to refer to last level
*
* @param failIfNotLastLevel true iff user wants file to be ingested to the last level
*
* @return the reference to the current IngestExternalFileOptions.
*/
public IngestExternalFileOptions setFailIfNotLastLevel(final boolean failIfNotLastLevel) {
setFailIfNotLastLevel(nativeHandle_, failIfNotLastLevel);
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 All @@ -226,4 +394,19 @@ private static native void setAllowBlockingFlush(
private static native void setIngestBehind(final long handle, final boolean ingestBehind);
private static native boolean writeGlobalSeqno(final long handle);
private static native void setWriteGlobalSeqno(final long handle, final boolean writeGlobalSeqNo);
private static native boolean verifyChecksumsBeforeIngest(final long handle);
private static native void setVerifyChecksumsBeforeIngest(
final long handle, final boolean verifyChecksumsBeforeIngest);
private static native long verifyChecksumsReadaheadSize(final long handle);
private static native void setVerifyChecksumsReadaheadSize(
final long handle, final long verifyChecksumsReadaheadSize);
private static native boolean verifyFileChecksum(final long handle);
private static native void setVerifyFileChecksum(
final long handle, final boolean verifyFileChecksum);
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);
}
Loading
Loading