]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/rocksjni/checkpoint.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rocksdb / java / rocksjni / checkpoint.cc
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
5 //
6 // This file implements the "bridge" between Java and C++ and enables
7 // calling c++ rocksdb::Checkpoint methods from Java side.
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <jni.h>
12 #include <string>
13
14 #include "include/org_rocksdb_Checkpoint.h"
15 #include "rocksjni/portal.h"
16 #include "rocksdb/db.h"
17 #include "rocksdb/utilities/checkpoint.h"
18 /*
19 * Class: org_rocksdb_Checkpoint
20 * Method: newCheckpoint
21 * Signature: (J)J
22 */
23 jlong Java_org_rocksdb_Checkpoint_newCheckpoint(JNIEnv* env,
24 jclass jclazz, jlong jdb_handle) {
25 auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
26 rocksdb::Checkpoint* checkpoint;
27 rocksdb::Checkpoint::Create(db, &checkpoint);
28 return reinterpret_cast<jlong>(checkpoint);
29 }
30
31 /*
32 * Class: org_rocksdb_Checkpoint
33 * Method: dispose
34 * Signature: (J)V
35 */
36 void Java_org_rocksdb_Checkpoint_disposeInternal(JNIEnv* env, jobject jobj,
37 jlong jhandle) {
38 auto* checkpoint = reinterpret_cast<rocksdb::Checkpoint*>(jhandle);
39 assert(checkpoint != nullptr);
40 delete checkpoint;
41 }
42
43 /*
44 * Class: org_rocksdb_Checkpoint
45 * Method: createCheckpoint
46 * Signature: (JLjava/lang/String;)V
47 */
48 void Java_org_rocksdb_Checkpoint_createCheckpoint(
49 JNIEnv* env, jobject jobj, jlong jcheckpoint_handle,
50 jstring jcheckpoint_path) {
51 const char* checkpoint_path = env->GetStringUTFChars(
52 jcheckpoint_path, 0);
53 if(checkpoint_path == nullptr) {
54 // exception thrown: OutOfMemoryError
55 return;
56 }
57
58 auto* checkpoint = reinterpret_cast<rocksdb::Checkpoint*>(
59 jcheckpoint_handle);
60 rocksdb::Status s = checkpoint->CreateCheckpoint(
61 checkpoint_path);
62
63 env->ReleaseStringUTFChars(jcheckpoint_path, checkpoint_path);
64
65 if (!s.ok()) {
66 rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
67 }
68 }