Tkrzw
Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
tkrzw::DBM Class Referenceabstract

Interface of database manager. More...

#include <tkrzw_dbm.h>

Classes

class  FileProcessor
 Interface of processor for a record. More...
 
class  FileProcessorCopyFileData
 File processor to implement DBM::CopyFileData. More...
 
class  Iterator
 Interface of iterator for each record. More...
 
class  RecordCheckerCompareExchangeMulti
 Record checker to implement DBM::CompareExchangeMulti. More...
 
class  RecordCheckerRekey
 Record checker to implement DBM::Rekey. More...
 
class  RecordProcessor
 Interface of processor for a record. More...
 
class  RecordProcessorAppend
 Record processor to implement DBM::Append. More...
 
class  RecordProcessorCompareExchange
 Record processor to implement DBM::CompareExchange. More...
 
class  RecordProcessorExport
 Record processor to implement DBM::Export. More...
 
class  RecordProcessorGet
 Record processor to implement DBM::Get. More...
 
class  RecordProcessorIncrement
 Record processor to implement DBM::Increment. More...
 
class  RecordProcessorIterator
 Record processor to implement DBM::Iterator methods. More...
 
class  RecordProcessorLambda
 Record processor to implement DBM::Process with a lambda function. More...
 
class  RecordProcessorPopFirst
 Record processor to implement DBM::PopFirst. More...
 
class  RecordProcessorRemove
 Record processor to implement DBM::Remove. More...
 
class  RecordProcessorSet
 Record processor to implement DBM::Set. More...
 
class  RecordRemoverRekey
 Record remover to implement DBM::Rekey. More...
 
class  RecordSetterCompareExchangeMulti
 Record setter to implement DBM::CompareExchangeMulti. More...
 
class  RecordSetterRekey
 Record setter to implement DBM::Rekey. More...
 
class  UpdateLogger
 Interface of update logger. More...
 

Public Types

typedef std::function< std::string_view(std::string_view, std::string_view)> RecordLambdaType
 Lambda function type to process a record. More...
 

Public Member Functions

virtual ~DBM ()=default
 Destructor. More...
 
virtual Status Open (const std::string &path, bool writable, int32_t options=File::OPEN_DEFAULT)=0
 Opens a database file. More...
 
virtual Status Close ()=0
 Closes the database file. More...
 
virtual Status Process (std::string_view key, RecordProcessor *proc, bool writable)=0
 Processes a record with a processor. More...
 
virtual Status Process (std::string_view key, RecordLambdaType rec_lambda, bool writable)
 Processes a record with a lambda function. More...
 
virtual Status Get (std::string_view key, std::string *value=nullptr)
 Gets the value of a record of a key. 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 Status GetMulti (const std::vector< std::string_view > &keys, std::map< std::string, std::string > *records)
 Gets the values of multiple records of keys, with a string view vector. More...
 
virtual Status GetMulti (const std::initializer_list< std::string_view > &keys, std::map< std::string, std::string > *records)
 Gets the values of multiple records of keys, with an initializer list. More...
 
virtual Status GetMulti (const std::vector< std::string > &keys, std::map< std::string, std::string > *records)
 Gets the values of multiple records of keys, with a string vector. More...
 
virtual Status Set (std::string_view key, std::string_view value, bool overwrite=true, std::string *old_value=nullptr)
 Sets a record of a key and a value. More...
 
virtual Status SetMulti (const std::map< std::string_view, std::string_view > &records, bool overwrite=true)
 Sets multiple records, with a map of string views. More...
 
virtual Status SetMulti (const std::initializer_list< std::pair< std::string_view, std::string_view >> &records, bool overwrite=true)
 Sets multiple records, with an initializer list. 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 Remove (std::string_view key, std::string *old_value=nullptr)
 Removes a record of a key. More...
 
virtual Status RemoveMulti (const std::vector< std::string_view > &keys)
 Removes records of keys, with a string view vector. More...
 
virtual Status RemoveMulti (const std::initializer_list< std::string_view > &keys)
 Removes records of keys, with an initializer list. More...
 
virtual Status RemoveMulti (const std::vector< std::string > &keys)
 Removes records of keys, with a string vector. More...
 
virtual Status Append (std::string_view key, std::string_view value, std::string_view delim="")
 Appends data at the end of a record of a key. More...
 
virtual Status AppendMulti (const std::map< std::string_view, std::string_view > &records, std::string_view delim="")
 Appends data to multiple records, with a map of string views. More...
 
