mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-29 18:33:58 +00:00
c6d464a9da
Summary: I have manually audited the entire RocksJava code base. Sorry for the large pull-request, I have broken it down into many small atomic commits though. My initial intention was to fix the warnings that appear when running RocksJava on Java 8 with `-Xcheck:jni`, for example when running `make jtest` you would see many errors similar to: ``` WARNING in native method: JNI call made without checking exceptions when required to from CallObjectMethod WARNING in native method: JNI call made without checking exceptions when required to from CallVoidMethod WARNING in native method: JNI call made without checking exceptions when required to from CallStaticVoidMethod ... ``` A few of those warnings still remain, however they seem to come directly from the JVM and are not directly related to RocksJava; I am in contact with the OpenJDK hostpot-dev mailing list about these - http://mail.openjdk.java.net/pipermail/hotspot-dev/2017-February/025981.html. As a result of fixing these, I realised we were not r Closes https://github.com/facebook/rocksdb/pull/1890 Differential Revision: D4591758 Pulled By: siying fbshipit-source-id: 7f7fdf4
100 lines
3.4 KiB
C++
100 lines
3.4 KiB
C++
// 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, nullptr);
|
|
if(file_path == nullptr) {
|
|
// exception thrown: OutOfMemoryError
|
|
return;
|
|
}
|
|
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);
|
|
}
|