Use ToplingDB step by step #60
rockeet
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
From ToplingDB document
中文版 (Chinese)
Using ToplingDB from scratch
Sample code (error handling omitted, full version here)
To migrate from RocksDB to ToplingDB, you only need to modify the code related to Open/Close, and no other code needs to be changed.
1. Open
SidePluginRepois the core class of ToplingDB SidePlugin, and all components are included in it. To use SidePlugin, you must first define aSidePluginRepoobject:With the
SidePluginRepoobject, the next step is to import configuration parameters. The most convenient way is to callImportAutoFile, which automatically recognizes json and yaml files according to the file extension:Now, we can open the DB:
DB* db = nullptr; repo.OpenDB(&db);In RocksDB, we generally use
DB::Open, and in a few cases use other Open functions. But in SidePlugin, we useOpenDBuniformly, and which Open function is used is configured in json/yaml: for example Todis secondary node.In this example, we use the default DB with only one ColumnFamily, but in fact OpenDB is an overloaded function, which can also be used to open a DB with multiple ColumnFamily (db_bench modified later is an example of this):
2. Start the embedded Http Web Server
In theory, the embedded Http Web Server can be automatically started in OpenDB. However, we still decided to let the user start it explicitly:
There are three main reasons:
Status, it is difficult to use the same Status to distinguish the error information of DB Open and Http StartClose
Need explicit Close, just one line of code:
Further reference: Using CompactionFilter in ToplingDB
A bit more complicated: db_bench modification for ToplingDB
db_bench_tool.ccis a file with more than 8000 lines. We make it support ToplingDB, adding only 47 lines of code, without any other modification, then we have all the capabilities of ToplingDB! Here is the diff contentBeta Was this translation helpful? Give feedback.
All reactions