Kyoto Tycoon
|
Remote database. More...
#include <ktremotedb.h>
Classes | |
struct | BulkRecord |
Record for bulk operation. More... | |
class | Cursor |
Cursor to indicate a record. More... | |
class | Error |
Error data. More... | |
struct | OrderedKey |
Key with the order. | |
Public Types | |
enum | BinaryMagic { BMNOP = 0xb0, BMREPLICATION = 0xb1, BMPLAYSCRIPT = 0xb4, BMSETBULK = 0xb8, BMREMOVEBULK = 0xb9, BMGETBULK = 0xba, BMERROR = 0xbf } |
Magic data in binary protocol. More... | |
enum | BinaryOption { BONOREPLY = 1 << 0 } |
Options in binary protocol. More... | |
Public Member Functions | |
RemoteDB () | |
Default constructor. | |
virtual | ~RemoteDB () |
Destructor. | |
Error | error () const |
Get the last happened error code. | |
bool | open (const std::string &host="", int32_t port=DEFPORT, double timeout=-1) |
Open the connection. | |
bool | close (bool grace=true) |
Close the connection. | |
bool | report (std::map< std::string, std::string > *strmap) |
Get the report of the server information. | |
bool | play_script (const std::string &name, const std::map< std::string, std::string > ¶ms, std::map< std::string, std::string > *result) |
Call a procedure of the scripting extension. | |
bool | tune_replication (const std::string &host="", int32_t port=DEFPORT, uint64_t ts=kc::UINT64MAX, double iv=-1) |
Set the replication configuration. | |
bool | ulog_list (std::vector< UpdateLogger::FileStatus > *fstvec) |
Get status of each update log files. | |
bool | ulog_remove (uint64_t ts=kc::UINT64MAX) |
Remove old update log files. | |
bool | status (std::map< std::string, std::string > *strmap) |
Get the miscellaneous status information. | |
bool | clear () |
Remove all records. | |
bool | synchronize (bool hard, const std::string &command="") |
Synchronize updated contents with the file and the device. | |
int64_t | count () |
Get the number of records. | |
int64_t | size () |
Get the size of the database file. | |
bool | set (const char *kbuf, size_t ksiz, const char *vbuf, size_t vsiz, int64_t xt=kc::INT64MAX) |
Set the value of a record. | |
bool | set (const std::string &key, const std::string &value, int64_t xt=kc::INT64MAX) |
Set the value of a record. | |
bool | add (const char *kbuf, size_t ksiz, const char *vbuf, size_t vsiz, int64_t xt=kc::INT64MAX) |
Add a record. | |
bool | add (const std::string &key, const std::string &value, int64_t xt=kc::INT64MAX) |
Set the value of a record. | |
bool | replace (const char *kbuf, size_t ksiz, const char *vbuf, size_t vsiz, int64_t xt=kc::INT64MAX) |
Replace the value of a record. | |
bool | replace (const std::string &key, const std::string &value, int64_t xt=kc::INT64MAX) |
Replace the value of a record. | |
bool | append (const char *kbuf, size_t ksiz, const char *vbuf, size_t vsiz, int64_t xt=kc::INT64MAX) |
Append the value of a record. | |
bool | append (const std::string &key, const std::string &value, int64_t xt=kc::INT64MAX) |
Set the value of a record. | |
int64_t | increment (const char *kbuf, size_t ksiz, int64_t num, int64_t orig=0, int64_t xt=kc::INT64MAX) |
Add a number to the numeric integer value of a record. | |
int64_t | increment (const std::string &key, int64_t num, int64_t orig=0, int64_t xt=kc::INT64MAX) |
Add a number to the numeric integer value of a record. | |
double | increment_double (const char *kbuf, size_t ksiz, double num, double orig=0, int64_t xt=kc::INT64MAX) |
Add a number to the numeric double value of a record. | |
double | increment_double (const std::string &key, double num, double orig=0, int64_t xt=kc::INT64MAX) |
Add a number to the numeric double value of a record. | |
bool | cas (const char *kbuf, size_t ksiz, const char *ovbuf, size_t ovsiz, const char *nvbuf, size_t nvsiz, int64_t xt=kc::INT64MAX) |
Perform compare-and-swap. | |
bool | cas (const std::string &key, const std::string &ovalue, const std::string &nvalue, int64_t xt=kc::INT64MAX) |
Perform compare-and-swap. | |
bool | remove (const char *kbuf, size_t ksiz) |
Remove a record. | |
bool | remove (const std::string &key) |
Remove a record. | |
char * | get (const char *kbuf, size_t ksiz, size_t *sp, int64_t *xtp=NULL) |
Retrieve the value of a record. | |
bool | get (const std::string &key, std::string *value, int64_t *xtp=NULL) |
Retrieve the value of a record. | |
int32_t | check (const char *kbuf, size_t ksiz, int64_t *xtp=NULL) |
Check the existence of a record. | |
int32_t | check (const std::string &key, int64_t *xtp=NULL) |
Check the existence of a record. | |
char * | seize (const char *kbuf, size_t ksiz, size_t *sp, int64_t *xtp=NULL) |
Retrieve the value of a record and remove it atomically. | |
bool | seize (const std::string &key, std::string *value, int64_t *xtp=NULL) |
Retrieve the value of a record and remove it atomically. | |
int64_t | set_bulk (const std::map< std::string, std::string > &recs, int64_t xt=kc::INT64MAX, bool atomic=true) |
Store records at once. | |
int64_t | remove_bulk (const std::vector< std::string > &keys, bool atomic=true) |
Store records at once. | |
int64_t | get_bulk (const std::vector< std::string > &keys, std::map< std::string, std::string > *recs, bool atomic=true) |
Retrieve records at once. | |
bool | vacuum (int64_t step=0) |
Scan the database and eliminate regions of expired records. | |
int64_t | match_prefix (const std::string &prefix, std::vector< std::string > *strvec, int64_t max=-1) |
Get keys matching a prefix string. | |
int64_t | match_regex (const std::string ®ex, std::vector< std::string > *strvec, int64_t max=-1) |
Get keys matching a regular expression string. | |
int64_t | match_similar (const std::string &origin, size_t range, bool utf, std::vector< std::string > *strvec, int64_t max=-1) |
Get keys similar to a string in terms of the levenshtein distance. | |
void | set_target (const std::string &expr) |
Set the target database. | |
void | set_signal_waiting (const std::string &name, double timeout=0) |
Set the signal waiting condition of the next procedure. | |
void | set_signal_sending (const std::string &name, bool broadcast=false) |
Set the signal sending condition of the next procedure. | |
bool | play_script_binary (const std::string &name, const std::map< std::string, std::string > ¶ms, std::map< std::string, std::string > *result=NULL, uint32_t opts=0) |
Call a procedure of the scripting extension in the binary protocol. | |
int64_t | set_bulk_binary (const std::vector< BulkRecord > &recs, uint32_t opts=0) |
Store records at once in the binary protocol. | |
int64_t | remove_bulk_binary (const std::vector< BulkRecord > &recs, uint32_t opts=0) |
Store records at once in the binary protocol. | |
int64_t | get_bulk_binary (std::vector< BulkRecord > *recs) |
Retrieve records at once in the binary protocol. | |
const std::string | expression () |
Get the expression of the socket. | |
Cursor * | cursor () |
Create a cursor object. | |
Static Public Attributes | |
static const size_t | DATAMAXSIZ = 1ULL << 28 |
The maximum size of each record data. |
Remote database.
kyototycoon::RemoteDB::RemoteDB | ( | ) | [explicit] |
Default constructor.
virtual kyototycoon::RemoteDB::~RemoteDB | ( | ) | [virtual] |
Destructor.
Error kyototycoon::RemoteDB::error | ( | ) | const |
Get the last happened error code.
bool kyototycoon::RemoteDB::open | ( | const std::string & | host = "" , |
int32_t | port = DEFPORT , |
||
double | timeout = -1 |
||
) |
Open the connection.
host | the name or the address of the server. If it is an empty string, the local host is specified. |
port | the port numger of the server. |
timeout | the timeout of each operation in seconds. If it is not more than 0, no timeout is specified. |
bool kyototycoon::RemoteDB::close | ( | bool | grace = true | ) |
Close the connection.
grace | true for graceful shutdown, or false for immediate disconnection. |
bool kyototycoon::RemoteDB::report | ( | std::map< std::string, std::string > * | strmap | ) |
Get the report of the server information.
strmap | a string map to contain the result. |
bool kyototycoon::RemoteDB::play_script | ( | const std::string & | name, |
const std::map< std::string, std::string > & | params, | ||
std::map< std::string, std::string > * | result | ||
) |
Call a procedure of the scripting extension.
name | the name of the procedure to call. |
params | a string map containing the input parameters. |
result | a string map to contain the output data. |
bool kyototycoon::RemoteDB::tune_replication | ( | const std::string & | host = "" , |
int32_t | port = DEFPORT , |
||
uint64_t | ts = kc::UINT64MAX , |
||
double | iv = -1 |
||
) |
Set the replication configuration.
host | the name or the address of the master server. If it is an empty string, replication is disabled. |
port | the port numger of the server. |
ts | the maximum time stamp of already read logs. If it is kyotocabinet::UINT64MAX, the current setting is not modified. If it is kyotocabinet::UINT64MAX - 1, the current time is specified. |
iv | the interval of each replication operation in milliseconds. If it is negative, the current interval is not modified. |
bool kyototycoon::RemoteDB::ulog_list | ( | std::vector< UpdateLogger::FileStatus > * | fstvec | ) |
Get status of each update log files.
fstvec | a vector to store status structures of each update log files. |
bool kyototycoon::RemoteDB::ulog_remove | ( | uint64_t | ts = kc::UINT64MAX | ) |
Remove old update log files.
ts | the maximum time stamp of disposable logs. |
bool kyototycoon::RemoteDB::status | ( | std::map< std::string, std::string > * | strmap | ) |
Get the miscellaneous status information.
strmap | a string map to contain the result. |
bool kyototycoon::RemoteDB::clear | ( | ) |
Remove all records.
bool kyototycoon::RemoteDB::synchronize | ( | bool | hard, |
const std::string & | command = "" |
||
) |
Synchronize updated contents with the file and the device.
hard | true for physical synchronization with the device, or false for logical synchronization with the file system. |
command | the command name to process the database file. If it is an empty string, no postprocessing is performed. |
int64_t kyototycoon::RemoteDB::count | ( | ) |
Get the number of records.
int64_t kyototycoon::RemoteDB::size | ( | ) |
Get the size of the database file.
bool kyototycoon::RemoteDB::set | ( | const char * | kbuf, |
size_t | ksiz, | ||
const char * | vbuf, | ||
size_t | vsiz, | ||
int64_t | xt = kc::INT64MAX |
||
) |
Set the value of a record.
kbuf | the pointer to the key region. |
ksiz | the size of the key region. |
vbuf | the pointer to the value region. |
vsiz | the size of the value region. |
xt | the expiration time from now in seconds. If it is negative, the absolute value is treated as the epoch time. |
bool kyototycoon::RemoteDB::set | ( | const std::string & | key, |
const std::string & | value, | ||
int64_t | xt = kc::INT64MAX |
||
) |
Set the value of a record.
bool kyototycoon::RemoteDB::add | ( | const char * | kbuf, |
size_t | ksiz, | ||
const char * | vbuf, | ||
size_t | vsiz, | ||
int64_t | xt = kc::INT64MAX |
||
) |
Add a record.
kbuf | the pointer to the key region. |
ksiz | the size of the key region. |
vbuf | the pointer to the value region. |
vsiz | the size of the value region. |
xt | the expiration time from now in seconds. If it is negative, the absolute value is treated as the epoch time. |
bool kyototycoon::RemoteDB::add | ( | const std::string & | key, |
const std::string & | value, | ||
int64_t | xt = kc::INT64MAX |
||
) |
Set the value of a record.
bool kyototycoon::RemoteDB::replace | ( | const char * | kbuf, |
size_t | ksiz, | ||
const char * | vbuf, | ||
size_t | vsiz, | ||
int64_t | xt = kc::INT64MAX |
||
) |
Replace the value of a record.
kbuf | the pointer to the key region. |
ksiz | the size of the key region. |
vbuf | the pointer to the value region. |
vsiz | the size of the value region. |
xt | the expiration time from now in seconds. If it is negative, the absolute value is treated as the epoch time. |
bool kyototycoon::RemoteDB::replace | ( | const std::string & | key, |
const std::string & | value, | ||
int64_t | xt = kc::INT64MAX |
||
) |
Replace the value of a record.
bool kyototycoon::RemoteDB::append | ( | const char * | kbuf, |
size_t | ksiz, | ||
const char * | vbuf, | ||
size_t | vsiz, | ||
int64_t | xt = kc::INT64MAX |
||
) |
Append the value of a record.
kbuf | the pointer to the key region. |
ksiz | the size of the key region. |
vbuf | the pointer to the value region. |
vsiz | the size of the value region. |
xt | the expiration time from now in seconds. If it is negative, the absolute value is treated as the epoch time. |
bool kyototycoon::RemoteDB::append | ( | const std::string & | key, |
const std::string & | value, | ||
int64_t | xt = kc::INT64MAX |
||
) |
Set the value of a record.
int64_t kyototycoon::RemoteDB::increment | ( | const char * | kbuf, |
size_t | ksiz, | ||
int64_t | num, | ||
int64_t | orig = 0 , |
||
int64_t | xt = kc::INT64MAX |
||
) |
Add a number to the numeric integer value of a record.
kbuf | the pointer to the key region. |
ksiz | the size of the key region. |
num | the additional number. |
orig | the origin number if no record corresponds to the key. If it is INT64MIN and no record corresponds, this function fails. If it is INT64MAX, the value is set as the additional number regardless of the current value. |
xt | the expiration time from now in seconds. If it is negative, the absolute value is treated as the epoch time. |
int64_t kyototycoon::RemoteDB::increment | ( | const std::string & | key, |
int64_t | num, | ||
int64_t | orig = 0 , |
||
int64_t | xt = kc::INT64MAX |
||
) |
Add a number to the numeric integer value of a record.
double kyototycoon::RemoteDB::increment_double | ( | const char * | kbuf, |
size_t | ksiz, | ||
double | num, | ||
double | orig = 0 , |
||
int64_t | xt = kc::INT64MAX |
||
) |
Add a number to the numeric double value of a record.
kbuf | the pointer to the key region. |
ksiz | the size of the key region. |
num | the additional number. |
orig | the origin number if no record corresponds to the key. If it is negative infinity and no record corresponds, this function fails. If it is positive infinity, the value is set as the additional number regardless of the current value. |
xt | the expiration time from now in seconds. If it is negative, the absolute value is treated as the epoch time. |
double kyototycoon::RemoteDB::increment_double | ( | const std::string & | key, |
double | num, | ||
double | orig = 0 , |
||
int64_t | xt = kc::INT64MAX |
||
) |
Add a number to the numeric double value of a record.
bool kyototycoon::RemoteDB::cas | ( | const char * | kbuf, |
size_t | ksiz, | ||
const char * | ovbuf, | ||
size_t | ovsiz, | ||
const char * | nvbuf, | ||
size_t | nvsiz, | ||
int64_t | xt = kc::INT64MAX |
||
) |
Perform compare-and-swap.
kbuf | the pointer to the key region. |
ksiz | the size of the key region. |
ovbuf | the pointer to the old value region. NULL means that no record corresponds. |
ovsiz | the size of the old value region. |
nvbuf | the pointer to the new value region. NULL means that the record is removed. |
nvsiz | the size of new old value region. |
xt | the expiration time from now in seconds. If it is negative, the absolute value is treated as the epoch time. |
bool kyototycoon::RemoteDB::cas | ( | const std::string & | key, |
const std::string & | ovalue, | ||
const std::string & | nvalue, | ||
int64_t | xt = kc::INT64MAX |
||
) |
Perform compare-and-swap.
bool kyototycoon::RemoteDB::remove | ( | const char * | kbuf, |
size_t | ksiz | ||
) |
Remove a record.
kbuf | the pointer to the key region. |
ksiz | the size of the key region. |
bool kyototycoon::RemoteDB::remove | ( | const std::string & | key | ) |
Remove a record.
char* kyototycoon::RemoteDB::get | ( | const char * | kbuf, |
size_t | ksiz, | ||
size_t * | sp, | ||
int64_t * | xtp = NULL |
||
) |
Retrieve the value of a record.
kbuf | the pointer to the key region. |
ksiz | the size of the key region. |
sp | the pointer to the variable into which the size of the region of the return value is assigned. |
xtp | the pointer to the variable into which the absolute expiration time is assigned. If it is NULL, it is ignored. |
bool kyototycoon::RemoteDB::get | ( | const std::string & | key, |
std::string * | value, | ||
int64_t * | xtp = NULL |
||
) |
Retrieve the value of a record.
int32_t kyototycoon::RemoteDB::check | ( | const char * | kbuf, |
size_t | ksiz, | ||
int64_t * | xtp = NULL |
||
) |
Check the existence of a record.
kbuf | the pointer to the key region. |
ksiz | the size of the key region. |
xtp | the pointer to the variable into which the absolute expiration time is assigned. If it is NULL, it is ignored. |
int32_t kyototycoon::RemoteDB::check | ( | const std::string & | key, |
int64_t * | xtp = NULL |
||
) |
Check the existence of a record.
char* kyototycoon::RemoteDB::seize | ( | const char * | kbuf, |
size_t | ksiz, | ||
size_t * | sp, | ||
int64_t * | xtp = NULL |
||
) |
Retrieve the value of a record and remove it atomically.
kbuf | the pointer to the key region. |
ksiz | the size of the key region. |
sp | the pointer to the variable into which the size of the region of the return value is assigned. |
xtp | the pointer to the variable into which the absolute expiration time is assigned. If it is NULL, it is ignored. |
bool kyototycoon::RemoteDB::seize | ( | const std::string & | key, |
std::string * | value, | ||
int64_t * | xtp = NULL |
||
) |
Retrieve the value of a record and remove it atomically.
int64_t kyototycoon::RemoteDB::set_bulk | ( | const std::map< std::string, std::string > & | recs, |
int64_t | xt = kc::INT64MAX , |
||
bool | atomic = true |
||
) |
Store records at once.
recs | the records to store. |
xt | the expiration time from now in seconds. If it is negative, the absolute value is treated as the epoch time. |
atomic | true to perform all operations atomically, or false for non-atomic operations. |
int64_t kyototycoon::RemoteDB::remove_bulk | ( | const std::vector< std::string > & | keys, |
bool | atomic = true |
||
) |
Store records at once.
keys | the keys of the records to remove. |
atomic | true to perform all operations atomically, or false for non-atomic operations. |
int64_t kyototycoon::RemoteDB::get_bulk | ( | const std::vector< std::string > & | keys, |
std::map< std::string, std::string > * | recs, | ||
bool | atomic = true |
||
) |
Retrieve records at once.
keys | the keys of the records to retrieve. |
recs | a string map to contain the retrieved records. |
atomic | true to perform all operations atomically, or false for non-atomic operations. |
bool kyototycoon::RemoteDB::vacuum | ( | int64_t | step = 0 | ) |
Scan the database and eliminate regions of expired records.
step | the number of steps. If it is not more than 0, the whole region is scanned. |
int64_t kyototycoon::RemoteDB::match_prefix | ( | const std::string & | prefix, |
std::vector< std::string > * | strvec, | ||
int64_t | max = -1 |
||
) |
Get keys matching a prefix string.
prefix | the prefix string. |
strvec | a string vector to contain the result. |
max | the maximum number to retrieve. If it is negative, no limit is specified. |
int64_t kyototycoon::RemoteDB::match_regex | ( | const std::string & | regex, |
std::vector< std::string > * | strvec, | ||
int64_t | max = -1 |
||
) |
Get keys matching a regular expression string.
regex | the regular expression string. |
strvec | a string vector to contain the result. |
max | the maximum number to retrieve. If it is negative, no limit is specified. |
int64_t kyototycoon::RemoteDB::match_similar | ( | const std::string & | origin, |
size_t | range, | ||
bool | utf, | ||
std::vector< std::string > * | strvec, | ||
int64_t | max = -1 |
||
) |
Get keys similar to a string in terms of the levenshtein distance.
origin | the origin string. |
range | the maximum distance of keys to adopt. |
utf | flag to treat keys as UTF-8 strings. |
strvec | a string vector to contain the result. |
max | the maximum number to retrieve. If it is negative, no limit is specified. |
void kyototycoon::RemoteDB::set_target | ( | const std::string & | expr | ) |
Set the target database.
expr | the expression of the target database. |
void kyototycoon::RemoteDB::set_signal_waiting | ( | const std::string & | name, |
double | timeout = 0 |
||
) |
Set the signal waiting condition of the next procedure.
name | the name of the condition variable. |
timeout | the timeout in seconds. |
void kyototycoon::RemoteDB::set_signal_sending | ( | const std::string & | name, |
bool | broadcast = false |
||
) |
Set the signal sending condition of the next procedure.
name | the name of the condition variable. |
broadcast | true to send the signal to every corresponding thread, or false to send it to just one thread. |
bool kyototycoon::RemoteDB::play_script_binary | ( | const std::string & | name, |
const std::map< std::string, std::string > & | params, | ||
std::map< std::string, std::string > * | result = NULL , |
||
uint32_t | opts = 0 |
||
) |
Call a procedure of the scripting extension in the binary protocol.
name | the name of the procedure to call. |
params | a string map containing the input parameters. |
result | a string map to contain the output data. If it is NULL, it is ignored. |
opts | the optional features by bitwise-or: RemoteDB::BONOREPLY to ignore reply from the server. |
int64_t kyototycoon::RemoteDB::set_bulk_binary | ( | const std::vector< BulkRecord > & | recs, |
uint32_t | opts = 0 |
||
) |
Store records at once in the binary protocol.
recs | the records to store. |
opts | the optional features by bitwise-or: RemoteDB::BONOREPLY to ignore reply from the server. |
int64_t kyototycoon::RemoteDB::remove_bulk_binary | ( | const std::vector< BulkRecord > & | recs, |
uint32_t | opts = 0 |
||
) |
Store records at once in the binary protocol.
recs | the records to remove. |
opts | the optional features by bitwise-or: RemoteDB::BONOREPLY to ignore reply from the server. |
int64_t kyototycoon::RemoteDB::get_bulk_binary | ( | std::vector< BulkRecord > * | recs | ) |
Retrieve records at once in the binary protocol.
recs | the records to retrieve. The value member and the xt member of each retrieved record will be set appropriately. The xt member of each missing record will be -1. |
const std::string kyototycoon::RemoteDB::expression | ( | ) |
Get the expression of the socket.
Create a cursor object.
const size_t kyototycoon::RemoteDB::DATAMAXSIZ = 1ULL << 28 [static] |
The maximum size of each record data.