virtual Status AppendMulti (const std::initializer_list< std::pair< std::string_view, std::string_view >> &records, std::string_view delim="")
 Appends data to multiple records, with an initializer list. More...
 
virtual Status AppendMulti (const std::map< std::string, std::string > &records, std::string_view delim="")
 Appends data to 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, bool *found=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...
 
virtual 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 ProcessMulti (const std::vector< std::pair< std::string_view, RecordProcessor * >> &key_proc_pairs, bool writable)=0
 Processes multiple records with processors. More...
 
virtual Status ProcessMulti (const std::vector< std::pair< std::string_view, RecordLambdaType >> &key_lambda_pairs, bool writable)
 Processes multiple records with lambda functions. More...
 
virtual Status CompareExchangeMulti (const std::vector< std::pair< std::string_view, std::string_view >> &expected, const std::vector< std::pair< std::string_view, std::string_view >> &desired)
 Compares the values of records and exchanges if the condition meets. More...
 
virtual Status Rekey (std::string_view old_key, std::string_view new_key, bool overwrite=true, bool copying=false, std::string *value=nullptr)
 Changes the key of a record. More...
 
virtual Status ProcessFirst (RecordProcessor *proc, bool writable)=0
 Processes the first record with a processor. More...
 
virtual Status ProcessFirst (RecordLambdaType rec_lambda, bool writable)
 Processes the first record with a lambda function. More...
 
virtual Status PopFirst (std::string *key=nullptr, std::string *value=nullptr)
 Gets the first record and removes it. More...
 
virtual Status PushLast (std::string_view value, double wtime=-1, std::string *key=nullptr)
 Adds a record with a key of the current timestamp. More...
 
virtual Status ProcessEach (RecordProcessor *proc, bool writable)=0
 Processes each and every record in the database with a processor. More...
 
virtual Status ProcessEach (RecordLambdaType rec_lambda, bool writable)
 Processes each and every record in the database with a lambda function. More...
 
virtual Status Count (int64_t *count)=0
 Gets the number of records. More...
 
virtual int64_t CountSimple ()
 Gets the number of records, in a simple way. More...
 
virtual Status GetFileSize (int64_t *size)=0
 Gets the current file size of the database. More...
 
virtual int64_t GetFileSizeSimple ()
 Gets the current file size of the database, in a simple way. More...
 
virtual Status GetFilePath (std::string *path)=0
 Gets the path of the database file. More...
 
virtual std::string GetFilePathSimple ()
 Gets the path of the database file, in a simple way. More...
 
virtual Status GetTimestamp (double *timestamp)=0
 Gets the timestamp in seconds of the last modified time. More...
 
virtual double GetTimestampSimple ()
 Gets the timestamp of the last modified time, in a simple way. More...
 
virtual Status Clear ()=0
 Removes all records. More...
 
virtual Status Rebuild ()=0
 Rebuilds the entire database. More...
 
virtual Status ShouldBeRebuilt (bool *tobe)=0
 Checks whether the database should be rebuilt. More...
 
virtual bool ShouldBeRebuiltSimple ()
 Checks whether the database should be rebuilt, in a simple way. More...
 
virtual Status Synchronize (bool hard, FileProcessor *proc=nullptr)=0
 Synchronizes the content of the database to the file system. More...
 
virtual Status CopyFileData (const std::string &dest_path, bool sync_hard=false)
 Copies the content of the database file to another file. More...
 
virtual Status Export (DBM *dest_dbm)
 Exports all records to another database. More...
 
virtual std::vector< std::pair< std::string, std::string > > Inspect ()=0
 Inspects the database. More...
 
virtual bool IsOpen () const =0
 Checks whether the database is open. More...
 
virtual bool IsWritable () const =0
 Checks whether the database is writable. More...
 
virtual bool IsHealthy () const =0
 Checks whether the database condition is healthy. More...
 
virtual bool IsOrdered () const =0
 Checks whether ordered operations are supported. More...
 
virtual std::unique_ptr< IteratorMakeIterator ()=0
 Makes an iterator for each record. More...
 
virtual std::unique_ptr< DBMMakeDBM () const =0
 Makes a new DBM object of the same concrete class. More...
 
virtual UpdateLoggerGetUpdateLogger () const =0
 Gets the logger to write all update operations. More...
 
virtual void SetUpdateLogger (UpdateLogger *update_logger)=0
 Sets the logger to write all update operations. More...
 
const std::type_info & GetType () const
 Gets the type information of the actual class. More...
 

Static Public Attributes

