Skip to content

Commit

Permalink
[feat] Add support of Secondary Instances (#29)
Browse files Browse the repository at this point in the history
* Adding `OpenAsSecondary` support

* Bump up version

* Bump up version to 0.5.0

---------

Co-authored-by: Albert Torosyan <torosyanalbert@gmail.com>
  • Loading branch information
mahnerak and alberttorosyan authored Aug 21, 2023
1 parent 91a9e57 commit 0376c30
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

setup(
name="aimrocks",
version='0.4.0',
version='0.5.0',
description='RocksDB wrapper implemented in Cython.',
setup_requires=['setuptools>=25', 'Cython>=3.0.0a9'],
packages=find_packages('./src'),
Expand Down
16 changes: 16 additions & 0 deletions src/aimrocks/db.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ cdef extern from "rocksdb/db.h" namespace "rocksdb":
Status DisableFileDeletions() nogil except+
Status EnableFileDeletions() nogil except+

Status TryCatchUpWithPrimary() nogil except+

# TODO: Status GetSortedWalFiles(VectorLogPtr& files)
# TODO: SequenceNumber GetLatestSequenceNumber()
# TODO: Status GetUpdatesSince(
Expand Down Expand Up @@ -194,6 +196,20 @@ cdef extern from "rocksdb/db.h" namespace "rocksdb":
DB**,
cpp_bool) nogil except+

cdef Status DB_OpenAsSecondary "rocksdb::DB::OpenAsSecondary"(
const options.Options&,
const string&,
const string&,
DB**) nogil except+

cdef Status DB_OpenAsSecondary_ColumnFamilies "rocksdb::DB::OpenAsSecondary"(
const options.Options&,
const string&,
const string&,
const vector[ColumnFamilyDescriptor]&,
vector[ColumnFamilyHandle*]*,
DB**) nogil except+

cdef Status RepairDB(const string& dbname, const options.Options&)

cdef Status ListColumnFamilies "rocksdb::DB::ListColumnFamilies" (
Expand Down
1 change: 1 addition & 0 deletions src/aimrocks/lib_rocksdb.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ cdef class DB(IDB):
cpdef itersitems(self, column_families)
cpdef snapshot(self)
cpdef get_property(self, prop, ColumnFamilyHandle column_family = *)
cpdef try_catch_up_with_primary(self)
cpdef get_live_files_metadata(self)
cpdef void compact_range(
self,
Expand Down
27 changes: 25 additions & 2 deletions src/aimrocks/lib_rocksdb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1618,9 +1618,17 @@ cdef class DB(IDB):
# cdef list cf_handles
# cdef list cf_options

def __cinit__(self, db_name, Options opts, dict column_families=None, read_only=False):
def __cinit__(
self,
db_name,
Options opts,
dict column_families=None,
read_only=False,
secondary_path=None,
):
cdef Status st
cdef string db_path
cdef string secondary_path_c
cdef vector[db.ColumnFamilyDescriptor] column_family_descriptors
cdef vector[db.ColumnFamilyHandle*] column_family_handles
cdef bytes default_cf_name = db.kDefaultColumnFamilyName
Expand Down Expand Up @@ -1666,7 +1674,19 @@ cdef class DB(IDB):
)
)
self.cf_options.append(cf_options)
if read_only:

if secondary_path is not None:
assert read_only
secondary_path_c = path_to_string(secondary_path)
with nogil:
st = db.DB_OpenAsSecondary_ColumnFamilies(
deref(opts.opts),
db_path,
secondary_path_c,
column_family_descriptors,
&column_family_handles,
&self.db)
elif read_only:
with nogil:
st = db.DB_OpenForReadOnly_ColumnFamilies(
deref(opts.opts),
Expand Down Expand Up @@ -2073,6 +2093,9 @@ cdef class DB(IDB):
else:
return None

cpdef try_catch_up_with_primary(self):
self.db.TryCatchUpWithPrimary()

cpdef get_live_files_metadata(self):
cdef vector[db.LiveFileMetaData] metadata

Expand Down

0 comments on commit 0376c30

Please sign in to comment.