|
| PolyDBM () |
| Default constructor. More...
|
|
Status | Open (const std::string &path, bool writable, int32_t options=File::OPEN_DEFAULT) override |
| Opens a database file. More...
|
|
Status | OpenAdvanced (const std::string &path, bool writable, int32_t options=File::OPEN_DEFAULT, const std::map< std::string, std::string > ¶ms={}) override |
| Opens a database file, in an advanced way. More...
|
|
Status | Close () override |
| Closes the database file. More...
|
|
Status | Process (std::string_view key, RecordProcessor *proc, bool writable) override |
| Processes a record with a processor. More...
|
|
Status | Get (std::string_view key, std::string *value=nullptr) override |
| Gets the value of a record of a key. More...
|
|
Status | Set (std::string_view key, std::string_view value, bool overwrite=true, std::string *old_value=nullptr) override |
| Sets a record of a key and a value. More...
|
|
Status | Remove (std::string_view key, std::string *old_value=nullptr) override |
| Removes a record of a key. More...
|
|
Status | Append (std::string_view key, std::string_view value, std::string_view delim="") override |
| Appends data at the end of a record of a key. More...
|
|
Status | ProcessEach (RecordProcessor *proc, bool writable) override |
| Processes each and every record in the database with a processor. More...
|
|
Status | Count (int64_t *count) override |
| Gets the number of records. More...
|
|
Status | GetFileSize (int64_t *size) override |
| Gets the current file size of the database. More...
|
|
Status | GetFilePath (std::string *path) override |
| Gets the path of the database file. More...
|
|
Status | Clear () override |
| Removes all records. More...
|
|
Status | Rebuild () override |
| Rebuilds the entire database. More...
|
|
Status | RebuildAdvanced (const std::map< std::string, std::string > ¶ms={}) override |
| Rebuilds the entire database, in an advanced way. More...
|
|
Status | ShouldBeRebuilt (bool *tobe) override |
| Checks whether the database should be rebuilt. More...
|
|
Status | Synchronize (bool hard, FileProcessor *proc=nullptr) override |
| Synchronizes the content of the database to the file system. More...
|
|
Status | SynchronizeAdvanced (bool hard, FileProcessor *proc=nullptr, const std::map< std::string, std::string > ¶ms={}) override |
| Synchronizes the content of the database to the file system, in an advanced way. More...
|
|
std::vector< std::pair< std::string, std::string > > | Inspect () override |
| Inspects the database. More...
|
|
bool | IsOpen () const override |
| Checks whether the database is open. More...
|
|
bool | IsWritable () const override |
| Checks whether the database is writable. More...
|
|
bool | IsHealthy () const override |
| Checks whether the database condition is healthy. More...
|
|
bool | IsOrdered () const override |
| Checks whether ordered operations are supported. More...
|
|
std::unique_ptr< DBM::Iterator > | MakeIterator () override |
| Makes an iterator for each record. More...
|
|
std::unique_ptr< DBM > | MakeDBM () const override |
| Make a new DBM object of the same concrete class. More...
|
|
DBM * | GetInternalDBM () const |
| Gets the pointer to the internal database object. More...
|
|
virtual | ~ParamDBM ()=default |
| Destructor. More...
|
|
virtual | ~DBM ()=default |
| Destructor. More...
|
|
virtual Status | Process (std::string_view key, RecordLambdaType rec_lambda, bool writable) |
| Processes a record with a lambda function. More...
|
|
virtual std::string | GetSimple (std::string_view key, std::string_view default_value="") |
| Gets the value of a record of a key, in a simple way. More...
|
|
virtual std::map< std::string, std::string > | GetMulti (const std::initializer_list< std::string > &keys) |
| Gets the values of multiple records of keys. More...
|
|
virtual std::map< std::string, std::string > | GetMulti (const std::vector< std::string > &keys) |
| Gets the values of multiple records of keys, with a vector. More...
|
|
virtual Status | SetMulti (const std::initializer_list< std::pair< std::string, std::string >> &records, bool overwrite=true) |
| Sets multiple records. More...
|
|
virtual Status | SetMulti (const std::map< std::string, std::string > &records, bool overwrite=true) |
| Sets multiple records, with a map of strings. More...
|
|
virtual Status | CompareExchange (std::string_view key, std::string_view expected, std::string_view desired, std::string *actual=nullptr) |
| Compares the value of a record and exchanges if the condition meets. More...
|
|
virtual Status | Increment (std::string_view key, int64_t increment=1, int64_t *current=nullptr, int64_t initial=0) |
| Increments the numeric value of a record. More...
|
|
int64_t | IncrementSimple (std::string_view key, int64_t increment=1, int64_t initial=0) |
| Increments the numeric value of a record, in a simple way. More...
|
|
virtual Status | ProcessEach (RecordLambdaType rec_lambda, bool writable) |
| Processes each and every record in the database with a lambda function. More...
|
|
virtual int64_t | CountSimple () |
| Gets the number of records, in a simple way. More...
|
|
virtual int64_t | GetFileSizeSimple () |
| Gets the current file size of the database, in a simple way. More...
|
|
virtual std::string | GetFilePathSimple () |
| Gets the path of the database file, in a simple way. More...
|
|
virtual bool | ShouldBeRebuiltSimple () |
| Checks whether the database should be rebuilt, in a simple way. More...
|
|
virtual Status | CopyFileData (const std::string &dest_path) |
| Copies the content of the database file to another file. More...
|
|
virtual Status | Export (DBM *dbm) |
| Exports all records to another database. More...
|
|
Polymorphic database manager adapter.
All operations except for Open and Close are thread-safe; Multiple threads can access the same database concurrently. Every opened database must be closed explicitly to avoid data corruption.
This class is a wrapper of HashDBM, TreeDBM, SkipDBM, TinyDBM, BabyDBM, StdHashDBM, and StdTreeDBM. The open method specifies the actuall class used internally.
Status tkrzw::PolyDBM::OpenAdvanced |
( |
const std::string & |
path, |
|
|
bool |
writable, |
|
|
int32_t |
options = File::OPEN_DEFAULT , |
|
|
const std::map< std::string, std::string > & |
params = {} |
|
) |
| |
|
overridevirtual |
Opens a database file, in an advanced way.
- Parameters
-
path | A path of the file. |
writable | If true, the file is writable. If false, it is read-only. |
options | Bit-sum options for opening the file. |
params | Optional parameters. |
- Returns
- The result status.
The extension of the path indicates the type of the database.
The optional parameters can include options for the file opening operation.
- truncate (bool): True to truncate the file.
- no_create (bool): True to omit file creation.
- no_wait (bool): True to fail if the file is locked by another process.
- no_lock (bool): True to omit file locking.
The optional parameter "dbm" supercedes the decision of the database type by the extension. The value is the type name: "HashDBM", "TreeDBM", "SkipDBM", "TinyDBM", "BabyDBM", "CacheDBM", "StdHashDBM", "StdTreeDBM".
The optional parameter "file" specifies the internal file implementation class. The default file class is "MemoryMapAtomicFile". The other supported classes are "StdFile", "MemoryMapAtomicFile", "PositionalParallelFile", and "PositionalAtomicFile".
For HashDBM, these optional parameters are supported.
- update_mode (string): How to update the database file: "UPDATE_IN_PLACE" for the in-palce and "UPDATE_APPENDING" for the appending mode.
- offset_width (int): The width to represent the offset of records.
- align_pow (int): The power to align records.
- num_buckets (int): The number of buckets for hashing.
- fbp_capacity (int): The capacity of the free block pool.
- lock_mem_buckets (bool): True to lock the memory for the hash buckets.
- cache_buckets (bool): True to cache the hash buckets on memory.
For TreeDBM, all optional parameters for HashDBM are available. In addition, these optional parameters are supported.
- max_page_size (int): The maximum size of a page.
- max_branches (int): The maximum number of branches each inner node can have.
- max_cached_pages (int): The maximum number of cached pages.
- key_comparator (string): The comparator of record keys: "LexicalKeyComparator" for the lexical order, "LexicalCaseKeyComparator" for the lexical order ignoring case, "DecimalKeyComparator" for the order of the decimal integer numeric expressions, "HexadecimalKeyComparator" for the order of the hexadecimal integer numeric expressions, "RealNumberKeyComparator" for the order of the decimal real number expressions.
For SkipDBM, these optional parameters are supported.
- offset_width (int): The width to represent the offset of records.
- step_unit (int): The step unit of the skip list.
- max_level (int): The maximum level of the skip list.
- sort_mem_size (int): The memory size used for sorting to build the database in the at-random mode.
- insert_in_order (bool): If true, records are assumed to be inserted in ascending order of the key.
- max_cached_records (int): The maximum number of cached records.
For TinyDBM, these optional parameters are supported.
- num_buckets (int): The number of buckets for hashing.
For BabyDBM, these optional parameters are supported.
- key_comparator (string): The comparator of record keys. The same ones as TreeDBM.
For CacheDBM, these optional parameters are supported.
- cap_rec_num (int): The maximum number of records.
- cap_mem_size (int): The total memory size to use.
For the file "PositionalParallelFile" and "PositionalAtomicFile", these optional parameters are supported.
- block_size (int): The block size to which all blocks should be aligned.
- access_options (str): Values separated by colon. "direct" for direct I/O. "sync" for synchrnizing I/O.
Implements tkrzw::ParamDBM.