static const std::string_view ANY_DATA
 The special string_view value to represent any data. More...
 

Detailed Description

Interface of database manager.

Member Typedef Documentation

◆ RecordLambdaType

typedef std::function<std::string_view(std::string_view, std::string_view)> tkrzw::DBM::RecordLambdaType

Lambda function type to process a record.

The first parameter is the key of the record. The second parameter is the value of the existing record, or NOOP if it the record doesn't exist. The return value is a string reference to NOOP, REMOVE, or the new record value.

Constructor & Destructor Documentation

◆ ~DBM()

virtual tkrzw::DBM::~DBM ( )
virtualdefault

Destructor.

Member Function Documentation

◆ Open()

virtual Status tkrzw::DBM::Open ( const std::string &  path,
bool  writable,
int32_t  options = File::OPEN_DEFAULT 
)
pure virtual

Opens a database file.

Parameters
pathA path of the file.
writableIf true, the file is writable. If false, it is read-only.
optionsBit-sum options of File::OpenOption enumss for opening the file.
Returns
The result status.

Implemented in tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::StdTreeDBM, tkrzw::StdHashDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, tkrzw::HashDBM, tkrzw::CacheDBM, and tkrzw::BabyDBM.

◆ Close()

virtual Status tkrzw::DBM::Close ( )
pure virtual

◆ Process() [1/2]

virtual Status tkrzw::DBM::Process ( std::string_view  key,
RecordProcessor proc,
bool  writable 
)
pure virtual

Processes a record with a processor.

Parameters
keyThe key of the record.
procThe pointer to the processor object.
writableTrue if the processor can edit the record.
Returns
The result status.

If the specified record exists, the ProcessFull of the processor is called. Otherwise, the ProcessEmpty of the processor is called.

Implemented in tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::StdTreeDBM, tkrzw::StdHashDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, tkrzw::HashDBM, tkrzw::CacheDBM, and tkrzw::BabyDBM.

◆ Process() [2/2]

virtual Status tkrzw::DBM::Process ( std::string_view  key,
RecordLambdaType  rec_lambda,
bool  writable 
)
virtual

Processes a record with a lambda function.

Parameters
keyThe key of the record.
rec_lambdaThe lambda function to process a record. The first parameter is the key of the record. The second parameter is the value of the existing record, or RecordProcessor::NOOP if it the record doesn't exist. The return value is a string reference to RecordProcessor::NOOP, RecordProcessor::REMOVE, or the new record value.
writableTrue if the processor can edit the record.
Returns
The result status.

◆ Get()

virtual Status tkrzw::DBM::Get ( std::string_view  key,
std::string *  value = nullptr 
)
virtual

Gets the value of a record of a key.

Parameters
keyThe key of the record.
valueThe pointer to a string object to contain the result value. If it is nullptr, the value data is ignored.
Returns
The result status. If there's no matching record, NOT_FOUND_ERROR is returned.

Reimplemented in tkrzw::ShardDBM, tkrzw::PolyDBM, and tkrzw::HashDBM.

◆ GetSimple()

virtual std::string tkrzw::DBM::GetSimple ( std::string_view  key,
std::string_view  default_value = "" 
)
virtual

Gets the value of a record of a key, in a simple way.

Parameters
keyThe key of the record.
default_valueThe value to be returned on failure.
Returns
The value of the matching record on success, or the default value on failure.

◆ GetMulti() [1/3]

virtual Status tkrzw::DBM::GetMulti ( const std::vector< std::string_view > &  keys,
std::map< std::string, std::string > *  records 
)
virtual

Gets the values of multiple records of keys, with a string view vector.

Parameters
keysThe keys of records to retrieve.
recordsThe pointer to a map to store retrieved records. Keys which don't match existing records are ignored.
Returns
The result status. If all records of the given keys are found, SUCCESS is returned. If one or more records are missing, NOT_FOUND_ERROR is returned. Thus, even with an error code, the result map can have elements.

◆ GetMulti() [2/3]

virtual Status tkrzw::DBM::GetMulti ( const std::initializer_list< std::string_view > &  keys,
std::map< std::string, std::string > *  records 
)
virtual

Gets the values of multiple records of keys, with an initializer list.

Parameters
keysThe keys of records to retrieve.
recordsThe pointer to a map to store retrieved records. Keys which don't match existing records are ignored.
Returns
The result status. If all records of the given keys are found, SUCCESS is returned. If one or more records are missing, NOT_FOUND_ERROR is returned. Thus, even with an error code, the result map can have elements.

◆ GetMulti() [3/3]

