Tkrzw
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
tkrzw::DBMUpdateLoggerMQ Class Referencefinal

DBM update logger with a message queue. More...

#include <tkrzw_dbm_ulog.h>

Classes

struct  UpdateLog
 Common structure of an update log. More...
 

Public Types

enum  OpType : int32_t { OP_VOID = 0 , OP_SET = 1 , OP_REMOVE = 2 , OP_CLEAR = 3 }
 Enumeration for operation types. More...
 

Public Member Functions

 DBMUpdateLoggerMQ (MessageQueue *mq, int32_t server_id=0, int32_t dbm_index=0, int64_t fixed_timestamp=-1)
 Constructor. More...
 
Status WriteSet (std::string_view key, std::string_view value) override
 Writes a log for modifying an existing record or adding a new record. More...
 
Status WriteRemove (std::string_view key) override
 Writes a log for removing an existing record. More...
 
Status WriteClear () override
 Writes a log for removing all records. More...
 
Status Synchronize (bool hard) override
 Synchronizes the metadata and content to the file system. More...
 
- Public Member Functions inherited from tkrzw::DBM::UpdateLogger
virtual ~UpdateLogger ()=default
 Destructor. More...
 

Static Public Member Functions

static void OverwriteThreadServerID (int32_t server_id)
 Overwrites the server ID of the current thread. More...
 
static Status ParseUpdateLog (std::string_view message, UpdateLog *op)
 Parses an update log message. More...
 
static Status ApplyUpdateLog (DBM *dbm, std::string_view message, int32_t server_id=INT32MIN+1, int32_t dbm_index=INT32MIN+1)
 Applys the operation in an update log to a database. More...
 
static Status ApplyUpdateLogFromFiles (DBM *dbm, const std::string &prefix, double min_timestamp=0, int32_t server_id=INT32MIN+1, int32_t dbm_index=INT32MIN+1)
 Applys the operations in the message queue files. More...
 

Detailed Description

DBM update logger with a message queue.

Member Enumeration Documentation

◆ OpType

Enumeration for operation types.

Enumerator
OP_VOID 

Invalid operation.

OP_SET 

To modify or add a record.

OP_REMOVE 

To remove a record.

OP_CLEAR 

To remove all records.

Constructor & Destructor Documentation

◆ DBMUpdateLoggerMQ()

tkrzw::DBMUpdateLoggerMQ::DBMUpdateLoggerMQ ( MessageQueue mq,
int32_t  server_id = 0,
int32_t  dbm_index = 0,
int64_t  fixed_timestamp = -1 
)
explicit

Constructor.

Parameters
mqThe message queue object to store update logs. The ownership is not taken.
server_idThe server ID of the process.
dbm_indexThe index of the DBM on the server.
fixed_timestampIf not negative, the timestamp is fixed to the value.

Member Function Documentation

◆ WriteSet()

Status tkrzw::DBMUpdateLoggerMQ::WriteSet ( std::string_view  key,
std::string_view  value 
)
overridevirtual

Writes a log for modifying an existing record or adding a new record.

Parameters
keyThe key of the record.
valueThe new value of the record.
Returns
The result status.

Implements tkrzw::DBM::UpdateLogger.

◆ WriteRemove()

Status tkrzw::DBMUpdateLoggerMQ::WriteRemove ( std::string_view  key)
overridevirtual

Writes a log for removing an existing record.

Parameters
keyThe key of the record.
Returns
The result status.

Implements tkrzw::DBM::UpdateLogger.

◆ WriteClear()

Status tkrzw::DBMUpdateLoggerMQ::WriteClear ( )
overridevirtual

Writes a log for removing all records.

Returns
The result status.

Implements tkrzw::DBM::UpdateLogger.

◆ Synchronize()

Status tkrzw::DBMUpdateLoggerMQ::Synchronize ( bool  hard)
overridevirtual

Synchronizes the metadata and content to the file system.

Parameters
hardTrue to do physical synchronization with the hardware or false to do only logical synchronization with the file system.
Returns
The result status.

Reimplemented from tkrzw::DBM::UpdateLogger.

◆ OverwriteThreadServerID()

static void tkrzw::DBMUpdateLoggerMQ::OverwriteThreadServerID ( int32_t  server_id)
static

Overwrites the server ID of the current thread.

Parameters
server_idThe server ID of the process. If it is negative, the thread local setting is undone. If it is INT32MIN, logging of the current thread is disable.

This affects logging of only the current thread regardless of the logger instance.

◆ ParseUpdateLog()

static Status tkrzw::DBMUpdateLoggerMQ::ParseUpdateLog ( std::string_view  message,
UpdateLog op 
)
static

Parses an update log message.

Parameters
messageThe update log message.
opThe pointer to the update log object to store the result. The life duration of the key and the value fields is the same as the given message.
Returns
The result status.

◆ ApplyUpdateLog()

static Status tkrzw::DBMUpdateLoggerMQ::ApplyUpdateLog ( DBM dbm,
std::string_view  message,
int32_t  server_id = INT32MIN+1,
int32_t  dbm_index = INT32MIN+1 
)
static

Applys the operation in an update log to a database.

Parameters
dbmThe DBM object of the database.
messageThe update log message.
server_idThe server ID to focus on. A negative applies a filter which ignores the message if the server ID mathces the absolute value. Zero or a positive applies a filter which adopts the message if the server ID matches the value.
dbm_indexThe DBM index to focus on. A negative applies a filter which ignores the message if the DBM index mathces the absolute value. Zero or a positive applies a filter which adopts the message if the DBM index matches the value.
Returns
The result status. If the log is ignored due to the filter, INFEASIBLE_ERROR is returned.

◆ ApplyUpdateLogFromFiles()

static Status tkrzw::DBMUpdateLoggerMQ::ApplyUpdateLogFromFiles ( DBM dbm,
const std::string &  prefix,
double  min_timestamp = 0,
int32_t  server_id = INT32MIN+1,
int32_t  dbm_index = INT32MIN+1 
)
static

Applys the operations in the message queue files.

Parameters
dbmThe DBM object of the database.
prefixThe prefix for the message queue file names.
min_timestampThe minimum timestamp in milliseconds of messages to read.
server_idThe server ID to focus on. A negative applies a filter which ignores the message if the server ID mathces the absolute value. Zero or a positive applies a filter which adopts the message if the server ID matches the value.
dbm_indexThe DBM index to focus on. A negative applies a filter which ignores the message if the DBM index mathces the absolute value. Zero or a positive applies a filter which adopts the message if the DBM index matches the value.
Returns
The result status.