Class | TokyoCabinet::BDB |
In: |
tokyocabinet.c
tokyocabinet-doc.rb |
Parent: | Object |
B+ tree database is a file containing a B+ tree and is handled with the B+ tree database API. Before operations to store or retrieve records, it is necessary to open a database file and connect the B+ tree 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) | ||
CMPLEXICAL | = | rb_str_new2("CMPLEXICAL") | ||
CMPDECIMAL | = | rb_str_new2("CMPDECIMAL") | ||
CMPINT32 | = | rb_str_new2("CMPINT32") | ||
CMPINT64 | = | rb_str_new2("CMPINT64") | ||
TLARGE | = | INT2NUM(BDBTLARGE) | ||
TDEFLATE | = | INT2NUM(BDBTDEFLATE) | ||
TBZIP | = | INT2NUM(BDBTBZIP) | ||
TTCBS | = | INT2NUM(BDBTTCBS) | ||
OREADER | = | INT2NUM(BDBOREADER) | ||
OWRITER | = | INT2NUM(BDBOWRITER) | ||
OCREAT | = | INT2NUM(BDBOCREAT) | ||
OTRUNC | = | INT2NUM(BDBOTRUNC) | ||
ONOLCK | = | INT2NUM(BDBONOLCK) | ||
OLCKNB | = | INT2NUM(BDBOLCKNB) | ||
OTSYNC | = | INT2NUM(BDBOTSYNC) | ||
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 | |
CMPLEXICAL | = | "CMPLEXICAL" | comparison function: by lexical order | |
CMPDECIMAL | = | "CMPDECIMAL" | comparison function: as decimal strings of real numbers | |
CMPINT32 | = | "CMPINT32" | comparison function: as 32-bit integers in the native byte order | |
CMPINT64 | = | "CMPINT64" | comparison function: as 64-bit integers in the native byte order | |
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 563 563: def adddouble(key, num) 564: # (native code) 565: 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 555 555: def addint(key, num) 556: # (native code) 557: 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 450 450: def close() 451: # (native code) 452: 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 593 593: def copy(path) 594: # (native code) 595: end
Get the last happened error code.%% The return value is the last happened error code.%% The following error codes are defined: `TokyoCabinet::BDB::ESUCCESS’ for success, `TokyoCabinet::BDB::ETHREAD’ for threading error, `TokyoCabinet::BDB::EINVALID’ for invalid operation, `TokyoCabinet::BDB::ENOFILE’ for file not found, `TokyoCabinet::BDB::ENOPERM’ for no permission, `TokyoCabinet::BDB::EMETA’ for invalid meta data, `TokyoCabinet::BDB::ERHEAD’ for invalid record header, `TokyoCabinet::BDB::EOPEN’ for open error, `TokyoCabinet::BDB::ECLOSE’ for close error, `TokyoCabinet::BDB::ETRUNC’ for trunc error, `TokyoCabinet::BDB::ESYNC’ for sync error, `TokyoCabinet::BDB::ESTAT’ for stat error, `TokyoCabinet::BDB::ESEEK’ for seek error, `TokyoCabinet::BDB::EREAD’ for read error, `TokyoCabinet::BDB::EWRITE’ for write error, `TokyoCabinet::BDB::EMMAP’ for mmap error, `TokyoCabinet::BDB::ELOCK’ for lock error, `TokyoCabinet::BDB::EUNLINK’ for unlink error, `TokyoCabinet::BDB::ERENAME’ for rename error, `TokyoCabinet::BDB::EMKDIR’ for mkdir error, `TokyoCabinet::BDB::ERMDIR’ for rmdir error, `TokyoCabinet::BDB::EKEEP’ for existing record, `TokyoCabinet::BDB::ENOREC’ for no record found, and `TokyoCabinet::BDB::EMISC’ for miscellaneous error.%%
# File tokyocabinet-doc.rb, line 397 397: def ecode() 398: # (native code) 399: 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 391 391: def errmsg(ecode) 392: # (native code) 393: 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 626 626: def fsiz() 627: # (native code) 628: 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.%%
# File tokyocabinet-doc.rb, line 547 547: def fwmkeys(prefix, max) 548: # (native code) 549: 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.%% If the key of duplicated records is specified, the value of the first one is selected.%%
# File tokyocabinet-doc.rb, line 511 511: def get(key) 512: # (native code) 513: end
Retrieve records.%% `key’ specifies the key.%% If successful, the return value is a list object of the values of the corresponding records. `nil’ is returned if no record corresponds.%%
# File tokyocabinet-doc.rb, line 517 517: def getlist(key) 518: # (native code) 519: end
Open a database file.%% `path’ specifies the path of the database file.%% `omode’ specifies the connection mode: `TokyoCabinet::BDB::OWRITER’ as a writer, `TokyoCabinet::BDB::OREADER’ as a reader. If the mode is `TokyoCabinet::BDB::OWRITER’, the following may be added by bitwise-or: `TokyoCabinet::BDB::OCREAT’, which means it creates a new database if not exist, `TokyoCabinet::BDB::OTRUNC’, which means it creates a new database regardless if one exists, `TokyoCabinet::BDB::OTSYNC’, which means every transaction synchronizes updated contents with the device. Both of `TokyoCabinet::BDB::OREADER’ and `TokyoCabinet::BDB::OWRITER’ can be added to by bitwise-or: `TokyoCabinet::BDB::ONOLCK’, which means it opens the database file without file locking, or `TokyoCabinet::BDB::OLCKNB’, which means locking is performed without blocking. If it is not defined, `TokyoCabinet::BDB::OREADER’ is specified.%% If successful, the return value is true, else, it is false.%%
# File tokyocabinet-doc.rb, line 444 444: def open(path, omode) 445: # (native code) 446: end
Optimize the database file.%% `lmemb’ specifies the number of members in each leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 128.%% `nmemb’ specifies the number of members in each non-leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 256.%% `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 pages.%% `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::BDB::TLARGE’ specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::BDB::TDEFLATE’ specifies that each record is compressed with Deflate encoding, `TokyoCabinet::BDB::TBZIP’ specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::BDB::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 581 581: def optimize(lmemb, nmemb, bnum, apow, fpow, opts) 582: # (native code) 583: end
Remove a record.%% `key’ specifies the key.%% If successful, the return value is true, else, it is false.%% If the key of duplicated records is specified, the value of the first one is selected.%%
# File tokyocabinet-doc.rb, line 497 497: def out(key) 498: # (native code) 499: end
Remove records.%% `key’ specifies the key.%% If successful, the return value is true, else, it is false.%% If the key of duplicated records is specified, all of them are removed.%%
# File tokyocabinet-doc.rb, line 504 504: def outlist(key) 505: # (native code) 506: 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 458 458: def put(key, value) 459: # (native code) 460: 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 474 474: def putcat(key, value) 475: # (native code) 476: end
Store a record with allowing duplication of keys.%% `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, the new record is placed after the existing one.%%
# File tokyocabinet-doc.rb, line 482 482: def putdup(key, value) 483: # (native code) 484: 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 466 466: def putkeep(key, value) 467: # (native code) 468: end
Store records with allowing duplication of keys.%% `key’ specifies the key.%% `values’ specifies an array of the values.%% If successful, the return value is true, else, it is false.%% If a record with the same key exists in the database, the new records are placed after the existing one.%%
# File tokyocabinet-doc.rb, line 490 490: def putlist(key, values) 491: # (native code) 492: end
Get keys of ranged records.%% `bkey’ specifies the key of the beginning border. If it is not defined, the first record is specified.%% `binc’ specifies whether the beginning border is inclusive or not. If it is not defined, false is specified.%% `ekey’ specifies the key of the ending border. If it is not defined, the last record is specified.%% `einc’ specifies whether the ending border is inclusive or not. If it is not defined, false is specified.%% `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.%%
# File tokyocabinet-doc.rb, line 540 540: def range(bkey, binc, ekey, einc, max) 541: # (native code) 542: 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 621 621: def rnum() 622: # (native code) 623: end
Set the caching parameters.%% `lcnum’ specifies the maximum number of leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 1024.%% `ncnum’ specifies the maximum number of non-leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 512.%% 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 423 423: def setcache(lcnum, ncnum) 424: # (native code) 425: end
Set the custom comparison function.%% `cmp’ specifies the custom comparison function. It should be an instance of the class `Proc’.%% If successful, the return value is true, else, it is false.%% The default comparison function compares keys of two records by lexical order. The constants `TokyoCabinet::BDB::CMPLEXICAL’ (dafault), `TokyoCabinet::BDB::CMPDECIMAL’, `TokyoCabinet::BDB::CMPINT32’, and `TokyoCabinet::BDB::CMPINT64’ are built-in. Note that the comparison function should be set before the database is opened. Moreover, user-defined comparison functions should be set every time the database is being opened.%%
# File tokyocabinet-doc.rb, line 404 404: def setcmpfunc(cmp) 405: # (native code) 406: 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 437 437: def setdfunit(dfunit) 438: # (native code) 439: 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. It is disabled by default.%% 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 430 430: def setxmsiz(xmsiz) 431: # (native code) 432: 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 569 569: def sync() 570: # (native code) 571: 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 611 611: def tranabort() 612: # (native code) 613: 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. Because all pages are cached on memory while the transaction, the amount of referred records is limited by the memory capacity. If the database is closed during transaction, the transaction is aborted implicitly.%%
# File tokyocabinet-doc.rb, line 599 599: def tranbegin() 600: # (native code) 601: 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 605 605: def trancommit() 606: # (native code) 607: end
Set the tuning parameters.%% `lmemb’ specifies the number of members in each leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 128.%% `nmemb’ specifies the number of members in each non-leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 256.%% `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 32749. Suggested size of the bucket array is about from 1 to 4 times of the number of all pages 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^8=256.%% `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::BDB::TLARGE’ specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::BDB::TDEFLATE’ specifies that each record is compressed with Deflate encoding, `TokyoCabinet::BDB::TBZIP’ specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::BDB::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 415 415: def tune(lmemb, nmemb, bnum, apow, fpow, opts) 416: # (native code) 417: end
Remove all records.%% If successful, the return value is true, else, it is false.%%
# File tokyocabinet-doc.rb, line 586 586: def vanish() 587: # (native code) 588: end
Get the number of records corresponding a key.%% `key’ specifies the key.%% If successful, the return value is the number of the corresponding records, else, it is 0.%%
# File tokyocabinet-doc.rb, line 523 523: def vnum(key) 524: # (native code) 525: end
Get the size of the value of a record.%% `key’ specifies the key.%% If successful, the return value is the size of the value of the corresponding record, else, it is -1.%% If the key of duplicated records is specified, the value of the first one is selected.%%
# File tokyocabinet-doc.rb, line 530 530: def vsiz(key) 531: # (native code) 532: end