virtual Status tkrzw::DBM::GetMulti ( const std::vector< std::string > &  keys,
std::map< std::string, std::string > *  records 
)
virtual

Gets the values of multiple records of keys, with a string vector.

Parameters
keysThe keys of records to retrieve.
recordsThe pointer to a map to store retrieved records. Keys which don't match existing records are ignored.
Returns
The result status. If all records of the given keys are found, SUCCESS is returned. If one or more records are missing, NOT_FOUND_ERROR is returned. Thus, even with an error code, the result map can have elements.

◆ Set()

virtual Status tkrzw::DBM::Set ( std::string_view  key,
std::string_view  value,
bool  overwrite = true,
std::string *  old_value = nullptr 
)
virtual

Sets a record of a key and a value.

Parameters
keyThe key of the record.
valueThe value of the record.
overwriteWhether to overwrite the existing value if there's a record with the same key. If true, the existing value is overwritten by the new value. If false, the operation is given up and an error status is returned.
old_valueThe pointer to a string object to contain the old value. Assignment is done even on the duplication error. If it is nullptr, it is ignored.
Returns
The result status. If overwriting is abandoned, DUPLICATION_ERROR is returned.

Reimplemented in tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, and tkrzw::HashDBM.

◆ SetMulti() [1/3]

virtual Status tkrzw::DBM::SetMulti ( const std::map< std::string_view, std::string_view > &  records,
bool  overwrite = true 
)
virtual

Sets multiple records, with a map of string views.

Parameters
recordsThe records to store.
overwriteWhether to overwrite the existing value if there's a record with the same key. If true, the existing value is overwritten by the new value. If false, the operation is given up and an error status is returned.
Returns
The result status. If there are records avoiding overwriting, DUPLICATION_ERROR is returned.

◆ SetMulti() [2/3]

virtual Status tkrzw::DBM::SetMulti ( const std::initializer_list< std::pair< std::string_view, std::string_view >> &  records,
bool  overwrite = true 
)
virtual

Sets multiple records, with an initializer list.

Parameters
recordsThe records to store.
overwriteWhether to overwrite the existing value if there's a record with the same key. If true, the existing value is overwritten by the new value. If false, the operation is given up and an error status is returned.
Returns
The result status. If there are records avoiding overwriting, DUPLICATION_ERROR is returned.

◆ SetMulti() [3/3]

virtual Status tkrzw::DBM::SetMulti ( const std::map< std::string, std::string > &  records,
bool  overwrite = true 
)
virtual

Sets multiple records, with a map of strings.

Parameters
recordsThe records to store.
overwriteWhether to overwrite the existing value if there's a record with the same key. If true, the existing value is overwritten by the new value. If false, the operation is given up and an error status is returned.
Returns
The result status. If there are records avoiding overwriting, DUPLICATION_ERROR is returned.

◆ Remove()

virtual Status tkrzw::DBM::Remove ( std::string_view  key,
std::string *  old_value = nullptr 
)
virtual

Removes a record of a key.

Parameters
keyThe key of the record.
old_valueThe pointer to a string object to contain the old value. If it is nullptr, it is ignored.
Returns
The result status. If there's no matching record, NOT_FOUND_ERROR is returned.

Reimplemented in tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, and tkrzw::HashDBM.

◆ RemoveMulti() [1/3]

virtual Status tkrzw::DBM::RemoveMulti ( const std::vector< std::string_view > &  keys)
virtual

Removes records of keys, with a string view vector.

Parameters
keysThe keys of records to remove.
Returns
The result status. If there are missing records, NOT_FOUND_ERROR is returned.

◆ RemoveMulti() [2/3]

virtual Status tkrzw::DBM::RemoveMulti ( const std::initializer_list< std::string_view > &  keys)
virtual

Removes records of keys, with an initializer list.

Parameters
keysThe keys of records to remove.
Returns
The result status.

◆ RemoveMulti() [3/3]

virtual Status tkrzw::DBM::RemoveMulti ( const std::vector< std::string > &  keys)
virtual

Removes records of keys, with a string vector.

Parameters
keysThe keys of records to remove.
Returns
The result status. If there are missing records, NOT_FOUND_ERROR is returned.

◆ Append()

virtual Status tkrzw::DBM::Append ( std::string_view  key,
std::string_view  value,
std::string_view  delim = "" 
)
virtual

Appends data at the end of a record of a key.

Parameters
keyThe key of the record.
valueThe value to append.
delimThe delimiter to put after the existing record.
Returns
The result status.

