Class | TokyoCabinet::HDB |
In: |
tokyocabinet.c
tokyocabinet-doc.rb |
Parent: | Object |
Hash database is a file containing a hash table and is handled with the hash database API. Before operations to store or retrieve records, it is necessary to open a database file and connect the hash database object to it. To avoid data missing or corruption, it is important to close every database file when it is no longer in use. It is forbidden for multible database objects in a process to open the same database at the same time.%% Except for the interface below, methods compatible with the `Hash’ class are also provided; `[]’, `[]=’, `store’, `delete’, `fetch’, `has_key?’, `has_value?’, `key’, `clear’, `length’, `empty?’, `each’, `each_key’, `each_value’, and `keys’.%%
ESUCCESS | = | INT2NUM(TCESUCCESS) | ||
ETHREAD | = | INT2NUM(TCETHREAD) | ||
EINVALID | = | INT2NUM(TCEINVALID) | ||
ENOFILE | = | INT2NUM(TCENOFILE) | ||
ENOPERM | = | INT2NUM(TCENOPERM) | ||
EMETA | = | INT2NUM(TCEMETA) | ||
ERHEAD | = | INT2NUM(TCERHEAD) | ||
EOPEN | = | INT2NUM(TCEOPEN) | ||
ECLOSE | = | INT2NUM(TCECLOSE) | ||
ETRUNC | = | INT2NUM(TCETRUNC) | ||
ESYNC | = | INT2NUM(TCESYNC) | ||
ESTAT | = | INT2NUM(TCESTAT) | ||
ESEEK | = | INT2NUM(TCESEEK) | ||
EREAD | = | INT2NUM(TCEREAD) | ||
EWRITE | = | INT2NUM(TCEWRITE) | ||
EMMAP | = | INT2NUM(TCEMMAP) | ||
ELOCK | = | INT2NUM(TCELOCK) | ||
EUNLINK | = | INT2NUM(TCEUNLINK) | ||
ERENAME | = | INT2NUM(TCERENAME) | ||
EMKDIR | = | INT2NUM(TCEMKDIR) | ||
ERMDIR | = | INT2NUM(TCERMDIR) | ||
EKEEP | = | INT2NUM(TCEKEEP) | ||
ENOREC | = | INT2NUM(TCENOREC) | ||
EMISC | = | INT2NUM(TCEMISC) | ||
TLARGE | = | INT2NUM(HDBTLARGE) | ||
TDEFLATE | = | INT2NUM(HDBTDEFLATE) | ||
TBZIP | = | INT2NUM(HDBTBZIP) | ||
TTCBS | = | INT2NUM(HDBTTCBS) | ||
OREADER | = | INT2NUM(HDBOREADER) | ||
OWRITER | = | INT2NUM(HDBOWRITER) | ||
OCREAT | = | INT2NUM(HDBOCREAT) | ||
OTRUNC | = | INT2NUM(HDBOTRUNC) | ||
ONOLCK | = | INT2NUM(HDBONOLCK) | ||
OLCKNB | = | INT2NUM(HDBOLCKNB) | ||
OTSYNC | = | INT2NUM(HDBOTSYNC) | ||
ESUCCESS | = | 0 | error code: success | |
ETHREAD | = | 1 | error code: threading error | |
EINVALID | = | 2 | error code: invalid operation | |
ENOFILE | = | 3 | error code: file not found | |
ENOPERM | = | 4 | error code: no permission | |
EMETA | = | 5 | error code: invalid meta data | |
ERHEAD | = | 6 | error code: invalid record header | |
EOPEN | = | 7 | error code: open error | |
ECLOSE | = | 8 | error code: close error | |
ETRUNC | = | 9 | error code: trunc error | |
ESYNC | = | 10 | error code: sync error | |
ESTAT | = | 11 | error code: stat error | |
ESEEK | = | 12 | error code: seek error | |
EREAD | = | 13 | error code: read error | |
EWRITE | = | 14 | error code: write error | |
EMMAP | = | 15 | error code: mmap error | |
ELOCK | = | 16 | error code: lock error | |
EUNLINK | = | 17 | error code: unlink error | |
ERENAME | = | 18 | error code: rename error | |
EMKDIR | = | 19 | error code: mkdir error | |
ERMDIR | = | 20 | error code: rmdir error | |
EKEEP | = | 21 | error code: existing record | |
ENOREC | = | 22 | error code: no record found | |
EMISC | = | 9999 | error code: miscellaneous error | |
TLARGE | = | 1 << 0 | tuning option: use 64-bit bucket array | |
TDEFLATE | = | 1 << 1 | tuning option: compress each record with Deflate | |
TBZIP | = | 1 << 2 | tuning option: compress each record with BZIP2 | |
TTCBS | = | 1 << 3 | tuning option: compress each record with TCBS | |
OREADER | = | 1 << 0 | open mode: open as a reader | |
OWRITER | = | 1 << 1 | open mode: open as a writer | |
OCREAT | = | 1 << 2 | open mode: writer creating | |
OTRUNC | = | 1 << 3 | open mode: writer truncating | |
ONOLCK | = | 1 << 4 | open mode: open without locking | |
OLCKNB | = | 1 << 5 | open mode: lock without blocking | |
OTSYNC | = | 1 << 6 | open mode: synchronize every transaction |
Add a real number to a record.%% `key’ specifies the key.%% `num’ specifies the additional value.%% If successful, the return value is the summation value, else, it is `nil’.%% If the corresponding record exists, the value is treated as a real number and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack’ method with the `d’ operator after retrieval.%%
# File tokyocabinet-doc.rb, line 237 237: def adddouble(key, num) 238: # (native code) 239: end
Add an integer to a record.%% `key’ specifies the key.%% `num’ specifies the additional value.%% If successful, the return value is the summation value, else, it is `nil’.%% If the corresponding record exists, the value is treated as an integer and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack’ method with the `i’ operator after retrieval.%%
# File tokyocabinet-doc.rb, line 229 229: def addint(key, num) 230: # (native code) 231: end
Close the database file.%% If successful, the return value is true, else, it is false.%% Update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken.%%
# File tokyocabinet-doc.rb, line 151 151: def close() 152: # (native code) 153: end
Copy the database file.%% `path’ specifies the path of the destination file. If it begins with `@’, the trailing substring is executed as a command line.%% If successful, the return value is true, else, it is false. False is returned if the executed command returns non-zero code.%% The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.%%
# File tokyocabinet-doc.rb, line 265 265: def copy(path) 266: # (native code) 267: end
Get the last happened error code.%% The return value is the last happened error code.%% The following error codes are defined: `TokyoCabinet::HDB::ESUCCESS’ for success, `TokyoCabinet::HDB::ETHREAD’ for threading error, `TokyoCabinet::HDB::EINVALID’ for invalid operation, `TokyoCabinet::HDB::ENOFILE’ for file not found, `TokyoCabinet::HDB::ENOPERM’ for no permission, `TokyoCabinet::HDB::EMETA’ for invalid meta data, `TokyoCabinet::HDB::ERHEAD’ for invalid record header, `TokyoCabinet::HDB::EOPEN’ for open error, `TokyoCabinet::HDB::ECLOSE’ for close error, `TokyoCabinet::HDB::ETRUNC’ for trunc error, `TokyoCabinet::HDB::ESYNC’ for sync error, `TokyoCabinet::HDB::ESTAT’ for stat error, `TokyoCabinet::HDB::ESEEK’ for seek error, `TokyoCabinet::HDB::EREAD’ for read error, `TokyoCabinet::HDB::EWRITE’ for write error, `TokyoCabinet::HDB::EMMAP’ for mmap error, `TokyoCabinet::HDB::ELOCK’ for lock error, `TokyoCabinet::HDB::EUNLINK’ for unlink error, `TokyoCabinet::HDB::ERENAME’ for rename error, `TokyoCabinet::HDB::EMKDIR’ for mkdir error, `TokyoCabinet::HDB::ERMDIR’ for rmdir error, `TokyoCabinet::HDB::EKEEP’ for existing record, `TokyoCabinet::HDB::ENOREC’ for no record found, and `TokyoCabinet::HDB::EMISC’ for miscellaneous error.%%
# File tokyocabinet-doc.rb, line 108 108: def ecode() 109: # (native code) 110: end
Get the message string corresponding to an error code.%% `ecode’ specifies the error code. If it is not defined or negative, the last happened error code is specified.%% The return value is the message string of the error code.%%
# File tokyocabinet-doc.rb, line 102 102: def errmsg(ecode) 103: # (native code) 104: end
Get the size of the database file.%% The return value is the size of the database file or 0 if the object does not connect to any database file.%%
# File tokyocabinet-doc.rb, line 298 298: def fsiz() 299: # (native code) 300: end
Get forward matching keys.%% `prefix’ specifies the prefix of the corresponding keys.%% `max’ specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.%% The return value is a list object of the keys of the corresponding records. This method does never fail. It returns an empty list even if no record corresponds.%% Note that this method may be very slow because every key in the database is scanned.%%
# File tokyocabinet-doc.rb, line 221 221: def fwmkeys(prefix, max) 222: # (native code) 223: end
Retrieve a record.%% `key’ specifies the key.%% If successful, the return value is the value of the corresponding record. `nil’ is returned if no record corresponds.%%
# File tokyocabinet-doc.rb, line 195 195: def get(key) 196: # (native code) 197: end
Initialize the iterator.%% If successful, the return value is true, else, it is false.%% The iterator is used in order to access the key of every record stored in a database.%%
# File tokyocabinet-doc.rb, line 207 207: def iterinit() 208: # (native code) 209: end
Get the next key of the iterator.%% If successful, the return value is the next key, else, it is `nil’. `nil’ is returned when no record is to be get out of the iterator.%% It is possible to access every record by iteration of calling this method. It is allowed to update or remove records whose keys are fetched while the iteration. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access.%%
# File tokyocabinet-doc.rb, line 213 213: def iternext() 214: # (native code) 215: end
Open a database file.%% `path’ specifies the path of the database file.%% `omode’ specifies the connection mode: `TokyoCabinet::HDB::OWRITER’ as a writer, `TokyoCabinet::HDB::OREADER’ as a reader. If the mode is `TokyoCabinet::HDB::OWRITER’, the following may be added by bitwise-or: `TokyoCabinet::HDB::OCREAT’, which means it creates a new database if not exist, `TokyoCabinet::HDB::OTRUNC’, which means it creates a new database regardless if one exists, `TokyoCabinet::HDB::OTSYNC’, which means every transaction synchronizes updated contents with the device. Both of `TokyoCabinet::HDB::OREADER’ and `TokyoCabinet::HDB::OWRITER’ can be added to by bitwise-or: `TokyoCabinet::HDB::ONOLCK’, which means it opens the database file without file locking, or `TokyoCabinet::HDB::OLCKNB’, which means locking is performed without blocking. If it is not defined, `TokyoCabinet::HDB::OREADER’ is specified.%% If successful, the return value is true, else, it is false.%%
# File tokyocabinet-doc.rb, line 145 145: def open(path, omode) 146: # (native code) 147: end
Optimize the database file.%% `bnum’ specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is two times of the number of records.%% `apow’ specifies the size of record alignment by power of 2. If it is not defined or negative, the current setting is not changed.%% `fpow’ specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the current setting is not changed.%% `opts’ specifies options by bitwise-or: `TokyoCabinet::HDB::TLARGE’ specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::HDB::TDEFLATE’ specifies that each record is compressed with Deflate encoding, `TokyoCabinet::HDB::TBZIP’ specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::HDB::TTCBS’ specifies that each record is compressed with TCBS encoding. If it is not defined or 0xff, the current setting is not changed.%% If successful, the return value is true, else, it is false.%% This method is useful to reduce the size of the database file with data fragmentation by successive updating.%%
# File tokyocabinet-doc.rb, line 253 253: def optimize(bnum, apow, fpow, opts) 254: # (native code) 255: end
Remove a record.%% `key’ specifies the key.%% If successful, the return value is true, else, it is false.%%
# File tokyocabinet-doc.rb, line 189 189: def out(key) 190: # (native code) 191: end
Store a record.%% `key’ specifies the key.%% `value’ specifies the value.%% If successful, the return value is true, else, it is false.%% If a record with the same key exists in the database, it is overwritten.%%
# File tokyocabinet-doc.rb, line 159 159: def put(key, value) 160: # (native code) 161: end
Store a record in asynchronous fashion.%% `key’ specifies the key.%% `value’ specifies the value.%% If successful, the return value is true, else, it is false.%% If a record with the same key exists in the database, it is overwritten. Records passed to this method are accumulated into the inner buffer and wrote into the file at a blast.%%
# File tokyocabinet-doc.rb, line 183 183: def putasync(key, value) 184: # (native code) 185: end
Concatenate a value at the end of the existing record.%% `key’ specifies the key.%% `value’ specifies the value.%% If successful, the return value is true, else, it is false.%% If there is no corresponding record, a new record is created.%%
# File tokyocabinet-doc.rb, line 175 175: def putcat(key, value) 176: # (native code) 177: end
Store a new record.%% `key’ specifies the key.%% `value’ specifies the value.%% If successful, the return value is true, else, it is false.%% If a record with the same key exists in the database, this method has no effect.%%
# File tokyocabinet-doc.rb, line 167 167: def putkeep(key, value) 168: # (native code) 169: end
Get the number of records.%% The return value is the number of records or 0 if the object does not connect to any database file.%%
# File tokyocabinet-doc.rb, line 293 293: def rnum() 294: # (native code) 295: end
Set the caching parameters.%% `rcnum’ specifies the maximum number of records to be cached. If it is not defined or not more than 0, the record cache is disabled. It is disabled by default.%% If successful, the return value is true, else, it is false.%% Note that the caching parameters of the database should be set before the database is opened.%%
# File tokyocabinet-doc.rb, line 124 124: def setcache(rcnum) 125: # (native code) 126: end
Set the unit step number of auto defragmentation.%% `dfunit’ specifie the unit step number. If it is not more than 0, the auto defragmentation is disabled. It is disabled by default.%% If successful, the return value is true, else, it is false.%% Note that the defragmentation parameters should be set before the database is opened.%%
# File tokyocabinet-doc.rb, line 138 138: def setdfunit(dfunit) 139: # (native code) 140: end
Set the size of the extra mapped memory.%% `xmsiz’ specifies the size of the extra mapped memory. If it is not defined or not more than 0, the extra mapped memory is disabled. The default size is 67108864.%% If successful, the return value is true, else, it is false.%% Note that the mapping parameters should be set before the database is opened.%%
# File tokyocabinet-doc.rb, line 131 131: def setxmsiz(xmsiz) 132: # (native code) 133: end
Synchronize updated contents with the file and the device.%% If successful, the return value is true, else, it is false.%% This method is useful when another process connects the same database file.%%
# File tokyocabinet-doc.rb, line 243 243: def sync() 244: # (native code) 245: end
Abort the transaction.%% If successful, the return value is true, else, it is false.%% Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.%%
# File tokyocabinet-doc.rb, line 283 283: def tranabort() 284: # (native code) 285: end
Begin the transaction.%% If successful, the return value is true, else, it is false.%% The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. All updated regions are kept track of by write ahead logging while the transaction. If the database is closed during transaction, the transaction is aborted implicitly.%%
# File tokyocabinet-doc.rb, line 271 271: def tranbegin() 272: # (native code) 273: end
Commit the transaction.%% If successful, the return value is true, else, it is false.%% Update in the transaction is fixed when it is committed successfully.%%
# File tokyocabinet-doc.rb, line 277 277: def trancommit() 278: # (native code) 279: end
Set the tuning parameters.%% `bnum’ specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is 131071. Suggested size of the bucket array is about from 0.5 to 4 times of the number of all records to be stored.%% `apow’ specifies the size of record alignment by power of 2. If it is not defined or negative, the default value is specified. The default value is 4 standing for 2^4=16.%% `fpow’ specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the default value is specified. The default value is 10 standing for 2^10=1024.%% `opts’ specifies options by bitwise-or: `TokyoCabinet::HDB::TLARGE’ specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::HDB::TDEFLATE’ specifies that each record is compressed with Deflate encoding, `TokyoCabinet::HDB::TDBZIP’ specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::HDB::TTCBS’ specifies that each record is compressed with TCBS encoding. If it is not defined, no option is specified.%% If successful, the return value is true, else, it is false. Note that the tuning parameters of the database should be set before the database is opened.%%
# File tokyocabinet-doc.rb, line 117 117: def tune(bnum, apow, fpow, opts) 118: # (native code) 119: end