]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/rocksjni/persistent_cache.cc
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / rocksdb / java / rocksjni / persistent_cache.cc
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
5 //
6 // This file implements the "bridge" between Java and C++ for
7 // rocksdb::PersistentCache.
8
9 #include <jni.h>
10 #include <string>
11
12 #include "include/org_rocksdb_PersistentCache.h"
13 #include "rocksdb/persistent_cache.h"
14 #include "loggerjnicallback.h"
15 #include "portal.h"
16
17 /*
18 * Class: org_rocksdb_PersistentCache
19 * Method: newPersistentCache
20 * Signature: (JLjava/lang/String;JJZ)J
21 */
22 jlong Java_org_rocksdb_PersistentCache_newPersistentCache(
23 JNIEnv* env, jclass, jlong jenv_handle, jstring jpath,
24 jlong jsz, jlong jlogger_handle, jboolean joptimized_for_nvm) {
25 auto* rocks_env = reinterpret_cast<rocksdb::Env*>(jenv_handle);
26 jboolean has_exception = JNI_FALSE;
27 std::string path = rocksdb::JniUtil::copyStdString(env, jpath, &has_exception);
28 if (has_exception == JNI_TRUE) {
29 return 0;
30 }
31 auto* logger =
32 reinterpret_cast<std::shared_ptr<rocksdb::LoggerJniCallback>*>(jlogger_handle);
33 auto* cache = new std::shared_ptr<rocksdb::PersistentCache>(nullptr);
34 rocksdb::Status s = rocksdb::NewPersistentCache(
35 rocks_env, path, static_cast<uint64_t>(jsz), *logger,
36 static_cast<bool>(joptimized_for_nvm), cache);
37 if (!s.ok()) {
38 rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
39 }
40 return reinterpret_cast<jlong>(cache);
41 }
42
43 /*
44 * Class: org_rocksdb_PersistentCache
45 * Method: disposeInternal
46 * Signature: (J)V
47 */
48 void Java_org_rocksdb_PersistentCache_disposeInternal(
49 JNIEnv*, jobject, jlong jhandle) {
50 auto* cache =
51 reinterpret_cast<std::shared_ptr<rocksdb::PersistentCache>*>(jhandle);
52 delete cache; // delete std::shared_ptr
53 }