]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/java/rocksjni/checkpoint.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / java / rocksjni / checkpoint.cc
CommitLineData
7c673cae 1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
11fdf7f2
TL
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).
7c673cae
FG
5//
6// This file implements the "bridge" between Java and C++ and enables
7// calling c++ rocksdb::Checkpoint methods from Java side.
8
11fdf7f2 9#include <jni.h>
7c673cae
FG
10#include <stdio.h>
11#include <stdlib.h>
7c673cae
FG
12#include <string>
13
14#include "include/org_rocksdb_Checkpoint.h"
7c673cae
FG
15#include "rocksdb/db.h"
16#include "rocksdb/utilities/checkpoint.h"
11fdf7f2 17#include "rocksjni/portal.h"
7c673cae
FG
18/*
19 * Class: org_rocksdb_Checkpoint
20 * Method: newCheckpoint
21 * Signature: (J)J
22 */
11fdf7f2
TL
23jlong Java_org_rocksdb_Checkpoint_newCheckpoint(JNIEnv* /*env*/,
24 jclass /*jclazz*/,
25 jlong jdb_handle) {
7c673cae
FG
26 auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
27 rocksdb::Checkpoint* checkpoint;
28 rocksdb::Checkpoint::Create(db, &checkpoint);
29 return reinterpret_cast<jlong>(checkpoint);
30}
31
32/*
33 * Class: org_rocksdb_Checkpoint
34 * Method: dispose
35 * Signature: (J)V
36 */
11fdf7f2
TL
37void Java_org_rocksdb_Checkpoint_disposeInternal(JNIEnv* /*env*/,
38 jobject /*jobj*/,
39 jlong jhandle) {
7c673cae
FG
40 auto* checkpoint = reinterpret_cast<rocksdb::Checkpoint*>(jhandle);
41 assert(checkpoint != nullptr);
42 delete checkpoint;
43}
44
45/*
46 * Class: org_rocksdb_Checkpoint
47 * Method: createCheckpoint
48 * Signature: (JLjava/lang/String;)V
49 */
11fdf7f2
TL
50void Java_org_rocksdb_Checkpoint_createCheckpoint(JNIEnv* env, jobject /*jobj*/,
51 jlong jcheckpoint_handle,
52 jstring jcheckpoint_path) {
53 const char* checkpoint_path = env->GetStringUTFChars(jcheckpoint_path, 0);
54 if (checkpoint_path == nullptr) {
7c673cae
FG
55 // exception thrown: OutOfMemoryError
56 return;
57 }
58
11fdf7f2
TL
59 auto* checkpoint = reinterpret_cast<rocksdb::Checkpoint*>(jcheckpoint_handle);
60 rocksdb::Status s = checkpoint->CreateCheckpoint(checkpoint_path);
61
7c673cae 62 env->ReleaseStringUTFChars(jcheckpoint_path, checkpoint_path);
11fdf7f2 63
7c673cae 64 if (!s.ok()) {
11fdf7f2 65 rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
7c673cae
FG
66 }
67}