Add Java API for SstFileWriter. Closes https://github.com/facebook/rocksdb/issues/1248main
parent
26388247aa
commit
7260662b39
@ -0,0 +1,315 @@ |
||||
// 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::BackupableDB and rocksdb::BackupableDBOptions methods
|
||||
// from Java side.
|
||||
|
||||
#include <jni.h> |
||||
|
||||
#include "include/org_rocksdb_EnvOptions.h" |
||||
#include "rocksdb/env.h" |
||||
|
||||
#define ENV_OPTIONS_SET_BOOL(_jhandle, _opt) \ |
||||
reinterpret_cast<rocksdb::EnvOptions *>(_jhandle)->_opt = \
|
||||
static_cast<bool>(_opt) |
||||
|
||||
#define ENV_OPTIONS_SET_SIZE_T(_jhandle, _opt) \ |
||||
reinterpret_cast<rocksdb::EnvOptions *>(_jhandle)->_opt = \
|
||||
static_cast<size_t>(_opt) |
||||
|
||||
#define ENV_OPTIONS_SET_UINT64_T(_jhandle, _opt) \ |
||||
reinterpret_cast<rocksdb::EnvOptions *>(_jhandle)->_opt = \
|
||||
static_cast<uint64_t>(_opt) |
||||
|
||||
#define ENV_OPTIONS_GET(_jhandle, _opt) \ |
||||
reinterpret_cast<rocksdb::EnvOptions *>(_jhandle)->_opt |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: newEnvOptions |
||||
* Signature: ()J |
||||
*/ |
||||
jlong Java_org_rocksdb_EnvOptions_newEnvOptions(JNIEnv *env, jclass jcls) { |
||||
auto *env_opt = new rocksdb::EnvOptions(); |
||||
return reinterpret_cast<jlong>(env_opt); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: disposeInternal |
||||
* Signature: (J)V |
||||
*/ |
||||
void Java_org_rocksdb_EnvOptions_disposeInternal(JNIEnv *env, jobject jobj, |
||||
jlong jhandle) { |
||||
delete reinterpret_cast<rocksdb::EnvOptions *>(jhandle); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: setUseOsBuffer |
||||
* Signature: (JZ)V |
||||
*/ |
||||
void Java_org_rocksdb_EnvOptions_setUseOsBuffer(JNIEnv *env, jobject jobj, |
||||
jlong jhandle, |
||||
jboolean use_os_buffer) { |
||||
ENV_OPTIONS_SET_BOOL(jhandle, use_os_buffer); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: useOsBuffer |
||||
* Signature: (J)Z |
||||
*/ |
||||
jboolean Java_org_rocksdb_EnvOptions_useOsBuffer(JNIEnv *env, jobject jobj, |
||||
jlong jhandle) { |
||||
return ENV_OPTIONS_GET(jhandle, use_os_buffer); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: setUseMmapReads |
||||
* Signature: (JZ)V |
||||
*/ |
||||
void Java_org_rocksdb_EnvOptions_setUseMmapReads(JNIEnv *env, jobject jobj, |
||||
jlong jhandle, |
||||
jboolean use_mmap_reads) { |
||||
ENV_OPTIONS_SET_BOOL(jhandle, use_mmap_reads); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: useMmapReads |
||||
* Signature: (J)Z |
||||
*/ |
||||
jboolean Java_org_rocksdb_EnvOptions_useMmapReads(JNIEnv *env, jobject jobj, |
||||
jlong jhandle) { |
||||
return ENV_OPTIONS_GET(jhandle, use_mmap_reads); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: setUseMmapWrites |
||||
* Signature: (JZ)V |
||||
*/ |
||||
void Java_org_rocksdb_EnvOptions_setUseMmapWrites(JNIEnv *env, jobject jobj, |
||||
jlong jhandle, |
||||
jboolean use_mmap_writes) { |
||||
ENV_OPTIONS_SET_BOOL(jhandle, use_mmap_writes); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: useMmapWrites |
||||
* Signature: (J)Z |
||||
*/ |
||||
jboolean Java_org_rocksdb_EnvOptions_useMmapWrites(JNIEnv *env, jobject jobj, |
||||
jlong jhandle) { |
||||
return ENV_OPTIONS_GET(jhandle, use_mmap_writes); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: setUseDirectReads |
||||
* Signature: (JZ)V |
||||
*/ |
||||
void Java_org_rocksdb_EnvOptions_setUseDirectReads(JNIEnv *env, jobject jobj, |
||||
jlong jhandle, |
||||
jboolean use_direct_reads) { |
||||
ENV_OPTIONS_SET_BOOL(jhandle, use_direct_reads); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: useDirectReads |
||||
* Signature: (J)Z |
||||
*/ |
||||
jboolean Java_org_rocksdb_EnvOptions_useDirectReads(JNIEnv *env, jobject jobj, |
||||
jlong jhandle) { |
||||
return ENV_OPTIONS_GET(jhandle, use_direct_reads); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: setUseDirectWrites |
||||
* Signature: (JZ)V |
||||
*/ |
||||
void Java_org_rocksdb_EnvOptions_setUseDirectWrites( |
||||
JNIEnv *env, jobject jobj, jlong jhandle, jboolean use_direct_writes) { |
||||
ENV_OPTIONS_SET_BOOL(jhandle, use_direct_writes); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: useDirectWrites |
||||
* Signature: (J)Z |
||||
*/ |
||||
jboolean Java_org_rocksdb_EnvOptions_useDirectWrites(JNIEnv *env, jobject jobj, |
||||
jlong jhandle) { |
||||
return ENV_OPTIONS_GET(jhandle, use_direct_writes); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: setAllowFallocate |
||||
* Signature: (JZ)V |
||||
*/ |
||||
void Java_org_rocksdb_EnvOptions_setAllowFallocate(JNIEnv *env, jobject jobj, |
||||
jlong jhandle, |
||||
jboolean allow_fallocate) { |
||||
ENV_OPTIONS_SET_BOOL(jhandle, allow_fallocate); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: allowFallocate |
||||
* Signature: (J)Z |
||||
*/ |
||||
jboolean Java_org_rocksdb_EnvOptions_allowFallocate(JNIEnv *env, jobject jobj, |
||||
jlong jhandle) { |
||||
return ENV_OPTIONS_GET(jhandle, allow_fallocate); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: setSetFdCloexec |
||||
* Signature: (JZ)V |
||||
*/ |
||||
void Java_org_rocksdb_EnvOptions_setSetFdCloexec(JNIEnv *env, jobject jobj, |
||||
jlong jhandle, |
||||
jboolean set_fd_cloexec) { |
||||
ENV_OPTIONS_SET_BOOL(jhandle, set_fd_cloexec); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: setFdCloexec |
||||
* Signature: (J)Z |
||||
*/ |
||||
jboolean Java_org_rocksdb_EnvOptions_setFdCloexec(JNIEnv *env, jobject jobj, |
||||
jlong jhandle) { |
||||
return ENV_OPTIONS_GET(jhandle, set_fd_cloexec); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: setBytesPerSync |
||||
* Signature: (JJ)V |
||||
*/ |
||||
void Java_org_rocksdb_EnvOptions_setBytesPerSync(JNIEnv *env, jobject jobj, |
||||
jlong jhandle, |
||||
jlong bytes_per_sync) { |
||||
ENV_OPTIONS_SET_UINT64_T(jhandle, bytes_per_sync); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: bytesPerSync |
||||
* Signature: (J)J |
||||
*/ |
||||
jlong Java_org_rocksdb_EnvOptions_bytesPerSync(JNIEnv *env, jobject jobj, |
||||
jlong jhandle) { |
||||
return ENV_OPTIONS_GET(jhandle, bytes_per_sync); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: setFallocateWithKeepSize |
||||
* Signature: (JZ)V |
||||
*/ |
||||
void Java_org_rocksdb_EnvOptions_setFallocateWithKeepSize( |
||||
JNIEnv *env, jobject jobj, jlong jhandle, |
||||
jboolean fallocate_with_keep_size) { |
||||
ENV_OPTIONS_SET_BOOL(jhandle, fallocate_with_keep_size); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: fallocateWithKeepSize |
||||
* Signature: (J)Z |
||||
*/ |
||||
jboolean Java_org_rocksdb_EnvOptions_fallocateWithKeepSize(JNIEnv *env, |
||||
jobject jobj, |
||||
jlong jhandle) { |
||||
return ENV_OPTIONS_GET(jhandle, fallocate_with_keep_size); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: setCompactionReadaheadSize |
||||
* Signature: (JJ)V |
||||
*/ |
||||
void Java_org_rocksdb_EnvOptions_setCompactionReadaheadSize( |
||||
JNIEnv *env, jobject jobj, jlong jhandle, jlong compaction_readahead_size) { |
||||
ENV_OPTIONS_SET_SIZE_T(jhandle, compaction_readahead_size); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: compactionReadaheadSize |
||||
* Signature: (J)J |
||||
*/ |
||||
jlong Java_org_rocksdb_EnvOptions_compactionReadaheadSize(JNIEnv *env, |
||||
jobject jobj, |
||||
jlong jhandle) { |
||||
return ENV_OPTIONS_GET(jhandle, compaction_readahead_size); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: setRandomAccessMaxBufferSize |
||||
* Signature: (JJ)V |
||||
*/ |
||||
void Java_org_rocksdb_EnvOptions_setRandomAccessMaxBufferSize( |
||||
JNIEnv *env, jobject jobj, jlong jhandle, |
||||
jlong random_access_max_buffer_size) { |
||||
ENV_OPTIONS_SET_SIZE_T(jhandle, random_access_max_buffer_size); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: randomAccessMaxBufferSize |
||||
* Signature: (J)J |
||||
*/ |
||||
jlong Java_org_rocksdb_EnvOptions_randomAccessMaxBufferSize(JNIEnv *env, |
||||
jobject jobj, |
||||
jlong jhandle) { |
||||
return ENV_OPTIONS_GET(jhandle, random_access_max_buffer_size); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: setWritableFileMaxBufferSize |
||||
* Signature: (JJ)V |
||||
*/ |
||||
void Java_org_rocksdb_EnvOptions_setWritableFileMaxBufferSize( |
||||
JNIEnv *env, jobject jobj, jlong jhandle, |
||||
jlong writable_file_max_buffer_size) { |
||||
ENV_OPTIONS_SET_SIZE_T(jhandle, writable_file_max_buffer_size); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: writableFileMaxBufferSize |
||||
* Signature: (J)J |
||||
*/ |
||||
jlong Java_org_rocksdb_EnvOptions_writableFileMaxBufferSize(JNIEnv *env, |
||||
jobject jobj, |
||||
jlong jhandle) { |
||||
return ENV_OPTIONS_GET(jhandle, writable_file_max_buffer_size); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_EnvOptions |
||||
* Method: setRateLimiter |
||||
* Signature: (JJ)V |
||||
*/ |
||||
void Java_org_rocksdb_EnvOptions_setRateLimiter(JNIEnv *env, jobject jobj, |
||||
jlong jhandle, |
||||
jlong rl_handle) { |
||||
auto *rate_limiter = reinterpret_cast<rocksdb::RateLimiter *>(rl_handle); |
||||
auto *env_opt = reinterpret_cast<rocksdb::EnvOptions *>(jhandle); |
||||
env_opt->rate_limiter = rate_limiter; |
||||
} |
@ -0,0 +1,242 @@ |
||||
// 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::BackupableDB and rocksdb::BackupableDBOptions 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, NULL); |
||||
const char *smallest_key = env->GetStringUTFChars(jsmallest_key, NULL); |
||||
const char *largest_key = env->GetStringUTFChars(jlargest_key, NULL); |
||||
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(jfile_path, file_path); |
||||
env->ReleaseStringUTFChars(jsmallest_key, smallest_key); |
||||
env->ReleaseStringUTFChars(jlargest_key, largest_key); |
||||
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, NULL); |
||||
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, NULL); |
||||
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); |
||||
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) { |
||||
delete reinterpret_cast<rocksdb::ExternalSstFileInfo *>(jhandle); |
||||
} |
@ -0,0 +1,94 @@ |
||||
// 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::BackupableDB and rocksdb::BackupableDBOptions methods
|
||||
// from Java side.
|
||||
|
||||
#include <jni.h> |
||||
#include <string> |
||||
|
||||
#include "include/org_rocksdb_SstFileWriter.h" |
||||
#include "rocksdb/comparator.h" |
||||
#include "rocksdb/env.h" |
||||
#include "rocksdb/options.h" |
||||
#include "rocksdb/sst_file_writer.h" |
||||
#include "rocksjni/portal.h" |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_SstFileWriter |
||||
* Method: newSstFileWriter |
||||
* Signature: (JJJ)J |
||||
*/ |
||||
jlong Java_org_rocksdb_SstFileWriter_newSstFileWriter(JNIEnv *env, jclass jcls, |
||||
jlong jenvoptions, |
||||
jlong joptions, |
||||
jlong jcomparator) { |
||||
auto *env_options = |
||||
reinterpret_cast<const rocksdb::EnvOptions *>(jenvoptions); |
||||
auto *options = reinterpret_cast<const rocksdb::Options *>(joptions); |
||||
auto *comparator = reinterpret_cast<const rocksdb::Comparator *>(jcomparator); |
||||
rocksdb::SstFileWriter *sst_file_writer = |
||||
new rocksdb::SstFileWriter(*env_options, *options, comparator); |
||||
return reinterpret_cast<jlong>(sst_file_writer); |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_SstFileWriter |
||||
* Method: open |
||||
* Signature: (JLjava/lang/String;)V |
||||
*/ |
||||
void Java_org_rocksdb_SstFileWriter_open(JNIEnv *env, jobject jobj, |
||||
jlong jhandle, jstring jfile_path) { |
||||
const char *file_path = env->GetStringUTFChars(jfile_path, NULL); |
||||
rocksdb::Status s = |
||||
reinterpret_cast<rocksdb::SstFileWriter *>(jhandle)->Open(file_path); |
||||
env->ReleaseStringUTFChars(jfile_path, file_path); |
||||
|
||||
if (!s.ok()) { |
||||
rocksdb::RocksDBExceptionJni::ThrowNew(env, s); |
||||
} |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_SstFileWriter |
||||
* Method: add |
||||
* Signature: (JJJ)V |
||||
*/ |
||||
void Java_org_rocksdb_SstFileWriter_add(JNIEnv *env, jobject jobj, |
||||
jlong jhandle, jlong jkey_handle, |
||||
jlong jvalue_handle) { |
||||
auto *key_slice = reinterpret_cast<rocksdb::Slice *>(jkey_handle); |
||||
auto *value_slice = reinterpret_cast<rocksdb::Slice *>(jvalue_handle); |
||||
rocksdb::Status s = reinterpret_cast<rocksdb::SstFileWriter *>(jhandle)->Add( |
||||
*key_slice, *value_slice); |
||||
if (!s.ok()) { |
||||
rocksdb::RocksDBExceptionJni::ThrowNew(env, s); |
||||
} |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_SstFileWriter |
||||
* Method: finish |
||||
* Signature: (J)V |
||||
*/ |
||||
void Java_org_rocksdb_SstFileWriter_finish(JNIEnv *env, jobject jobj, |
||||
jlong jhandle) { |
||||
rocksdb::Status s = |
||||
reinterpret_cast<rocksdb::SstFileWriter *>(jhandle)->Finish(); |
||||
if (!s.ok()) { |
||||
rocksdb::RocksDBExceptionJni::ThrowNew(env, s); |
||||
} |
||||
} |
||||
|
||||
/*
|
||||
* Class: org_rocksdb_SstFileWriter |
||||
* Method: disposeInternal |
||||
* Signature: (J)V |
||||
*/ |
||||
void Java_org_rocksdb_SstFileWriter_disposeInternal(JNIEnv *env, jobject jobj, |
||||
jlong jhandle) { |
||||
delete reinterpret_cast<rocksdb::SstFileWriter *>(jhandle); |
||||
} |
@ -0,0 +1,207 @@ |
||||
// 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; |
||||
|
||||
public class EnvOptions extends RocksObject { |
||||
static { |
||||
RocksDB.loadLibrary(); |
||||
} |
||||
|
||||
public EnvOptions() { |
||||
super(newEnvOptions()); |
||||
} |
||||
|
||||
public EnvOptions setUseOsBuffer(final boolean useOsBuffer) { |
||||
setUseOsBuffer(nativeHandle_, useOsBuffer); |
||||
return this; |
||||
} |
||||
|
||||
public boolean useOsBuffer() { |
||||
assert(isOwningHandle()); |
||||
return useOsBuffer(nativeHandle_); |
||||
} |
||||
|
||||
public EnvOptions setUseMmapReads(final boolean useMmapReads) { |
||||
setUseMmapReads(nativeHandle_, useMmapReads); |
||||
return this; |
||||
} |
||||
|
||||
public boolean useMmapReads() { |
||||
assert(isOwningHandle()); |
||||
return useMmapReads(nativeHandle_); |
||||
} |
||||
|
||||
public EnvOptions setUseMmapWrites(final boolean useMmapWrites) { |
||||
setUseMmapWrites(nativeHandle_, useMmapWrites); |
||||
return this; |
||||
} |
||||
|
||||
public boolean useMmapWrites() { |
||||
assert(isOwningHandle()); |
||||
return useMmapWrites(nativeHandle_); |
||||
} |
||||
|
||||
public EnvOptions setUseDirectReads(final boolean useDirectReads) { |
||||
setUseDirectReads(nativeHandle_, useDirectReads); |
||||
return this; |
||||
} |
||||
|
||||
public boolean useDirectReads() { |
||||
assert(isOwningHandle()); |
||||
return useDirectReads(nativeHandle_); |
||||
} |
||||
|
||||
public EnvOptions setUseDirectWrites(final boolean useDirectWrites) { |
||||
setUseDirectWrites(nativeHandle_, useDirectWrites); |
||||
return this; |
||||
} |
||||
|
||||
public boolean useDirectWrites() { |
||||
assert(isOwningHandle()); |
||||
return useDirectWrites(nativeHandle_); |
||||
} |
||||
|
||||
public EnvOptions setAllowFallocate(final boolean allowFallocate) { |
||||
setAllowFallocate(nativeHandle_, allowFallocate); |
||||
return this; |
||||
} |
||||
|
||||
public boolean allowFallocate() { |
||||
assert(isOwningHandle()); |
||||
return allowFallocate(nativeHandle_); |
||||
} |
||||
|
||||
public EnvOptions setSetFdCloexec(final boolean setFdCloexec) { |
||||
setSetFdCloexec(nativeHandle_, setFdCloexec); |
||||
return this; |
||||
} |
||||
|
||||
public boolean setFdCloexec() { |
||||
assert(isOwningHandle()); |
||||
return setFdCloexec(nativeHandle_); |
||||
} |
||||
|
||||
public EnvOptions setBytesPerSync(final long bytesPerSync) { |
||||
setBytesPerSync(nativeHandle_, bytesPerSync); |
||||
return this; |
||||
} |
||||
|
||||
public long bytesPerSync() { |
||||
assert(isOwningHandle()); |
||||
return bytesPerSync(nativeHandle_); |
||||
} |
||||
|
||||
public EnvOptions setFallocateWithKeepSize(final boolean fallocateWithKeepSize) { |
||||
setFallocateWithKeepSize(nativeHandle_, fallocateWithKeepSize); |
||||
return this; |
||||
} |
||||
|
||||
public boolean fallocateWithKeepSize() { |
||||
assert(isOwningHandle()); |
||||
return fallocateWithKeepSize(nativeHandle_); |
||||
} |
||||
|
||||
public EnvOptions setCompactionReadaheadSize(final long compactionReadaheadSize) { |
||||
setCompactionReadaheadSize(nativeHandle_, compactionReadaheadSize); |
||||
return this; |
||||
} |
||||
|
||||
public long compactionReadaheadSize() { |
||||
assert(isOwningHandle()); |
||||
return compactionReadaheadSize(nativeHandle_); |
||||
} |
||||
|
||||
public EnvOptions setRandomAccessMaxBufferSize(final long randomAccessMaxBufferSize) { |
||||
setRandomAccessMaxBufferSize(nativeHandle_, randomAccessMaxBufferSize); |
||||
return this; |
||||
} |
||||
|
||||
public long randomAccessMaxBufferSize() { |
||||
assert(isOwningHandle()); |
||||
return randomAccessMaxBufferSize(nativeHandle_); |
||||
} |
||||
|
||||
public EnvOptions setWritableFileMaxBufferSize(final long writableFileMaxBufferSize) { |
||||
setWritableFileMaxBufferSize(nativeHandle_, writableFileMaxBufferSize); |
||||
return this; |
||||
} |
||||
|
||||
public long writableFileMaxBufferSize() { |
||||
assert(isOwningHandle()); |
||||
return writableFileMaxBufferSize(nativeHandle_); |
||||
} |
||||
|
||||
public EnvOptions setRateLimiterConfig(final RateLimiterConfig rateLimiterConfig) { |
||||
this.rateLimiterConfig = rateLimiterConfig; |
||||
setRateLimiter(nativeHandle_, rateLimiterConfig.newRateLimiterHandle()); |
||||
return this; |
||||
} |
||||
|
||||
public RateLimiterConfig rateLimiterConfig() { |
||||
assert(isOwningHandle()); |
||||
return rateLimiterConfig; |
||||
} |
||||
|
||||
private native static long newEnvOptions(); |
||||
|
||||
@Override protected final native void disposeInternal(final long handle); |
||||
|
||||
private native void setUseOsBuffer(final long handle, final boolean useOsBuffer); |
||||
|
||||
private native boolean useOsBuffer(final long handle); |
||||
|
||||
private native void setUseMmapReads(final long handle, final boolean useMmapReads); |
||||
|
||||
private native boolean useMmapReads(final long handle); |
||||
|
||||
private native void setUseMmapWrites(final long handle, final boolean useMmapWrites); |
||||
|
||||
private native boolean useMmapWrites(final long handle); |
||||
|
||||
private native void setUseDirectReads(final long handle, final boolean useDirectReads); |
||||
|
||||
private native boolean useDirectReads(final long handle); |
||||
|
||||
private native void setUseDirectWrites(final long handle, final boolean useDirectWrites); |
||||
|
||||
private native boolean useDirectWrites(final long handle); |
||||
|
||||
private native void setAllowFallocate(final long handle, final boolean allowFallocate); |
||||
|
||||
private native boolean allowFallocate(final long handle); |
||||
|
||||
private native void setSetFdCloexec(final long handle, final boolean setFdCloexec); |
||||
|
||||
private native boolean setFdCloexec(final long handle); |
||||
|
||||
private native void setBytesPerSync(final long handle, final long bytesPerSync); |
||||
|
||||
private native long bytesPerSync(final long handle); |
||||
|
||||
private native void setFallocateWithKeepSize( |
||||
final long handle, final boolean fallocateWithKeepSize); |
||||
|
||||
private native boolean fallocateWithKeepSize(final long handle); |
||||
|
||||
private native void setCompactionReadaheadSize( |
||||
final long handle, final long compactionReadaheadSize); |
||||
|
||||
private native long compactionReadaheadSize(final long handle); |
||||
|
||||
private native void setRandomAccessMaxBufferSize( |
||||
final long handle, final long randomAccessMaxBufferSize); |
||||
|
||||
private native long randomAccessMaxBufferSize(final long handle); |
||||
|
||||
private native void setWritableFileMaxBufferSize( |
||||
final long handle, final long writableFileMaxBufferSize); |
||||
|
||||
private native long writableFileMaxBufferSize(final long handle); |
||||
|
||||
private native void setRateLimiter(final long handle, final long rateLimiterHandle); |
||||
|
||||
private RateLimiterConfig rateLimiterConfig; |
||||
} |
@ -0,0 +1,135 @@ |
||||
// 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,46 @@ |
||||
// 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; |
||||
|
||||
public class SstFileWriter extends RocksObject { |
||||
static { |
||||
RocksDB.loadLibrary(); |
||||
} |
||||
|
||||
public SstFileWriter(final EnvOptions envOptions, final Options options, |
||||
final AbstractComparator<? extends AbstractSlice<?>> comparator) { |
||||
super(newSstFileWriter( |
||||
envOptions.nativeHandle_, options.nativeHandle_, comparator.getNativeHandle())); |
||||
} |
||||
|
||||
public void open(final String filePath) throws RocksDBException { |
||||
open(nativeHandle_, filePath); |
||||
} |
||||
|
||||
public void add(final Slice key, final Slice value) throws RocksDBException { |
||||
add(nativeHandle_, key.getNativeHandle(), value.getNativeHandle()); |
||||
} |
||||
|
||||
public void add(final DirectSlice key, final DirectSlice value) throws RocksDBException { |
||||
add(nativeHandle_, key.getNativeHandle(), value.getNativeHandle()); |
||||
} |
||||
|
||||
public void finish() throws RocksDBException { |
||||
finish(nativeHandle_); |
||||
} |
||||
|
||||
private native static long newSstFileWriter( |
||||
final long envOptionsHandle, final long optionsHandle, final long userComparatorHandle); |
||||
|
||||
private native void open(final long handle, final String filePath) throws RocksDBException; |
||||
|
||||
private native void add(final long handle, final long keyHandle, final long valueHandle) |
||||
throws RocksDBException; |
||||
|
||||
private native void finish(final long handle) throws RocksDBException; |
||||
|
||||
@Override protected final native void disposeInternal(final long handle); |
||||
} |
@ -0,0 +1,142 @@ |
||||
// 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 EnvOptionsTest { |
||||
@ClassRule |
||||
public static final RocksMemoryResource rocksMemoryResource = new RocksMemoryResource(); |
||||
|
||||
public static final Random rand = PlatformRandomHelper.getPlatformSpecificRandomFactory(); |
||||
|
||||
@Test |
||||
public void useOsBuffer() { |
||||
try (final EnvOptions envOptions = new EnvOptions()) { |
||||
final boolean boolValue = rand.nextBoolean(); |
||||
envOptions.setUseOsBuffer(boolValue); |
||||
assertThat(envOptions.useOsBuffer()).isEqualTo(boolValue); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void useMmapReads() { |
||||
try (final EnvOptions envOptions = new EnvOptions()) { |
||||
final boolean boolValue = rand.nextBoolean(); |
||||
envOptions.setUseMmapReads(boolValue); |
||||
assertThat(envOptions.useMmapReads()).isEqualTo(boolValue); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void useMmapWrites() { |
||||
try (final EnvOptions envOptions = new EnvOptions()) { |
||||
final boolean boolValue = rand.nextBoolean(); |
||||
envOptions.setUseMmapWrites(boolValue); |
||||
assertThat(envOptions.useMmapWrites()).isEqualTo(boolValue); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void useDirectReads() { |
||||
try (final EnvOptions envOptions = new EnvOptions()) { |
||||
final boolean boolValue = rand.nextBoolean(); |
||||
envOptions.setUseDirectReads(boolValue); |
||||
assertThat(envOptions.useDirectReads()).isEqualTo(boolValue); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void useDirectWrites() { |
||||
try (final EnvOptions envOptions = new EnvOptions()) { |
||||
final boolean boolValue = rand.nextBoolean(); |
||||
envOptions.setUseDirectWrites(boolValue); |
||||
assertThat(envOptions.useDirectWrites()).isEqualTo(boolValue); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void allowFallocate() { |
||||
try (final EnvOptions envOptions = new EnvOptions()) { |
||||
final boolean boolValue = rand.nextBoolean(); |
||||
envOptions.setAllowFallocate(boolValue); |
||||
assertThat(envOptions.allowFallocate()).isEqualTo(boolValue); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void setFdCloexecs() { |
||||
try (final EnvOptions envOptions = new EnvOptions()) { |
||||
final boolean boolValue = rand.nextBoolean(); |
||||
envOptions.setSetFdCloexec(boolValue); |
||||
assertThat(envOptions.setFdCloexec()).isEqualTo(boolValue); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void bytesPerSync() { |
||||
try (final EnvOptions envOptions = new EnvOptions()) { |
||||
final long longValue = rand.nextLong(); |
||||
envOptions.setBytesPerSync(longValue); |
||||
assertThat(envOptions.bytesPerSync()).isEqualTo(longValue); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void fallocateWithKeepSize() { |
||||
try (final EnvOptions envOptions = new EnvOptions()) { |
||||
final boolean boolValue = rand.nextBoolean(); |
||||
envOptions.setFallocateWithKeepSize(boolValue); |
||||
assertThat(envOptions.fallocateWithKeepSize()).isEqualTo(boolValue); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void compactionReadaheadSize() { |
||||
try (final EnvOptions envOptions = new EnvOptions()) { |
||||
final int intValue = rand.nextInt(); |
||||
envOptions.setCompactionReadaheadSize(intValue); |
||||
assertThat(envOptions.compactionReadaheadSize()).isEqualTo(intValue); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void randomAccessMaxBufferSize() { |
||||
try (final EnvOptions envOptions = new EnvOptions()) { |
||||
final int intValue = rand.nextInt(); |
||||
envOptions.setRandomAccessMaxBufferSize(intValue); |
||||
assertThat(envOptions.randomAccessMaxBufferSize()).isEqualTo(intValue); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void writableFileMaxBufferSize() { |
||||
try (final EnvOptions envOptions = new EnvOptions()) { |
||||
final int intValue = rand.nextInt(); |
||||
envOptions.setWritableFileMaxBufferSize(intValue); |
||||
assertThat(envOptions.writableFileMaxBufferSize()).isEqualTo(intValue); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void rateLimiterConfig() { |
||||
try (final EnvOptions envOptions = new EnvOptions()) { |
||||
final RateLimiterConfig rateLimiterConfig1 = |
||||
new GenericRateLimiterConfig(1000, 100 * 1000, 1); |
||||
envOptions.setRateLimiterConfig(rateLimiterConfig1); |
||||
assertThat(envOptions.rateLimiterConfig()).isEqualTo(rateLimiterConfig1); |
||||
|
||||
final RateLimiterConfig rateLimiterConfig2 = new GenericRateLimiterConfig(1000); |
||||
envOptions.setRateLimiterConfig(rateLimiterConfig2); |
||||
assertThat(envOptions.rateLimiterConfig()).isEqualTo(rateLimiterConfig2); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,105 @@ |
||||
// 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,84 @@ |
||||
// 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.Rule; |
||||
import org.junit.Test; |
||||
import org.junit.rules.TemporaryFolder; |
||||
import org.rocksdb.util.BytewiseComparator; |
||||
|
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.util.Map; |
||||
import java.util.TreeMap; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
public class SstFileWriterTest { |
||||
private static final String SST_FILE_NAME = "test.sst"; |
||||
private static final String DB_DIRECTORY_NAME = "test_db"; |
||||
|
||||
@ClassRule |
||||
public static final RocksMemoryResource rocksMemoryResource = new RocksMemoryResource(); |
||||
|
||||
@Rule public TemporaryFolder parentFolder = new TemporaryFolder(); |
||||
|
||||
private File newSstFile(final TreeMap<String, String> keyValues) |
||||
throws IOException, RocksDBException { |
||||
final EnvOptions envOptions = new EnvOptions(); |
||||
final ComparatorOptions comparatorOptions = new ComparatorOptions(); |
||||
final BytewiseComparator comparator = new BytewiseComparator(comparatorOptions); |
||||
final Options options = new Options().setComparator(comparator); |
||||
final SstFileWriter sstFileWriter = new SstFileWriter(envOptions, options, comparator); |
||||
final File sstFile = parentFolder.newFile(SST_FILE_NAME); |
||||
try { |
||||
sstFileWriter.open(sstFile.getAbsolutePath()); |
||||
for (Map.Entry<String, String> keyValue : keyValues.entrySet()) { |
||||
Slice keySlice = new Slice(keyValue.getKey()); |
||||
Slice valueSlice = new Slice(keyValue.getValue()); |
||||
sstFileWriter.add(keySlice, valueSlice); |
||||
keySlice.close(); |
||||
valueSlice.close(); |
||||
} |
||||
sstFileWriter.finish(); |
||||
} finally { |
||||
assertThat(sstFileWriter).isNotNull(); |
||||
sstFileWriter.close(); |
||||
options.close(); |
||||
envOptions.close(); |
||||
comparatorOptions.close(); |
||||
comparator.close(); |
||||
} |
||||
return sstFile; |
||||
} |
||||
|
||||
@Test |
||||
public void generateSstFile() throws RocksDBException, IOException { |
||||
final TreeMap<String, String> keyValues = new TreeMap<>(); |
||||
keyValues.put("key1", "value1"); |
||||
keyValues.put("key2", "value2"); |
||||
newSstFile(keyValues); |
||||
} |
||||
|
||||
@Test |
||||
public void ingestSstFile() throws RocksDBException, IOException { |
||||
final TreeMap<String, String> keyValues = new TreeMap<>(); |
||||
keyValues.put("key1", "value1"); |
||||
keyValues.put("key2", "value2"); |
||||
final File sstFile = newSstFile(keyValues); |
||||
final File dbFolder = parentFolder.newFolder(DB_DIRECTORY_NAME); |
||||
final Options options = new Options().setCreateIfMissing(true); |
||||
final RocksDB db = RocksDB.open(options, dbFolder.getAbsolutePath()); |
||||
db.addFileWithFilePath(sstFile.getAbsolutePath()); |
||||
|
||||
assertThat(db.get("key1".getBytes())).isEqualTo("value1".getBytes()); |
||||
assertThat(db.get("key2".getBytes())).isEqualTo("value2".getBytes()); |
||||
|
||||
options.close(); |
||||
db.close(); |
||||
} |
||||
} |
Loading…
Reference in new issue