If there's no existing record, the value is set without the delimiter.

Reimplemented in tkrzw::TinyDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, and tkrzw::BabyDBM.

◆ AppendMulti() [1/3]

virtual Status tkrzw::DBM::AppendMulti ( const std::map< std::string_view, std::string_view > &  records,
std::string_view  delim = "" 
)
virtual

Appends data to multiple records, with a map of string views.

Parameters
recordsThe records to append.
delimThe delimiter to put after the existing record.
Returns
The result status.

If there's no existing record, the value is set without the delimiter.

◆ AppendMulti() [2/3]

virtual Status tkrzw::DBM::AppendMulti ( const std::initializer_list< std::pair< std::string_view, std::string_view >> &  records,
std::string_view  delim = "" 
)
virtual

Appends data to multiple records, with an initializer list.

Parameters
recordsThe records to store.
delimThe delimiter to put after the existing record.
Returns
The result status.

If there's no existing record, the value is set without the delimiter.

◆ AppendMulti() [3/3]

virtual Status tkrzw::DBM::AppendMulti ( const std::map< std::string, std::string > &  records,
std::string_view  delim = "" 
)
virtual

Appends data to multiple records, with a map of strings.

Parameters
recordsThe records to append.
delimThe delimiter to put after the existing record.
Returns
The result status.

If there's no existing record, the value is set without the delimiter.

◆ CompareExchange()

virtual Status tkrzw::DBM::CompareExchange ( std::string_view  key,
std::string_view  expected,
std::string_view  desired,
std::string *  actual = nullptr,
bool *  found = nullptr 
)
virtual

Compares the value of a record and exchanges if the condition meets.

Parameters
keyThe key of the record.
expectedThe expected value. If the data is nullptr, no existing record is expected. If it is ANY_DATA, an existing record with any value is expacted.
desiredThe desired value. If the data is nullptr, the record is to be removed. If it is ANY_DATA, no update is done.
actualThe pointer to a string object to contain the actual value of the existing record. If it is nullptr, it is ignored.
foundThe pointer to a variable to contain whether there is an existing record. If it is nullptr, it is ignored.
Returns
The result status. If the condition doesn't meet, INFEASIBLE_ERROR is returned.

◆ Increment()

virtual Status tkrzw::DBM::Increment ( std::string_view  key,
int64_t  increment = 1,
int64_t *  current = nullptr,
int64_t  initial = 0 
)
virtual

Increments the numeric value of a record.

Parameters
keyThe key of the record.
incrementThe incremental value. If it is INT64MIN, the current value is not changed and a new record is not created.
currentThe pointer to an integer to contain the current value. If it is nullptr, it is ignored.
initialThe initial value.
Returns
The result status.

The record value is stored as an 8-byte big-endian integer. Negative is also supported.

◆ IncrementSimple()

virtual int64_t tkrzw::DBM::IncrementSimple ( std::string_view  key,
int64_t  increment = 1,
int64_t  initial = 0 
)
virtual

Increments the numeric value of a record, in a simple way.

Parameters
keyThe key of the record.
incrementThe incremental value.
initialThe initial value.
Returns
The current value or INT64MIN on failure.

The record value is treated as a decimal integer. Negative is also supported.

◆ ProcessMulti() [1/2]

virtual Status tkrzw::DBM::ProcessMulti ( const std::vector< std::pair< std::string_view, RecordProcessor * >> &  key_proc_pairs,
bool  writable 
)
pure virtual

Processes multiple records with processors.

Parameters
key_proc_pairsPairs of the keys and their processor objects.
writableTrue if the processors can edit the records.
Returns
The result status.

If the specified record exists, the ProcessFull of the processor is called. Otherwise, the ProcessEmpty of the processor is called.

◆ ProcessMulti() [2/2]

virtual Status tkrzw::DBM::ProcessMulti ( const std::vector< std::pair< std::string_view, RecordLambdaType >> &  key_lambda_pairs,
bool  writable 
)
virtual

Processes multiple records with lambda functions.

Parameters
key_lambda_pairsPairs of the keys and their lambda functions. The first parameter of the lambda functions is the key of the record, or RecordProcessor::NOOP if it the record doesn't exist. The return value is a string reference to RecordProcessor::NOOP, RecordProcessor::REMOVE, or the new record value.
writableTrue if the processors can edit the records.
Returns
The result status.

◆ CompareExchangeMulti()

virtual Status tkrzw::DBM::CompareExchangeMulti ( const std::vector< std::pair< std::string_view, std::string_view >> &  expected,
const std::vector< std::pair< std::string_view, std::string_view >> &  desired 
)
virtual

