-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Expose LoadLatestOptions, LoadOptionsFromFile and GetLatestOptionsFileName APIs in RocksJava #2898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,114 @@ | ||
| // 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++ and enables | ||
| // calling C++ rocksdb::OptionsUtil methods from Java side. | ||
|
|
||
| #include <jni.h> | ||
|
|
||
| #include "include/org_rocksdb_OptionsUtil.h" | ||
|
|
||
| #include "rocksdb/db.h" | ||
| #include "rocksdb/env.h" | ||
| #include "rocksdb/utilities/options_util.h" | ||
| #include "rocksjni/portal.h" | ||
|
|
||
| void build_column_family_descriptor_list( | ||
| JNIEnv* env, jobject jcfds, | ||
| std::vector<rocksdb::ColumnFamilyDescriptor>& cf_descs) { | ||
| jmethodID add_mid = rocksdb::ListJni::getListAddMethodId(env); | ||
| if (add_mid == nullptr) { | ||
| // exception occurred accessing method | ||
| return; | ||
| } | ||
|
|
||
| // Column family descriptor | ||
| for (rocksdb::ColumnFamilyDescriptor& cfd : cf_descs) { | ||
| // Construct a ColumnFamilyDescriptor java object | ||
| jobject jcfd = rocksdb::ColumnFamilyDescriptorJni::construct(env, &cfd); | ||
| if (env->ExceptionCheck()) { | ||
| // exception occurred constructing object | ||
| if (jcfd != nullptr) { | ||
| env->DeleteLocalRef(jcfd); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| // Add the object to java list. | ||
| jboolean rs = env->CallBooleanMethod(jcfds, add_mid, jcfd); | ||
| if (env->ExceptionCheck() || rs == JNI_FALSE) { | ||
| // exception occurred calling method, or could not add | ||
| if (jcfd != nullptr) { | ||
| env->DeleteLocalRef(jcfd); | ||
| } | ||
| return; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
| } | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| * Class: org_rocksdb_OptionsUtil | ||
| * Method: loadLatestOptions | ||
| * Signature: (Ljava/lang/String;JLjava/util/List;Z)V | ||
| */ | ||
| void Java_org_rocksdb_OptionsUtil_loadLatestOptions( | ||
| JNIEnv* env, jclass jcls, jstring jdbpath, jlong jenv_handle, | ||
| jlong jdb_opts_handle, jobject jcfds, jboolean ignore_unknown_options) { | ||
| const char* db_path = env->GetStringUTFChars(jdbpath, nullptr); | ||
| std::vector<rocksdb::ColumnFamilyDescriptor> cf_descs; | ||
| rocksdb::Status s = rocksdb::LoadLatestOptions( | ||
| db_path, reinterpret_cast<rocksdb::Env*>(jenv_handle), | ||
| reinterpret_cast<rocksdb::DBOptions*>(jdb_opts_handle), &cf_descs, | ||
| ignore_unknown_options); | ||
| env->ReleaseStringUTFChars(jdbpath, db_path); | ||
|
|
||
| if (!s.ok()) { | ||
| rocksdb::RocksDBExceptionJni::ThrowNew(env, s); | ||
| } | ||
|
|
||
| build_column_family_descriptor_list(env, jcfds, cf_descs); | ||
| } | ||
|
|
||
| /* | ||
| * Class: org_rocksdb_OptionsUtil | ||
| * Method: loadOptionsFromFile | ||
| * Signature: (Ljava/lang/String;JJLjava/util/List;Z)V | ||
| */ | ||
| void Java_org_rocksdb_OptionsUtil_loadOptionsFromFile( | ||
| JNIEnv* env, jclass jcls, jstring jopts_file_name, jlong jenv_handle, | ||
| jlong jdb_opts_handle, jobject jcfds, jboolean ignore_unknown_options) { | ||
| const char* opts_file_name = env->GetStringUTFChars(jopts_file_name, nullptr); | ||
| std::vector<rocksdb::ColumnFamilyDescriptor> cf_descs; | ||
| rocksdb::Status s = rocksdb::LoadOptionsFromFile( | ||
| opts_file_name, reinterpret_cast<rocksdb::Env*>(jenv_handle), | ||
| reinterpret_cast<rocksdb::DBOptions*>(jdb_opts_handle), &cf_descs, | ||
| ignore_unknown_options); | ||
| env->ReleaseStringUTFChars(jopts_file_name, opts_file_name); | ||
|
|
||
| if (!s.ok()) { | ||
| rocksdb::RocksDBExceptionJni::ThrowNew(env, s); | ||
| } | ||
|
|
||
| build_column_family_descriptor_list(env, jcfds, cf_descs); | ||
| } | ||
|
|
||
| /* | ||
| * Class: org_rocksdb_OptionsUtil | ||
| * Method: getLatestOptionsFileName | ||
| * Signature: (Ljava/lang/String;J)Ljava/lang/String; | ||
| */ | ||
| jstring Java_org_rocksdb_OptionsUtil_getLatestOptionsFileName( | ||
| JNIEnv* env, jclass jcls, jstring jdbpath, jlong jenv_handle) { | ||
| const char* db_path = env->GetStringUTFChars(jdbpath, nullptr); | ||
| std::string options_file_name; | ||
| if (db_path != nullptr) { | ||
| rocksdb::GetLatestOptionsFileName( | ||
| db_path, reinterpret_cast<rocksdb::Env*>(jenv_handle), | ||
| &options_file_name); | ||
| } | ||
| env->ReleaseStringUTFChars(jdbpath, db_path); | ||
|
|
||
| return env->NewStringUTF(options_file_name.c_str()); | ||
| } | ||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to clear the objects already put in cf_descs?