]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/rocksjni/persistent_cache.cc
update ceph source to reef 18.1.2
[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_NAMESPACE::PersistentCache.
8
9 #include "rocksdb/persistent_cache.h"
10
11 #include <jni.h>
12
13 #include <string>
14
15 #include "include/org_rocksdb_PersistentCache.h"
16 #include "loggerjnicallback.h"
17 #include "portal.h"
18 #include "rocksjni/cplusplus_to_java_convert.h"
19
20 /*
21 * Class: org_rocksdb_PersistentCache
22 * Method: newPersistentCache
23 * Signature: (JLjava/lang/String;JJZ)J
24 */
25 jlong Java_org_rocksdb_PersistentCache_newPersistentCache(
26 JNIEnv* env, jclass, jlong jenv_handle, jstring jpath, jlong jsz,
27 jlong jlogger_handle, jboolean joptimized_for_nvm) {
28 auto* rocks_env = reinterpret_cast<ROCKSDB_NAMESPACE::Env*>(jenv_handle);
29 jboolean has_exception = JNI_FALSE;
30 std::string path =
31 ROCKSDB_NAMESPACE::JniUtil::copyStdString(env, jpath, &has_exception);
32 if (has_exception == JNI_TRUE) {
33 return 0;
34 }
35 auto* logger =
36 reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::LoggerJniCallback>*>(
37 jlogger_handle);
38 auto* cache =
39 new std::shared_ptr<ROCKSDB_NAMESPACE::PersistentCache>(nullptr);
40 ROCKSDB_NAMESPACE::Status s = ROCKSDB_NAMESPACE::NewPersistentCache(
41 rocks_env, path, static_cast<uint64_t>(jsz), *logger,
42 static_cast<bool>(joptimized_for_nvm), cache);
43 if (!s.ok()) {
44 ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
45 }
46 return GET_CPLUSPLUS_POINTER(cache);
47 }
48
49 /*
50 * Class: org_rocksdb_PersistentCache
51 * Method: disposeInternal
52 * Signature: (J)V
53 */
54 void Java_org_rocksdb_PersistentCache_disposeInternal(JNIEnv*, jobject,
55 jlong jhandle) {
56 auto* cache =
57 reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::PersistentCache>*>(
58 jhandle);
59 delete cache; // delete std::shared_ptr
60 }