Compares the values of records and exchanges if the condition meets.

Parameters
expectedThe record keys and their expected values. If the value data is nullptr, no existing record is expected. If the value is ANY_DATA, an existing record with any value is expacted.
desiredThe record keys and their desired values. If the value is nullptr, the record is to be removed.
Returns
The result status. If the condition doesn't meet, INFEASIBLE_ERROR is returned.

Reimplemented in tkrzw::ShardDBM.

◆ Rekey()

virtual Status tkrzw::DBM::Rekey ( std::string_view  old_key,
std::string_view  new_key,
bool  overwrite = true,
bool  copying = false,
std::string *  value = nullptr 
)
virtual

Changes the key of a record.

Parameters
old_keyThe old key of the record.
new_keyThe new key of the record.
overwriteWhether to overwrite the existing record of the new key.
copyingWhether to retain the record of the old key.
valueThe pointer to a string object to contain the value of the record. If it is nullptr, the value data is ignored.
Returns
The result status. If there's no matching record to the old key, NOT_FOUND_ERROR is returned. If the overwrite flag is false and there is an existing record of the new key, DUPLICATION ERROR is returned.

This method is done atomically by ProcessMulti. The other threads observe that the record has either the old key or the new key. No intermediate states are observed.

◆ ProcessFirst() [1/2]

virtual Status tkrzw::DBM::ProcessFirst ( RecordProcessor proc,
bool  writable 
)
pure virtual

Processes the first record with a processor.

Parameters
procThe pointer to the processor object.
writableTrue if the processor can edit the record.
Returns
The result status.

If the first record exists, the ProcessFull of the processor is called. Otherwise, this method fails and no method of the processor is called. Whereas ordered databases have efficient implementations of this method, unordered databases have inefficient implementations.

Implemented in tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::StdTreeDBM, tkrzw::StdHashDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, tkrzw::HashDBM, tkrzw::CacheDBM, and tkrzw::BabyDBM.

◆ ProcessFirst() [2/2]

virtual Status tkrzw::DBM::ProcessFirst ( RecordLambdaType  rec_lambda,
bool  writable 
)
virtual

Processes the first record with a lambda function.

Parameters
rec_lambdaThe lambda function to process a record. The first parameter is the key of the record. The second parameter is the value of the record. The return value is a string reference to RecordProcessor::NOOP, RecordProcessor::REMOVE, or the new record value.
writableTrue if the processor can edit the record.
Returns
The result status.

◆ PopFirst()

virtual Status tkrzw::DBM::PopFirst ( std::string *  key = nullptr,
std::string *  value = nullptr 
)
virtual

Gets the first record and removes it.

Parameters
keyThe pointer to a string object to contain the key of the first record. If it is nullptr, it is ignored.
valueThe pointer to a string object to contain the value of the first record. If it is nullptr, it is ignored.
Returns
The result status.

◆ PushLast()

virtual Status tkrzw::DBM::PushLast ( std::string_view  value,
double  wtime = -1,
std::string *  key = nullptr 
)
virtual

Adds a record with a key of the current timestamp.

Parameters
valueThe value of the record.
wtimeThe current wall time used to generate the key. If it is negative, the system clock is used.
keyThe pointer to a string object to contain the generated key of the record. If it is nullptr, it is ignored.
Returns
The result status.

The key is generated as an 8-bite big-endian binary string of the timestamp. If there is an existing record matching the generated key, the key is regenerated and the attempt is repeated until it succeeds.

◆ ProcessEach() [1/2]

virtual Status tkrzw::DBM::ProcessEach ( RecordProcessor proc,
bool  writable 
)
pure virtual

Processes each and every record in the database with a processor.

Parameters
procThe pointer to the processor object.
writableTrue if the processor can edit the record.
Returns
The result status.

The ProcessFull of the processor is called repeatedly for each record. The ProcessEmpty of the processor is called once before the iteration and once after the iteration.

Implemented in tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::StdTreeDBM, tkrzw::StdHashDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, tkrzw::HashDBM, tkrzw::CacheDBM, and tkrzw::BabyDBM.

◆ ProcessEach() [2/2]

virtual Status tkrzw::DBM::ProcessEach ( RecordLambdaType  rec_lambda,
bool  writable 
)
virtual

Processes each and every record in the database with a lambda function.

