Summary: Previously the Java implementation of `RocksDB#addFile` was both incomplete and not inline with the C++ API. Rather than fix it, as I see that `rocksdb::DB::AddFile` is now deprecated in favour of `rocksdb::DB::IngestExternalFile`, I have removed the old broken implementation and implemented `RocksDB#ingestExternalFile`. Closes https://github.com/facebook/rocksdb/issues/2261 Closes https://github.com/facebook/rocksdb/pull/2291 Differential Revision: D5061264 Pulled By: sagar0 fbshipit-source-id: 85df0899fa1b1fc3535175cac4f52353511d4104main
parent
228f49d20a
commit
88c818e437
@ -1,274 +0,0 @@ |
||||
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under the BSD-style license found in the
|
||||
// LICENSE file in the root directory of this source tree. An additional grant
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
//
|
||||
// This file implements the "bridge" between Java and C++ and enables
|
||||
// calling C++ rocksdb::ExternalSstFileInfo methods
|
||||
// from Java side.
|
||||
|
||||
#include <jni.h> |
||||
|
||||
#include "include/org_rocksdb_ExternalSstFileInfo.h" |
||||
#include "rocksdb/sst_file_writer.h" |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_ExternalSstFileInfo |
||||
* Method: newExternalSstFileInfo |
||||
* Signature: ()J |
||||
*/ |
||||
jlong Java_org_rocksdb_ExternalSstFileInfo_newExternalSstFileInfo__( |
||||
JNIEnv *env, jclass jcls) { |
||||
return reinterpret_cast<jlong>(new rocksdb::ExternalSstFileInfo()); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_ExternalSstFileInfo |
||||
* Method: newExternalSstFileInfo |
||||
* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JJII)J |
||||
*/ |
||||
jlong Java_org_rocksdb_ExternalSstFileInfo_newExternalSstFileInfo__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2JJII( |
||||
JNIEnv *env, jclass jcls, jstring jfile_path, jstring jsmallest_key, |
||||
jstring jlargest_key, jlong jsequence_number, jlong jfile_size, |
||||
jint jnum_entries, jint jversion) { |
||||
const char *file_path = env->GetStringUTFChars(jfile_path, nullptr); |
||||
if(file_path == nullptr) { |
||||
// exception thrown: OutOfMemoryError
|
||||
return 0; |
||||
} |
||||
const char *smallest_key = env->GetStringUTFChars(jsmallest_key, nullptr); |
||||
if(smallest_key == nullptr) { |
||||
// exception thrown: OutOfMemoryError
|
||||
env->ReleaseStringUTFChars(jfile_path, file_path); |
||||
return 0; |
||||
} |
||||
const char *largest_key = env->GetStringUTFChars(jlargest_key, nullptr); |
||||
if(largest_key == nullptr) { |
||||
// exception thrown: OutOfMemoryError
|
||||
env->ReleaseStringUTFChars(jsmallest_key, smallest_key); |
||||
env->ReleaseStringUTFChars(jfile_path, file_path); |
||||
return 0; |
||||
} |
||||
|
||||
auto *external_sst_file_info = new rocksdb::ExternalSstFileInfo( |
||||
file_path, smallest_key, largest_key, |
||||
static_cast<rocksdb::SequenceNumber>(jsequence_number), |
||||
static_cast<uint64_t>(jfile_size), static_cast<int32_t>(jnum_entries), |
||||
static_cast<int32_t>(jversion)); |
||||
|
||||
env->ReleaseStringUTFChars(jlargest_key, largest_key); |
||||
env->ReleaseStringUTFChars(jsmallest_key, smallest_key); |
||||
env->ReleaseStringUTFChars(jfile_path, file_path); |
||||
|
||||
return reinterpret_cast<jlong>(external_sst_file_info); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_ExternalSstFileInfo |
||||
* Method: setFilePath |
||||
* Signature: (JLjava/lang/String;)V |
||||
*/ |
||||
void Java_org_rocksdb_ExternalSstFileInfo_setFilePath(JNIEnv *env, jobject jobj, |
||||
jlong jhandle, |
||||
jstring jfile_path) { |
||||
auto *external_sst_file_info = |
||||
reinterpret_cast<rocksdb::ExternalSstFileInfo *>(jhandle); |
||||
const char *file_path = env->GetStringUTFChars(jfile_path, nullptr); |
||||
if(file_path == nullptr) { |
||||
// exception thrown: OutOfMemoryError
|
||||
return; |
||||
} |
||||
external_sst_file_info->file_path = file_path; |
||||
env->ReleaseStringUTFChars(jfile_path, file_path); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_ExternalSstFileInfo |
||||
* Method: filePath |
||||
* Signature: (J)Ljava/lang/String; |
||||
*/ |
||||
jstring Java_org_rocksdb_ExternalSstFileInfo_filePath(JNIEnv *env, jobject jobj, |
||||
jlong jhandle) { |
||||
auto *external_sst_file_info = |
||||
reinterpret_cast<rocksdb::ExternalSstFileInfo *>(jhandle); |
||||
return env->NewStringUTF(external_sst_file_info->file_path.data()); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_ExternalSstFileInfo |
||||
* Method: setSmallestKey |
||||
* Signature: (JLjava/lang/String;)V |
||||
*/ |
||||
void Java_org_rocksdb_ExternalSstFileInfo_setSmallestKey( |
||||
JNIEnv *env, jobject jobj, jlong jhandle, jstring jsmallest_key) { |
||||
auto *external_sst_file_info = |
||||
reinterpret_cast<rocksdb::ExternalSstFileInfo *>(jhandle); |
||||
const char *smallest_key = env->GetStringUTFChars(jsmallest_key, nullptr); |
||||
if(smallest_key == nullptr) { |
||||
// exception thrown: OutOfMemoryError
|
||||
return; |
||||
} |
||||
external_sst_file_info->smallest_key = smallest_key; |
||||
env->ReleaseStringUTFChars(jsmallest_key, smallest_key); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_ExternalSstFileInfo |
||||
* Method: smallestKey |
||||
* Signature: (J)Ljava/lang/String; |
||||
*/ |
||||
jstring Java_org_rocksdb_ExternalSstFileInfo_smallestKey(JNIEnv *env, |
||||
jobject jobj, |
||||
jlong jhandle) { |
||||
auto *external_sst_file_info = |
||||
reinterpret_cast<rocksdb::ExternalSstFileInfo *>(jhandle); |
||||
return env->NewStringUTF(external_sst_file_info->smallest_key.data()); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_ExternalSstFileInfo |
||||
* Method: setLargestKey |
||||
* Signature: (JLjava/lang/String;)V |
||||
*/ |
||||
void Java_org_rocksdb_ExternalSstFileInfo_setLargestKey(JNIEnv *env, |
||||
jobject jobj, |
||||
jlong jhandle, |
||||
jstring jlargest_key) { |
||||
auto *external_sst_file_info = |
||||
reinterpret_cast<rocksdb::ExternalSstFileInfo *>(jhandle); |
||||
const char *largest_key = env->GetStringUTFChars(jlargest_key, NULL); |
||||
if(largest_key == nullptr) { |
||||
// exception thrown: OutOfMemoryError
|
||||
return; |
||||
} |
||||
external_sst_file_info->largest_key = largest_key; |
||||
env->ReleaseStringUTFChars(jlargest_key, largest_key); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_ExternalSstFileInfo |
||||
* Method: largestKey |
||||
* Signature: (J)Ljava/lang/String; |
||||
*/ |
||||
jstring Java_org_rocksdb_ExternalSstFileInfo_largestKey(JNIEnv *env, |
||||
jobject jobj, |
||||
jlong jhandle) { |
||||
auto *external_sst_file_info = |
||||
reinterpret_cast<rocksdb::ExternalSstFileInfo *>(jhandle); |
||||
return env->NewStringUTF(external_sst_file_info->largest_key.data()); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_ExternalSstFileInfo |
||||
* Method: setSequenceNumber |
||||
* Signature: (JJ)V |
||||
*/ |
||||
void Java_org_rocksdb_ExternalSstFileInfo_setSequenceNumber( |
||||
JNIEnv *env, jobject jobj, jlong jhandle, jlong jsequence_number) { |
||||
auto *external_sst_file_info = |
||||
reinterpret_cast<rocksdb::ExternalSstFileInfo *>(jhandle); |
||||
external_sst_file_info->sequence_number = |
||||
static_cast<rocksdb::SequenceNumber>(jsequence_number); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_ExternalSstFileInfo |
||||
* Method: sequenceNumber |
||||
* Signature: (J)J |
||||
*/ |
||||
jlong Java_org_rocksdb_ExternalSstFileInfo_sequenceNumber(JNIEnv *env, |
||||
jobject jobj, |
||||
jlong jhandle) { |
||||
auto *external_sst_file_info = |
||||
reinterpret_cast<rocksdb::ExternalSstFileInfo *>(jhandle); |
||||
return static_cast<jlong>(external_sst_file_info->sequence_number); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_ExternalSstFileInfo |
||||
* Method: setFileSize |
||||
* Signature: (JJ)V |
||||
*/ |
||||
void Java_org_rocksdb_ExternalSstFileInfo_setFileSize(JNIEnv *env, jobject jobj, |
||||
jlong jhandle, |
||||
jlong jfile_size) { |
||||
auto *external_sst_file_info = |
||||
reinterpret_cast<rocksdb::ExternalSstFileInfo *>(jhandle); |
||||
external_sst_file_info->file_size = static_cast<uint64_t>(jfile_size); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_ExternalSstFileInfo |
||||
* Method: fileSize |
||||
* Signature: (J)J |
||||
*/ |
||||
jlong Java_org_rocksdb_ExternalSstFileInfo_fileSize(JNIEnv *env, jobject jobj, |
||||
jlong jhandle) { |
||||
auto *external_sst_file_info = |
||||
reinterpret_cast<rocksdb::ExternalSstFileInfo *>(jhandle); |
||||
return static_cast<jlong>(external_sst_file_info->file_size); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_ExternalSstFileInfo |
||||
* Method: setNumEntries |
||||
* Signature: (JI)V |
||||
*/ |
||||
void Java_org_rocksdb_ExternalSstFileInfo_setNumEntries(JNIEnv *env, |
||||
jobject jobj, |
||||
jlong jhandle, |
||||
jint jnum_entries) { |
||||
auto *external_sst_file_info = |
||||
reinterpret_cast<rocksdb::ExternalSstFileInfo *>(jhandle); |
||||
external_sst_file_info->num_entries = static_cast<uint64_t>(jnum_entries); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_ExternalSstFileInfo |
||||
* Method: numEntries |
||||
* Signature: (J)I |
||||
*/ |
||||
jint Java_org_rocksdb_ExternalSstFileInfo_numEntries(JNIEnv *env, jobject jobj, |
||||
jlong jhandle) { |
||||
auto *external_sst_file_info = |
||||
reinterpret_cast<rocksdb::ExternalSstFileInfo *>(jhandle); |
||||
return static_cast<jint>(external_sst_file_info->num_entries); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_ExternalSstFileInfo |
||||
* Method: setVersion |
||||
* Signature: (JI)V |
||||
*/ |
||||
void Java_org_rocksdb_ExternalSstFileInfo_setVersion(JNIEnv *env, jobject jobj, |
||||
jlong jhandle, |
||||
jint jversion) { |
||||
auto *external_sst_file_info = |
||||
reinterpret_cast<rocksdb::ExternalSstFileInfo *>(jhandle); |
||||
external_sst_file_info->version = static_cast<int32_t>(jversion); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_ExternalSstFileInfo |
||||
* Method: version |
||||
* Signature: (J)I |
||||
*/ |
||||
jint Java_org_rocksdb_ExternalSstFileInfo_version(JNIEnv *env, jobject jobj, |
||||
jlong jhandle) { |
||||
auto *external_sst_file_info = |
||||
reinterpret_cast<rocksdb::ExternalSstFileInfo *>(jhandle); |
||||
return static_cast<jint>(external_sst_file_info->version); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_ExternalSstFileInfo |
||||
* Method: disposeInternal |
||||
* Signature: (J)V |
||||
*/ |
||||
void Java_org_rocksdb_ExternalSstFileInfo_disposeInternal(JNIEnv *env, |
||||
jobject jobj, |
||||
jlong jhandle) { |
||||
auto* esfi = reinterpret_cast<rocksdb::ExternalSstFileInfo *>(jhandle); |
||||
assert(esfi != nullptr); |
||||
delete esfi; |
||||
} |
@ -0,0 +1,149 @@ |
||||
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under the BSD-style license found in the
|
||||
// LICENSE file in the root directory of this source tree. An additional grant
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
//
|
||||
// This file implements the "bridge" between Java and C++ for
|
||||
// rocksdb::FilterPolicy.
|
||||
|
||||
#include <jni.h> |
||||
|
||||
#include "include/org_rocksdb_IngestExternalFileOptions.h" |
||||
#include "rocksdb/options.h" |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_IngestExternalFileOptions |
||||
* Method: newIngestExternalFileOptions |
||||
* Signature: ()J |
||||
*/ |
||||
jlong Java_org_rocksdb_IngestExternalFileOptions_newIngestExternalFileOptions__( |
||||
JNIEnv* env, jclass jclazz) { |
||||
auto* options = new rocksdb::IngestExternalFileOptions(); |
||||
return reinterpret_cast<jlong>(options); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_IngestExternalFileOptions |
||||
* Method: newIngestExternalFileOptions |
||||
* Signature: (ZZZZ)J |
||||
*/ |
||||
jlong Java_org_rocksdb_IngestExternalFileOptions_newIngestExternalFileOptions__ZZZZ( |
||||
JNIEnv* env, jclass jcls, jboolean jmove_files, |
||||
jboolean jsnapshot_consistency, jboolean jallow_global_seqno, |
||||
jboolean jallow_blocking_flush) { |
||||
auto* options = new rocksdb::IngestExternalFileOptions(); |
||||
options->move_files = static_cast<bool>(jmove_files); |
||||
options->snapshot_consistency = static_cast<bool>(jsnapshot_consistency); |
||||
options->allow_global_seqno = static_cast<bool>(jallow_global_seqno); |
||||
options->allow_blocking_flush = static_cast<bool>(jallow_blocking_flush); |
||||
return reinterpret_cast<jlong>(options); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_IngestExternalFileOptions |
||||
* Method: moveFiles |
||||
* Signature: (J)Z |
||||
*/ |
||||
jboolean Java_org_rocksdb_IngestExternalFileOptions_moveFiles( |
||||
JNIEnv* env, jobject jobj, jlong jhandle) { |
||||
auto* options = |
||||
reinterpret_cast<rocksdb::IngestExternalFileOptions*>(jhandle); |
||||
return static_cast<jboolean>(options->move_files); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_IngestExternalFileOptions |
||||
* Method: setMoveFiles |
||||
* Signature: (JZ)V |
||||
*/ |
||||
void Java_org_rocksdb_IngestExternalFileOptions_setMoveFiles( |
||||
JNIEnv* env, jobject jobj, jlong jhandle, jboolean jmove_files) { |
||||
auto* options = |
||||
reinterpret_cast<rocksdb::IngestExternalFileOptions*>(jhandle); |
||||
options->move_files = static_cast<bool>(jmove_files); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_IngestExternalFileOptions |
||||
* Method: snapshotConsistency |
||||
* Signature: (J)Z |
||||
*/ |
||||
jboolean Java_org_rocksdb_IngestExternalFileOptions_snapshotConsistency( |
||||
JNIEnv* env, jobject jobj, jlong jhandle) { |
||||
auto* options = |
||||
reinterpret_cast<rocksdb::IngestExternalFileOptions*>(jhandle); |
||||
return static_cast<jboolean>(options->snapshot_consistency); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_IngestExternalFileOptions |
||||
* Method: setSnapshotConsistency |
||||
* Signature: (JZ)V |
||||
*/ |
||||
void Java_org_rocksdb_IngestExternalFileOptions_setSnapshotConsistency( |
||||
JNIEnv* env, jobject jobj, jlong jhandle, |
||||
jboolean jsnapshot_consistency) { |
||||
auto* options = |
||||
reinterpret_cast<rocksdb::IngestExternalFileOptions*>(jhandle); |
||||
options->snapshot_consistency = static_cast<bool>(jsnapshot_consistency); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_IngestExternalFileOptions |
||||
* Method: allowGlobalSeqNo |
||||
* Signature: (J)Z |
||||
*/ |
||||
jboolean Java_org_rocksdb_IngestExternalFileOptions_allowGlobalSeqNo( |
||||
JNIEnv* env, jobject jobj, jlong jhandle) { |
||||
auto* options = |
||||
reinterpret_cast<rocksdb::IngestExternalFileOptions*>(jhandle); |
||||
return static_cast<jboolean>(options->allow_global_seqno); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_IngestExternalFileOptions |
||||
* Method: setAllowGlobalSeqNo |
||||
* Signature: (JZ)V |
||||
*/ |
||||
void Java_org_rocksdb_IngestExternalFileOptions_setAllowGlobalSeqNo( |
||||
JNIEnv* env, jobject jobj, jlong jhandle, jboolean jallow_global_seqno) { |
||||
auto* options = |
||||
reinterpret_cast<rocksdb::IngestExternalFileOptions*>(jhandle); |
||||
options->allow_global_seqno = static_cast<bool>(jallow_global_seqno); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_IngestExternalFileOptions |
||||
* Method: allowBlockingFlush |
||||
* Signature: (J)Z |
||||
*/ |
||||
jboolean Java_org_rocksdb_IngestExternalFileOptions_allowBlockingFlush( |
||||
JNIEnv* env, jobject jobj, jlong jhandle) { |
||||
auto* options = |
||||
reinterpret_cast<rocksdb::IngestExternalFileOptions*>(jhandle); |
||||
return static_cast<jboolean>(options->allow_blocking_flush); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_IngestExternalFileOptions |
||||
* Method: setAllowBlockingFlush |
||||
* Signature: (JZ)V |
||||
*/ |
||||
void Java_org_rocksdb_IngestExternalFileOptions_setAllowBlockingFlush( |
||||
JNIEnv* env, jobject jobj, jlong jhandle, jboolean jallow_blocking_flush) { |
||||
auto* options = |
||||
reinterpret_cast<rocksdb::IngestExternalFileOptions*>(jhandle); |
||||
options->allow_blocking_flush = static_cast<bool>(jallow_blocking_flush); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_IngestExternalFileOptions |
||||
* Method: disposeInternal |
||||
* Signature: (J)V |
||||
*/ |
||||
void Java_org_rocksdb_IngestExternalFileOptions_disposeInternal( |
||||
JNIEnv* env, jobject jobj, jlong jhandle) { |
||||
auto* options = |
||||
reinterpret_cast<rocksdb::IngestExternalFileOptions*>(jhandle); |
||||
delete options; |
||||
} |
@ -1,135 +0,0 @@ |
||||
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under the BSD-style license found in the
|
||||
// LICENSE file in the root directory of this source tree. An additional grant
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
package org.rocksdb; |
||||
|
||||
import java.io.File; |
||||
|
||||
public class ExternalSstFileInfo extends RocksObject { |
||||
public ExternalSstFileInfo() { |
||||
super(newExternalSstFileInfo()); |
||||
} |
||||
|
||||
public ExternalSstFileInfo(final String filePath, final String smallestKey, |
||||
final String largestKey, final long sequenceNumber, final long fileSize, final int numEntries, |
||||
final int version) { |
||||
super(newExternalSstFileInfo(ensureNotNullFilePath(filePath), |
||||
ensureNotNullSmallestKey(smallestKey), ensureNotNullLargestKey(largestKey), sequenceNumber, |
||||
fileSize, numEntries, version)); |
||||
} |
||||
|
||||
private static String ensureNotNullFilePath(final String filePath) { |
||||
if (filePath == null) { |
||||
throw new NullPointerException("filePath is null."); |
||||
} |
||||
return filePath; |
||||
} |
||||
|
||||
private static String ensureNotNullSmallestKey(final String smallestKey) { |
||||
if (smallestKey == null) { |
||||
throw new NullPointerException("smallestKey is null."); |
||||
} |
||||
return smallestKey; |
||||
} |
||||
|
||||
private static String ensureNotNullLargestKey(final String largestKey) { |
||||
if (largestKey == null) { |
||||
throw new NullPointerException("largestKey is null."); |
||||
} |
||||
return largestKey; |
||||
} |
||||
|
||||
public void setFilePath(final String filePath) { |
||||
setFilePath(nativeHandle_, filePath); |
||||
} |
||||
|
||||
public String filePath() { |
||||
return filePath(nativeHandle_); |
||||
} |
||||
|
||||
public void setSmallestKey(final String smallestKey) { |
||||
setSmallestKey(nativeHandle_, smallestKey); |
||||
} |
||||
|
||||
public String smallestKey() { |
||||
return smallestKey(nativeHandle_); |
||||
} |
||||
|
||||
public void setLargestKey(final String largestKey) { |
||||
setLargestKey(nativeHandle_, largestKey); |
||||
} |
||||
|
||||
public String largestKey() { |
||||
return largestKey(nativeHandle_); |
||||
} |
||||
|
||||
public void setSequenceNumber(final long sequenceNumber) { |
||||
setSequenceNumber(nativeHandle_, sequenceNumber); |
||||
} |
||||
|
||||
public long sequenceNumber() { |
||||
return sequenceNumber(nativeHandle_); |
||||
} |
||||
|
||||
public void setFileSize(final long fileSize) { |
||||
setFileSize(nativeHandle_, fileSize); |
||||
} |
||||
|
||||
public long fileSize() { |
||||
return fileSize(nativeHandle_); |
||||
} |
||||
|
||||
public void setNumEntries(final int numEntries) { |
||||
setNumEntries(nativeHandle_, numEntries); |
||||
} |
||||
|
||||
public int numEntries() { |
||||
return numEntries(nativeHandle_); |
||||
} |
||||
|
||||
public void setVersion(final int version) { |
||||
setVersion(nativeHandle_, version); |
||||
} |
||||
|
||||
public int version() { |
||||
return version(nativeHandle_); |
||||
} |
||||
|
||||
private native static long newExternalSstFileInfo(); |
||||
|
||||
private native static long newExternalSstFileInfo(final String filePath, final String smallestKey, |
||||
final String largestKey, final long sequenceNumber, final long fileSize, final int numEntries, |
||||
final int version); |
||||
|
||||
private native void setFilePath(final long handle, final String filePath); |
||||
|
||||
private native String filePath(final long handle); |
||||
|
||||
private native void setSmallestKey(final long handle, final String smallestKey); |
||||
|
||||
private native String smallestKey(final long handle); |
||||
|
||||
private native void setLargestKey(final long handle, final String largestKey); |
||||
|
||||
private native String largestKey(final long handle); |
||||
|
||||
private native void setSequenceNumber(final long handle, final long sequenceNumber); |
||||
|
||||
private native long sequenceNumber(final long handle); |
||||
|
||||
private native void setFileSize(final long handle, final long fileSize); |
||||
|
||||
private native long fileSize(final long handle); |
||||
|
||||
private native void setNumEntries(final long handle, final int numEntries); |
||||
|
||||
private native int numEntries(final long handle); |
||||
|
||||
private native void setVersion(final long handle, final int version); |
||||
|
||||
private native int version(final long handle); |
||||
|
||||
@Override protected final native void disposeInternal(final long handle); |
||||
} |
@ -0,0 +1,125 @@ |
||||
package org.rocksdb; |
||||
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under the BSD-style license found in the
|
||||
// LICENSE file in the root directory of this source tree. An additional grant
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* IngestExternalFileOptions is used by {@link RocksDB#ingestExternalFile(ColumnFamilyHandle, List, IngestExternalFileOptions)} |
||||
*/ |
||||
public class IngestExternalFileOptions extends RocksObject { |
||||
|
||||
public IngestExternalFileOptions() { |
||||
super(newIngestExternalFileOptions()); |
||||
} |
||||
|
||||
/** |
||||
* @param moveFiles {@link #setMoveFiles(boolean)} |
||||
* @param snapshotConsistency {@link #setSnapshotConsistency(boolean)} |
||||
* @param allowGlobalSeqNo {@link #setAllowGlobalSeqNo(boolean)} |
||||
* @param allowBlockingFlush {@link #setAllowBlockingFlush(boolean)} |
||||
*/ |
||||
public IngestExternalFileOptions(final boolean moveFiles, |
||||
final boolean snapshotConsistency, final boolean allowGlobalSeqNo, |
||||
final boolean allowBlockingFlush) { |
||||
super(newIngestExternalFileOptions(moveFiles, snapshotConsistency, |
||||
allowGlobalSeqNo, allowBlockingFlush)); |
||||
} |
||||
|
||||
/** |
||||
* Can be set to true to move the files instead of copying them. |
||||
* |
||||
* @return true if files will be moved |
||||
*/ |
||||
public boolean moveFiles() { |
||||
return moveFiles(nativeHandle_); |
||||
} |
||||
|
||||
/** |
||||
* Can be set to true to move the files instead of copying them. |
||||
* |
||||
* @param moveFiles true if files should be moved instead of copied |
||||
*/ |
||||
public void setMoveFiles(final boolean moveFiles) { |
||||
setMoveFiles(nativeHandle_, moveFiles); |
||||
} |
||||
|
||||
/** |
||||
* If set to false, an ingested file keys could appear in existing snapshots |
||||
* that where created before the file was ingested. |
||||
* |
||||
* @return true if snapshot consistency is assured |
||||
*/ |
||||
public boolean snapshotConsistency() { |
||||
return snapshotConsistency(nativeHandle_); |
||||
} |
||||
|
||||
/** |
||||
* If set to false, an ingested file keys could appear in existing snapshots |
||||
* that where created before the file was ingested. |
||||
* |
||||
* @param snapshotConsistency true if snapshot consistency is required |
||||
*/ |
||||
public void setSnapshotConsistency(final boolean snapshotConsistency) { |
||||
setSnapshotConsistency(nativeHandle_, snapshotConsistency); |
||||
} |
||||
|
||||
/** |
||||
* If set to false, {@link RocksDB#ingestExternalFile(ColumnFamilyHandle, List, IngestExternalFileOptions)} |
||||
* will fail if the file key range overlaps with existing keys or tombstones in the DB. |
||||
* |
||||
* @return true if global seq numbers are assured |
||||
*/ |
||||
public boolean allowGlobalSeqNo() { |
||||
return allowGlobalSeqNo(nativeHandle_); |
||||
} |
||||
|
||||
/** |
||||
* If set to false, {@link RocksDB#ingestExternalFile(ColumnFamilyHandle, List, IngestExternalFileOptions)} |
||||
* will fail if the file key range overlaps with existing keys or tombstones in the DB. |
||||
* |
||||
* @param allowGlobalSeqNo true if global seq numbers are required |
||||
*/ |
||||
public void setAllowGlobalSeqNo(final boolean allowGlobalSeqNo) { |
||||
setAllowGlobalSeqNo(nativeHandle_, allowGlobalSeqNo); |
||||
} |
||||
|
||||
/** |
||||
* If set to false and the file key range overlaps with the memtable key range |
||||
* (memtable flush required), IngestExternalFile will fail. |
||||
* |
||||
* @return true if blocking flushes may occur |
||||
*/ |
||||
public boolean allowBlockingFlush() { |
||||
return allowBlockingFlush(nativeHandle_); |
||||
} |
||||
|
||||
/** |
||||
* If set to false and the file key range overlaps with the memtable key range |
||||
* (memtable flush required), IngestExternalFile will fail. |
||||
* |
||||
* @param allowBlockingFlush true if blocking flushes are allowed |
||||
*/ |
||||
public void setAllowBlockingFlush(final boolean allowBlockingFlush) { |
||||
setAllowBlockingFlush(nativeHandle_, allowBlockingFlush); |
||||
} |
||||
|
||||
private native static long newIngestExternalFileOptions(); |
||||
private native static long newIngestExternalFileOptions( |
||||
final boolean moveFiles, final boolean snapshotConsistency, |
||||
final boolean allowGlobalSeqNo, final boolean allowBlockingFlush); |
||||
private native boolean moveFiles(final long handle); |
||||
private native void setMoveFiles(final long handle, final boolean move_files); |
||||
private native boolean snapshotConsistency(final long handle); |
||||
private native void setSnapshotConsistency(final long handle, |
||||
final boolean snapshotConsistency); |
||||
private native boolean allowGlobalSeqNo(final long handle); |
||||
private native void setAllowGlobalSeqNo(final long handle, |
||||
final boolean allowGloablSeqNo); |
||||
private native boolean allowBlockingFlush(final long handle); |
||||
private native void setAllowBlockingFlush(final long handle, |
||||
final boolean allowBlockingFlush); |
||||
@Override protected final native void disposeInternal(final long handle); |
||||
} |
@ -1,105 +0,0 @@ |
||||
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under the BSD-style license found in the
|
||||
// LICENSE file in the root directory of this source tree. An additional grant
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
package org.rocksdb; |
||||
|
||||
import org.junit.ClassRule; |
||||
import org.junit.Test; |
||||
|
||||
import java.util.Random; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
public class ExternalSstFileInfoTest { |
||||
@ClassRule |
||||
public static final RocksMemoryResource rocksMemoryResource = new RocksMemoryResource(); |
||||
|
||||
public static final Random rand = PlatformRandomHelper.getPlatformSpecificRandomFactory(); |
||||
|
||||
@Test |
||||
public void createExternalSstFileInfoWithoutParameters() { |
||||
try (final ExternalSstFileInfo info = new ExternalSstFileInfo()) { |
||||
assertThat(info).isNotNull(); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void createExternalSstFileInfoWithParameters() { |
||||
final String filePath = "path/to/sst"; |
||||
final String smallestKey = "min"; |
||||
final String largestKey = "max"; |
||||
final long sequenceNumber = rand.nextLong(); |
||||
final long fileSize = rand.nextLong(); |
||||
final int numEntries = rand.nextInt(); |
||||
final int version = rand.nextInt(); |
||||
try (final ExternalSstFileInfo info = new ExternalSstFileInfo( |
||||
filePath, smallestKey, largestKey, sequenceNumber, fileSize, numEntries, version)) { |
||||
assertThat(info).isNotNull(); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void filePath() { |
||||
try (final ExternalSstFileInfo info = new ExternalSstFileInfo()) { |
||||
final String stringVale = "path/to/sst"; |
||||
info.setFilePath(stringVale); |
||||
assertThat(info.filePath()).isEqualTo(stringVale); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void smallestKey() { |
||||
try (final ExternalSstFileInfo info = new ExternalSstFileInfo()) { |
||||
final String stringValue = "min"; |
||||
info.setSmallestKey(stringValue); |
||||
assertThat(info.smallestKey()).isEqualTo(stringValue); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void largestKey() { |
||||
try (final ExternalSstFileInfo info = new ExternalSstFileInfo()) { |
||||
final String stringValue = "max"; |
||||
info.setLargestKey(stringValue); |
||||
assertThat(info.largestKey()).isEqualTo(stringValue); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void sequenceNumber() { |
||||
try (final ExternalSstFileInfo info = new ExternalSstFileInfo()) { |
||||
final long longValue = rand.nextLong(); |
||||
info.setSequenceNumber(longValue); |
||||
assertThat(info.sequenceNumber()).isEqualTo(longValue); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void fileSize() { |
||||
try (final ExternalSstFileInfo info = new ExternalSstFileInfo()) { |
||||
final long longValue = Math.max(1, rand.nextLong()); |
||||
info.setFileSize(longValue); |
||||
assertThat(info.fileSize()).isEqualTo(longValue); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void numEntries() { |
||||
try (final ExternalSstFileInfo info = new ExternalSstFileInfo()) { |
||||
final int intValue = Math.max(1, rand.nextInt()); |
||||
info.setNumEntries(intValue); |
||||
assertThat(info.numEntries()).isEqualTo(intValue); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void version() { |
||||
try (final ExternalSstFileInfo info = new ExternalSstFileInfo()) { |
||||
final int intValue = rand.nextInt(); |
||||
info.setVersion(intValue); |
||||
assertThat(info.version()).isEqualTo(intValue); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,87 @@ |
||||
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under the BSD-style license found in the
|
||||
// LICENSE file in the root directory of this source tree. An additional grant
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
package org.rocksdb; |
||||
|
||||
import org.junit.ClassRule; |
||||
import org.junit.Test; |
||||
|
||||
import java.util.Random; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
public class IngestExternalFileOptionsTest { |
||||
@ClassRule |
||||
public static final RocksMemoryResource rocksMemoryResource |
||||
= new RocksMemoryResource(); |
||||
|
||||
public static final Random rand = |
||||
PlatformRandomHelper.getPlatformSpecificRandomFactory(); |
||||
|
||||
@Test |
||||
public void createExternalSstFileInfoWithoutParameters() { |
||||
try (final IngestExternalFileOptions options = |
||||
new IngestExternalFileOptions()) { |
||||
assertThat(options).isNotNull(); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void createExternalSstFileInfoWithParameters() { |
||||
final boolean moveFiles = rand.nextBoolean(); |
||||
final boolean snapshotConsistency = rand.nextBoolean(); |
||||
final boolean allowGlobalSeqNo = rand.nextBoolean(); |
||||
final boolean allowBlockingFlush = rand.nextBoolean(); |
||||
try (final IngestExternalFileOptions options = |
||||
new IngestExternalFileOptions(moveFiles, snapshotConsistency, |
||||
allowGlobalSeqNo, allowBlockingFlush)) { |
||||
assertThat(options).isNotNull(); |
||||
assertThat(options.moveFiles()).isEqualTo(moveFiles); |
||||
assertThat(options.snapshotConsistency()).isEqualTo(snapshotConsistency); |
||||
assertThat(options.allowGlobalSeqNo()).isEqualTo(allowGlobalSeqNo); |
||||
assertThat(options.allowBlockingFlush()).isEqualTo(allowBlockingFlush); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void moveFiles() { |
||||
try (final IngestExternalFileOptions options = |
||||
new IngestExternalFileOptions()) { |
||||
final boolean moveFiles = rand.nextBoolean(); |
||||
options.setMoveFiles(moveFiles); |
||||
assertThat(options.moveFiles()).isEqualTo(moveFiles); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void snapshotConsistency() { |
||||
try (final IngestExternalFileOptions options = |
||||
new IngestExternalFileOptions()) { |
||||
final boolean snapshotConsistency = rand.nextBoolean(); |
||||
options.setSnapshotConsistency(snapshotConsistency); |
||||
assertThat(options.snapshotConsistency()).isEqualTo(snapshotConsistency); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void allowGlobalSeqNo() { |
||||
try (final IngestExternalFileOptions options = |
||||
new IngestExternalFileOptions()) { |
||||
final boolean allowGlobalSeqNo = rand.nextBoolean(); |
||||
options.setAllowGlobalSeqNo(allowGlobalSeqNo); |
||||
assertThat(options.allowGlobalSeqNo()).isEqualTo(allowGlobalSeqNo); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void allowBlockingFlush() { |
||||
try (final IngestExternalFileOptions options = |
||||
new IngestExternalFileOptions()) { |
||||
final boolean allowBlockingFlush = rand.nextBoolean(); |
||||
options.setAllowBlockingFlush(allowBlockingFlush); |
||||
assertThat(options.allowBlockingFlush()).isEqualTo(allowBlockingFlush); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue