From 9190e3edb4818bec020b33a435410fd953b31fb4 Mon Sep 17 00:00:00 2001 From: Zhou Xiaoqiang Date: Sun, 29 Aug 2021 22:13:24 +0800 Subject: [PATCH] add checkpoint support --- .gitignore | 2 ++ rocksdb/_rocksdb.pyx | 29 +++++++++++++++++++++++++++++ rocksdb/checkpoint.pxd | 11 +++++++++++ 3 files changed, 42 insertions(+) create mode 100644 rocksdb/checkpoint.pxd diff --git a/.gitignore b/.gitignore index ee003c3..3ab8dfd 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ docs/_build *.egg-info/ *.pyc *.so +venv +.idea __pycache__ rocksdb/_rocksdb.cpp diff --git a/rocksdb/_rocksdb.pyx b/rocksdb/_rocksdb.pyx index edd856a..687bb53 100644 --- a/rocksdb/_rocksdb.pyx +++ b/rocksdb/_rocksdb.pyx @@ -24,6 +24,7 @@ cimport snapshot cimport db cimport iterator cimport backup +cimport checkpoint cimport env cimport table_factory cimport memtablerep @@ -2322,6 +2323,34 @@ cdef class ReversedIterator(object): check_status(self.it.ptr.status()) return ret + +cdef class Checkpoint(object): + cdef checkpoint.Checkpoint* checkpoint + + def __cinit__(self, DB db): + cdef Status st + self.checkpoint = NULL + st = checkpoint.Checkpoint_Create( + db.db, + cython.address(self.checkpoint)) + + check_status(st) + + def __dealloc__(self): + if not self.checkpoint == NULL: + with nogil: + del self.checkpoint + + def create_checkpoint(self, checkpoint_dir): + cdef Status st + cdef string c_checkpoint_dir + c_checkpoint_dir = path_to_string(checkpoint_dir) + + with nogil: + st = self.checkpoint.CreateCheckpoint(c_checkpoint_dir) + check_status(st) + + cdef class BackupEngine(object): cdef backup.BackupEngine* engine diff --git a/rocksdb/checkpoint.pxd b/rocksdb/checkpoint.pxd new file mode 100644 index 0000000..2e9db44 --- /dev/null +++ b/rocksdb/checkpoint.pxd @@ -0,0 +1,11 @@ +from libcpp.string cimport string +from db cimport DB +from status cimport Status + +cdef extern from "rocksdb/utilities/checkpoint.h" namespace "rocksdb": + cdef cppclass Checkpoint: + Status CreateCheckpoint(const string&) nogil except+ + + cdef Status Checkpoint_Create "rocksdb::Checkpoint::Create"( + DB*, + Checkpoint**) nogil except+