Parameters
rec_lambdaThe lambda function to process a record. The first parameter is the key of the record. The second parameter is the value of the existing record, or RecordProcessor::NOOP if it the record doesn't exist. The return value is a string reference to RecordProcessor::NOOP, RecordProcessor::REMOVE, or the new record value.
writableTrue if the processor can edit the record.
Returns
The result status.

The lambda function is called repeatedly for each record. It is also called once before the iteration and once after the iteration with both the key and the value being RecordProcessor::NOOP.

◆ Count()

virtual Status tkrzw::DBM::Count ( int64_t *  count)
pure virtual

Gets the number of records.

Parameters
countThe pointer to an integer object to contain the result count.
Returns
The result status.

Implemented in tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::StdTreeDBM, tkrzw::StdHashDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, tkrzw::HashDBM, tkrzw::CacheDBM, and tkrzw::BabyDBM.

◆ CountSimple()

virtual int64_t tkrzw::DBM::CountSimple ( )
virtual

Gets the number of records, in a simple way.

Returns
The number of records on success, or -1 on failure.

◆ GetFileSize()

virtual Status tkrzw::DBM::GetFileSize ( int64_t *  size)
pure virtual

Gets the current file size of the database.

Parameters
sizeThe pointer to an integer object to contain the result size.
Returns
The result status.

Implemented in tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::StdTreeDBM, tkrzw::StdHashDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, tkrzw::HashDBM, tkrzw::CacheDBM, and tkrzw::BabyDBM.

◆ GetFileSizeSimple()

virtual int64_t tkrzw::DBM::GetFileSizeSimple ( )
virtual

Gets the current file size of the database, in a simple way.

Returns
The current file size of the database, or -1 on failure.

◆ GetFilePath()

virtual Status tkrzw::DBM::GetFilePath ( std::string *  path)
pure virtual

Gets the path of the database file.

Parameters
pathThe pointer to a string object to contain the result path.
Returns
The result status.

Implemented in tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::StdTreeDBM, tkrzw::StdHashDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, tkrzw::HashDBM, tkrzw::CacheDBM, and tkrzw::BabyDBM.

◆ GetFilePathSimple()

virtual std::string tkrzw::DBM::GetFilePathSimple ( )
virtual

Gets the path of the database file, in a simple way.

Returns
The file path of the database, or an empty string on failure.

◆ GetTimestamp()

virtual Status tkrzw::DBM::GetTimestamp ( double *  timestamp)
pure virtual

Gets the timestamp in seconds of the last modified time.

Parameters
timestampThe pointer to a double object to contain the timestamp.
Returns
The result status.

The timestamp is updated when the database opened in the writable mode is closed or synchronized, even if no updating opertion is done.

Implemented in tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::StdTreeDBM, tkrzw::StdHashDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, tkrzw::HashDBM, tkrzw::CacheDBM, and tkrzw::BabyDBM.

◆ GetTimestampSimple()

virtual double tkrzw::DBM::GetTimestampSimple ( )
virtual

Gets the timestamp of the last modified time, in a simple way.

Returns
The timestamp of the last modified time, or NaN on failure.

◆ Clear()

virtual Status tkrzw::DBM::Clear ( )
pure virtual

◆ Rebuild()

virtual Status tkrzw::DBM::Rebuild ( )
pure virtual

◆ ShouldBeRebuilt()

virtual Status tkrzw::DBM::ShouldBeRebuilt ( bool *  tobe)
pure virtual

Checks whether the database should be rebuilt.

Parameters
tobeThe pointer to a boolean object to contain the result decision.
Returns
The result status.

Implemented in tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::StdTreeDBM, tkrzw::StdHashDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, tkrzw::HashDBM, tkrzw::CacheDBM, and tkrzw::BabyDBM.

◆ ShouldBeRebuiltSimple()

virtual bool tkrzw::DBM::ShouldBeRebuiltSimple ( )
virtual

Checks whether the database should be rebuilt, in a simple way.

Returns
True if the database should be rebuilt or false if not or on failure.

◆ Synchronize()

virtual Status tkrzw::DBM::Synchronize ( bool  hard,
FileProcessor proc = nullptr 
)
pure virtual

Synchronizes the content of the database to the file system.

Parameters
hardTrue to do physical synchronization with the hardware or false to do only logical synchronization with the file system.
procThe pointer to the file processor object, whose Process method is called while the content of the file is synchronized. If it is nullptr, it is ignored.
Returns
The result status.

Implemented in tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::StdTreeDBM, tkrzw::StdHashDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, tkrzw::HashDBM, tkrzw::CacheDBM, and tkrzw::BabyDBM.

