checkpoint.cc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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++ and enables
  7. // calling c++ ROCKSDB_NAMESPACE::Checkpoint methods from Java side.
  8. #include <jni.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string>
  12. #include "include/org_rocksdb_Checkpoint.h"
  13. #include "rocksdb/db.h"
  14. #include "rocksdb/utilities/checkpoint.h"
  15. #include "rocksjni/portal.h"
  16. /*
  17. * Class: org_rocksdb_Checkpoint
  18. * Method: newCheckpoint
  19. * Signature: (J)J
  20. */
  21. jlong Java_org_rocksdb_Checkpoint_newCheckpoint(JNIEnv* /*env*/,
  22. jclass /*jclazz*/,
  23. jlong jdb_handle) {
  24. auto* db = reinterpret_cast<ROCKSDB_NAMESPACE::DB*>(jdb_handle);
  25. ROCKSDB_NAMESPACE::Checkpoint* checkpoint;
  26. ROCKSDB_NAMESPACE::Checkpoint::Create(db, &checkpoint);
  27. return reinterpret_cast<jlong>(checkpoint);
  28. }
  29. /*
  30. * Class: org_rocksdb_Checkpoint
  31. * Method: dispose
  32. * Signature: (J)V
  33. */
  34. void Java_org_rocksdb_Checkpoint_disposeInternal(JNIEnv* /*env*/,
  35. jobject /*jobj*/,
  36. jlong jhandle) {
  37. auto* checkpoint = reinterpret_cast<ROCKSDB_NAMESPACE::Checkpoint*>(jhandle);
  38. assert(checkpoint != nullptr);
  39. delete checkpoint;
  40. }
  41. /*
  42. * Class: org_rocksdb_Checkpoint
  43. * Method: createCheckpoint
  44. * Signature: (JLjava/lang/String;)V
  45. */
  46. void Java_org_rocksdb_Checkpoint_createCheckpoint(JNIEnv* env, jobject /*jobj*/,
  47. jlong jcheckpoint_handle,
  48. jstring jcheckpoint_path) {
  49. const char* checkpoint_path = env->GetStringUTFChars(jcheckpoint_path, 0);
  50. if (checkpoint_path == nullptr) {
  51. // exception thrown: OutOfMemoryError
  52. return;
  53. }
  54. auto* checkpoint =
  55. reinterpret_cast<ROCKSDB_NAMESPACE::Checkpoint*>(jcheckpoint_handle);
  56. ROCKSDB_NAMESPACE::Status s = checkpoint->CreateCheckpoint(checkpoint_path);
  57. env->ReleaseStringUTFChars(jcheckpoint_path, checkpoint_path);
  58. if (!s.ok()) {
  59. ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
  60. }
  61. }