forked from jansegre/python-rocksdb
-
Notifications
You must be signed in to change notification settings - Fork 5
fix: support building against rocksdb-11 #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jansegre
wants to merge
1
commit into
master
Choose a base branch
from
fix/rocksdb-11-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+199
−7
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "rocksdb/version.h" | ||
| #include "rocksdb/db.h" | ||
|
|
||
| #ifndef ROCKSDB_MAKE_VERSION_INT | ||
| #define ROCKSDB_MAKE_VERSION_INT(a, b, c) ((a) * 1000000 + (b) * 1000 + (c)) | ||
| #endif | ||
| #ifndef ROCKSDB_VERSION_INT | ||
| #define ROCKSDB_VERSION_INT \ | ||
| ROCKSDB_MAKE_VERSION_INT(ROCKSDB_MAJOR, ROCKSDB_MINOR, ROCKSDB_PATCH) | ||
| #endif | ||
| #ifndef ROCKSDB_VERSION_GE | ||
| #define ROCKSDB_VERSION_GE(a, b, c) \ | ||
| (ROCKSDB_VERSION_INT >= ROCKSDB_MAKE_VERSION_INT(a, b, c)) | ||
| #endif | ||
|
|
||
| namespace py_rocks { | ||
|
|
||
| inline rocksdb::Status DBOpen( | ||
| const rocksdb::Options& options, | ||
| const std::string& name, | ||
| rocksdb::DB** dbptr) { | ||
| *dbptr = nullptr; | ||
| #if ROCKSDB_VERSION_GE(10, 0, 0) | ||
| std::unique_ptr<rocksdb::DB> db; | ||
| auto status = rocksdb::DB::Open(options, name, &db); | ||
| if (status.ok()) { | ||
| *dbptr = db.release(); | ||
| } | ||
| return status; | ||
|
luislhl marked this conversation as resolved.
|
||
| #else | ||
| return rocksdb::DB::Open(options, name, dbptr); | ||
| #endif | ||
| } | ||
|
|
||
| inline rocksdb::Status DBOpenColumnFamilies( | ||
| const rocksdb::Options& options, | ||
| const std::string& name, | ||
| const std::vector<rocksdb::ColumnFamilyDescriptor>& column_families, | ||
| std::vector<rocksdb::ColumnFamilyHandle*>* handles, | ||
| rocksdb::DB** dbptr) { | ||
| *dbptr = nullptr; | ||
| #if ROCKSDB_VERSION_GE(10, 0, 0) | ||
| std::unique_ptr<rocksdb::DB> db; | ||
| auto status = rocksdb::DB::Open( | ||
| options, | ||
| name, | ||
| column_families, | ||
| handles, | ||
| &db); | ||
| if (status.ok()) { | ||
| *dbptr = db.release(); | ||
| } | ||
| return status; | ||
| #else | ||
| return rocksdb::DB::Open( | ||
| options, | ||
| name, | ||
| column_families, | ||
| handles, | ||
| dbptr); | ||
| #endif | ||
| } | ||
|
|
||
| inline rocksdb::Status DBOpenAsSecondary( | ||
| const rocksdb::Options& options, | ||
| const std::string& name, | ||
| const std::string& secondary_path, | ||
| rocksdb::DB** dbptr) { | ||
| *dbptr = nullptr; | ||
| #if ROCKSDB_VERSION_GE(10, 0, 0) | ||
| std::unique_ptr<rocksdb::DB> db; | ||
| auto status = rocksdb::DB::OpenAsSecondary( | ||
| options, | ||
| name, | ||
| secondary_path, | ||
| &db); | ||
| if (status.ok()) { | ||
| *dbptr = db.release(); | ||
| } | ||
| return status; | ||
| #else | ||
| return rocksdb::DB::OpenAsSecondary(options, name, secondary_path, dbptr); | ||
| #endif | ||
| } | ||
|
|
||
| inline rocksdb::Status DBOpenAsSecondaryColumnFamilies( | ||
| const rocksdb::Options& options, | ||
| const std::string& name, | ||
| const std::string& secondary_path, | ||
| const std::vector<rocksdb::ColumnFamilyDescriptor>& column_families, | ||
| std::vector<rocksdb::ColumnFamilyHandle*>* handles, | ||
| rocksdb::DB** dbptr) { | ||
| *dbptr = nullptr; | ||
| #if ROCKSDB_VERSION_GE(10, 0, 0) | ||
| std::unique_ptr<rocksdb::DB> db; | ||
| auto status = rocksdb::DB::OpenAsSecondary( | ||
| options, | ||
| name, | ||
| secondary_path, | ||
| column_families, | ||
| handles, | ||
| &db); | ||
| if (status.ok()) { | ||
| *dbptr = db.release(); | ||
| } | ||
| return status; | ||
| #else | ||
| return rocksdb::DB::OpenAsSecondary( | ||
| options, | ||
| name, | ||
| secondary_path, | ||
| column_families, | ||
| handles, | ||
| dbptr); | ||
| #endif | ||
| } | ||
|
|
||
| inline rocksdb::Status DBOpenForReadOnly( | ||
| const rocksdb::Options& options, | ||
| const std::string& name, | ||
| rocksdb::DB** dbptr, | ||
| bool error_if_wal_file_exists) { | ||
| *dbptr = nullptr; | ||
| #if ROCKSDB_VERSION_GE(10, 0, 0) | ||
| std::unique_ptr<rocksdb::DB> db; | ||
| auto status = rocksdb::DB::OpenForReadOnly( | ||
| options, | ||
| name, | ||
| &db, | ||
| error_if_wal_file_exists); | ||
| if (status.ok()) { | ||
| *dbptr = db.release(); | ||
| } | ||
| return status; | ||
| #else | ||
| return rocksdb::DB::OpenForReadOnly( | ||
| options, | ||
| name, | ||
| dbptr, | ||
| error_if_wal_file_exists); | ||
| #endif | ||
| } | ||
|
|
||
| inline rocksdb::Status DBOpenForReadOnlyColumnFamilies( | ||
| const rocksdb::Options& options, | ||
| const std::string& name, | ||
| const std::vector<rocksdb::ColumnFamilyDescriptor>& column_families, | ||
| std::vector<rocksdb::ColumnFamilyHandle*>* handles, | ||
| rocksdb::DB** dbptr, | ||
| bool error_if_wal_file_exists) { | ||
| *dbptr = nullptr; | ||
| #if ROCKSDB_VERSION_GE(10, 0, 0) | ||
| std::unique_ptr<rocksdb::DB> db; | ||
| auto status = rocksdb::DB::OpenForReadOnly( | ||
| options, | ||
| name, | ||
| column_families, | ||
| handles, | ||
| &db, | ||
| error_if_wal_file_exists); | ||
| if (status.ok()) { | ||
| *dbptr = db.release(); | ||
| } | ||
| return status; | ||
| #else | ||
| return rocksdb::DB::OpenForReadOnly( | ||
| options, | ||
| name, | ||
| column_families, | ||
| handles, | ||
| dbptr, | ||
| error_if_wal_file_exists); | ||
| #endif | ||
| } | ||
|
|
||
| inline void DBDestroy(rocksdb::DB* db) { | ||
| delete db; | ||
| } | ||
|
|
||
| } // namespace py_rocks | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is important to be able to avoid corrupting the DB in certain situations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On rocksdb, a close cannot fail, if anything errors it's left on the filesystem, not on the DB struct.