◆ CopyFileData()

virtual Status tkrzw::DBM::CopyFileData ( const std::string &  dest_path,
bool  sync_hard = false 
)
virtual

Copies the content of the database file to another file.

Parameters
dest_pathA path to the destination file.
sync_hardTrue to do physical synchronization with the hardware.
Returns
The result status.

Copying is done while the content is synchronized and stable. So, this method is suitable for making a backup file while running a database service.

Reimplemented in tkrzw::ShardDBM.

◆ Export()

virtual Status tkrzw::DBM::Export ( DBM dest_dbm)
virtual

Exports all records to another database.

Parameters
dest_dbmThe pointer to the destination database.
Returns
The result status.

◆ Inspect()

virtual std::vector<std::pair<std::string, std::string> > tkrzw::DBM::Inspect ( )
pure virtual

Inspects the database.

Returns
A vector of pairs of a property name and its value.

Implemented in tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::StdTreeDBM, tkrzw::StdHashDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, tkrzw::HashDBM, tkrzw::CacheDBM, and tkrzw::BabyDBM.

◆ IsOpen()

virtual bool tkrzw::DBM::IsOpen ( ) const
pure virtual

Checks whether the database is open.

Returns
True if the database is open, or false if not.

Implemented in tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::StdTreeDBM, tkrzw::StdHashDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, tkrzw::HashDBM, tkrzw::CacheDBM, and tkrzw::BabyDBM.

◆ IsWritable()

virtual bool tkrzw::DBM::IsWritable ( ) const
pure virtual

Checks whether the database is writable.

Returns
True if the database is writable, or false if not.

Implemented in tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::StdTreeDBM, tkrzw::StdHashDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, tkrzw::HashDBM, tkrzw::CacheDBM, and tkrzw::BabyDBM.

◆ IsHealthy()

virtual bool tkrzw::DBM::IsHealthy ( ) const
pure virtual

Checks whether the database condition is healthy.

Returns
True if the database condition is healthy, or false if not.

Implemented in tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::StdTreeDBM, tkrzw::StdHashDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, tkrzw::HashDBM, tkrzw::CacheDBM, and tkrzw::BabyDBM.

◆ IsOrdered()

virtual bool tkrzw::DBM::IsOrdered ( ) const
pure virtual

Checks whether ordered operations are supported.

Returns
True if ordered operations are supported, or false if not.

Implemented in tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::StdTreeDBM, tkrzw::StdHashDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, tkrzw::HashDBM, tkrzw::CacheDBM, and tkrzw::BabyDBM.

◆ MakeIterator()

virtual std::unique_ptr<Iterator> tkrzw::DBM::MakeIterator ( )
pure virtual

Makes an iterator for each record.

Returns
The iterator for each record.

Implemented in tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::StdTreeDBM, tkrzw::StdHashDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, tkrzw::HashDBM, tkrzw::CacheDBM, and tkrzw::BabyDBM.

◆ MakeDBM()

virtual std::unique_ptr<DBM> tkrzw::DBM::MakeDBM ( ) const
pure virtual

Makes a new DBM object of the same concrete class.

Returns
The new DBM object.

Implemented in tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::StdTreeDBM, tkrzw::StdHashDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, tkrzw::HashDBM, tkrzw::CacheDBM, and tkrzw::BabyDBM.

◆ GetUpdateLogger()

virtual UpdateLogger* tkrzw::DBM::GetUpdateLogger ( ) const
pure virtual

Gets the logger to write all update operations.

Returns
The update logger if it has been set or nullptr if it hasn't.

Implemented in tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::StdTreeDBM, tkrzw::StdHashDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, tkrzw::HashDBM, tkrzw::CacheDBM, and tkrzw::BabyDBM.

◆ SetUpdateLogger()

virtual void tkrzw::DBM::SetUpdateLogger ( UpdateLogger update_logger)
pure virtual

Sets the logger to write all update operations.

Parameters
update_loggerThe pointer to the update logger object. Ownership is not taken. If it is nullptr, no logger is used.

Implemented in tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::StdTreeDBM, tkrzw::StdHashDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::PolyDBM, tkrzw::HashDBM, tkrzw::CacheDBM, and tkrzw::BabyDBM.

◆ GetType()

const std::type_info& tkrzw::DBM::GetType ( ) const

Gets the type information of the actual class.

Returns
The type information of the actual class.

Member Data Documentation

◆ ANY_DATA

const std::string_view tkrzw::DBM::ANY_DATA
static

The special string_view value to represent any data.