forked from facebook/rocksdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added CompactionFilterFactory support to RocksJava
Summary: This PR also includes some cleanup, bugfixes and refactoring of the Java API. However these are really pre-cursors on the road to CompactionFilterFactory support. Closes facebook#1241 Differential Revision: D6012778 Pulled By: sagar0 fbshipit-source-id: 0774465940ee99001a78906e4fed4ef57068ad5c
- Loading branch information
1 parent
8dd0a7e
commit 560e984
Showing
34 changed files
with
917 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved. | ||
// This source code is licensed under both the GPLv2 (found in the | ||
// COPYING file in the root directory) and Apache 2.0 License | ||
// (found in the LICENSE.Apache file in the root directory). | ||
// | ||
// This file implements the "bridge" between Java and C++ for | ||
// rocksdb::CompactionFilterFactory. | ||
|
||
#include <jni.h> | ||
#include <memory> | ||
|
||
#include "include/org_rocksdb_AbstractCompactionFilterFactory.h" | ||
#include "rocksjni/compaction_filter_factory_jnicallback.h" | ||
|
||
/* | ||
* Class: org_rocksdb_AbstractCompactionFilterFactory | ||
* Method: createNewCompactionFilterFactory0 | ||
* Signature: ()J | ||
*/ | ||
jlong Java_org_rocksdb_AbstractCompactionFilterFactory_createNewCompactionFilterFactory0( | ||
JNIEnv* env, jobject jobj) { | ||
auto* cff = new rocksdb::CompactionFilterFactoryJniCallback(env, jobj); | ||
auto* ptr_sptr_cff = new std::shared_ptr<rocksdb::CompactionFilterFactoryJniCallback>(cff); | ||
return reinterpret_cast<jlong>(ptr_sptr_cff); | ||
} | ||
|
||
/* | ||
* Class: org_rocksdb_AbstractCompactionFilterFactory | ||
* Method: disposeInternal | ||
* Signature: (J)V | ||
*/ | ||
void Java_org_rocksdb_AbstractCompactionFilterFactory_disposeInternal( | ||
JNIEnv* env, jobject jobj, jlong jhandle) { | ||
auto* ptr_sptr_cff = | ||
reinterpret_cast<std::shared_ptr<rocksdb::CompactionFilterFactoryJniCallback> *>(jhandle); | ||
delete ptr_sptr_cff; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved. | ||
// This source code is licensed under both the GPLv2 (found in the | ||
// COPYING file in the root directory) and Apache 2.0 License | ||
// (found in the LICENSE.Apache file in the root directory). | ||
// | ||
// This file implements the callback "bridge" between Java and C++ for | ||
// rocksdb::CompactionFilterFactory. | ||
|
||
#include "rocksjni/compaction_filter_factory_jnicallback.h" | ||
#include "rocksjni/portal.h" | ||
|
||
namespace rocksdb { | ||
CompactionFilterFactoryJniCallback::CompactionFilterFactoryJniCallback( | ||
JNIEnv* env, jobject jcompaction_filter_factory) | ||
: JniCallback(env, jcompaction_filter_factory) { | ||
|
||
// Note: The name of a CompactionFilterFactory will not change during | ||
// it's lifetime, so we cache it in a global var | ||
jmethodID jname_method_id = | ||
AbstractCompactionFilterFactoryJni::getNameMethodId(env); | ||
if(jname_method_id == nullptr) { | ||
// exception thrown: NoSuchMethodException or OutOfMemoryError | ||
return; | ||
} | ||
|
||
jstring jname = | ||
(jstring)env->CallObjectMethod(m_jcallback_obj, jname_method_id); | ||
if(env->ExceptionCheck()) { | ||
// exception thrown | ||
return; | ||
} | ||
jboolean has_exception = JNI_FALSE; | ||
m_name = JniUtil::copyString(env, jname, &has_exception); // also releases jname | ||
if (has_exception == JNI_TRUE) { | ||
// exception thrown | ||
return; | ||
} | ||
|
||
m_jcreate_compaction_filter_methodid = | ||
AbstractCompactionFilterFactoryJni::getCreateCompactionFilterMethodId(env); | ||
if(m_jcreate_compaction_filter_methodid == nullptr) { | ||
// exception thrown: NoSuchMethodException or OutOfMemoryError | ||
return; | ||
} | ||
} | ||
|
||
const char* CompactionFilterFactoryJniCallback::Name() const { | ||
return m_name.get(); | ||
} | ||
|
||
std::unique_ptr<CompactionFilter> CompactionFilterFactoryJniCallback::CreateCompactionFilter( | ||
const CompactionFilter::Context& context) { | ||
jboolean attached_thread = JNI_FALSE; | ||
JNIEnv* env = getJniEnv(&attached_thread); | ||
assert(env != nullptr); | ||
|
||
jlong addr_compaction_filter = env->CallLongMethod(m_jcallback_obj, | ||
m_jcreate_compaction_filter_methodid, | ||
static_cast<jboolean>(context.is_full_compaction), | ||
static_cast<jboolean>(context.is_manual_compaction)); | ||
|
||
if(env->ExceptionCheck()) { | ||
// exception thrown from CallLongMethod | ||
env->ExceptionDescribe(); // print out exception to stderr | ||
releaseJniEnv(attached_thread); | ||
return nullptr; | ||
} | ||
|
||
auto* cff = reinterpret_cast<CompactionFilter*>(addr_compaction_filter); | ||
|
||
releaseJniEnv(attached_thread); | ||
|
||
return std::unique_ptr<CompactionFilter>(cff); | ||
} | ||
|
||
} // namespace rocksdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved. | ||
// This source code is licensed under both the GPLv2 (found in the | ||
// COPYING file in the root directory) and Apache 2.0 License | ||
// (found in the LICENSE.Apache file in the root directory). | ||
// | ||
// This file implements the callback "bridge" between Java and C++ for | ||
// rocksdb::CompactionFilterFactory. | ||
|
||
#ifndef JAVA_ROCKSJNI_COMPACTION_FILTER_FACTORY_JNICALLBACK_H_ | ||
#define JAVA_ROCKSJNI_COMPACTION_FILTER_FACTORY_JNICALLBACK_H_ | ||
|
||
#include <jni.h> | ||
#include <memory> | ||
|
||
#include "rocksdb/compaction_filter.h" | ||
#include "rocksjni/jnicallback.h" | ||
|
||
namespace rocksdb { | ||
|
||
class CompactionFilterFactoryJniCallback : public JniCallback, public CompactionFilterFactory { | ||
public: | ||
CompactionFilterFactoryJniCallback( | ||
JNIEnv* env, jobject jcompaction_filter_factory); | ||
virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter( | ||
const CompactionFilter::Context& context); | ||
virtual const char* Name() const; | ||
|
||
private: | ||
std::unique_ptr<const char[]> m_name; | ||
jmethodID m_jcreate_compaction_filter_methodid; | ||
}; | ||
|
||
} //namespace rocksdb | ||
|
||
#endif // JAVA_ROCKSJNI_COMPACTION_FILTER_FACTORY_JNICALLBACK_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.