upscaledb
2.2.1
|
Macros | |
#define | UPS_FLUSH_COMMITTED_TRANSACTIONS 1 |
#define | UPS_DONT_LOCK 0xf0000000 |
#define UPS_DONT_LOCK 0xf0000000 |
Definition at line 1082 of file upscaledb.h.
#define UPS_FLUSH_COMMITTED_TRANSACTIONS 1 |
Definition at line 1061 of file upscaledb.h.
UPS_EXPORT ups_status_t UPS_CALLCONV ups_env_close | ( | ups_env_t * | env, |
uint32_t | flags | ||
) |
Closes the Database Environment
This function closes the Database Environment. It also frees the memory resources allocated in the env handle, and tries to truncate the file (see below).
If the flag UPS_AUTO_CLEANUP is specified, upscaledb automatically calls ups_db_close with flag UPS_AUTO_CLEANUP on all open Databases (which closes all open Databases and their Cursors). This invalidates the ups_db_t and ups_cursor_t handles!
If the flag is not specified, the application must close all Database handles with ups_db_close to prevent memory leaks.
This function also aborts all Transactions which were not yet committed, and therefore renders all Txn handles invalid. If the flag UPS_TXN_AUTO_COMMIT is specified, all Transactions will be committed.
This function also tries to truncate the file and "cut off" unused space at the end of the file to reduce the file size. This feature is disabled on Win32 if memory mapped I/O is used (see UPS_DISABLE_MMAP).
env | A valid Environment handle |
flags | Optional flags for closing the handle. Possible flags are:
|
Referenced by upscaledb::env::close(), and main().
UPS_EXPORT ups_status_t UPS_CALLCONV ups_env_create | ( | ups_env_t ** | env, |
const char * | filename, | ||
uint32_t | flags, | ||
uint32_t | mode, | ||
const ups_parameter_t * | param | ||
) |
Creates a Database Environment
A Database Environment is a collection of Databases, which are all stored in one physical file (or in-memory). The maximum number of Databases depends on the page size; the default is above 600.
Each Database in an Environment is identified by a positive 16bit value (except 0 and values at or above 0xf000). Databases in an Environment can be created with ups_env_create_db or opened with ups_env_open_db.
Specify a URL instead of a filename (i.e. "ups://localhost:8080/customers.db") to access a remote upscaledb Server.
To enable ACID Transactions, supply the flag UPS_ENABLE_TRANSACTIONS. By default, upscaledb will use a Journal for recovering the Environment and its data in case of a crash, and also to re-apply committed Transactions which were not yet flushed to disk. This Journalling can be disabled with the flag UPS_DISABLE_RECOVERY. (It is disabled if the Environment is in-memory.)
For performance reasons the Journal does not use fsync(2) (or FlushFileBuffers on Win32) to flush modified buffers to disk. Use the flag UPS_ENABLE_FSYNC to force the use of fsync.
If Transactions are enabled, a journal file is written in order to provide recovery if the system crashes. These journal files can be compressed by supplying the parameter UPS_PARAM_ENABLE_JOURNAL_COMPRESSION. Values are one of UPS_COMPRESSOR_ZLIB, UPS_COMPRESSOR_SNAPPY etc. See the upscaledb documentation for more details. This parameter is not persisted.
Upscaledb can transparently encrypt the generated file using 128bit AES in CBC mode. The transactional journal is not encrypted. Encryption can be enabled by specifying UPS_PARAM_ENCRYPTION_KEY (see below). The identical key has to be provided in ups_env_open as well. Ignored for remote Environments.
CRC32 checksums are stored when a page is flushed, and verified when it is fetched from disk if the flag UPS_ENABLE_CRC32 is set. API functions will return UPS_INTEGRITY_VIOLATED in case of failed verifications. Not allowed in In-Memory Environments. This flag is not persisted.
env | A pointer to an Environment handle |
filename | The filename of the Environment file. If the file already exists, it is overwritten. Can be NULL for an In-Memory Environment. Can be a URL ("ups://<hostname>:<port>/<environment>") for remote access. |
flags | Optional flags for opening the Environment, combined with bitwise OR. Possible flags are:
|
mode | File access rights for the new file. This is the mode parameter for creat(2). Ignored on Microsoft Windows. Default is 0644. |
param | An array of ups_parameter_t structures. The following parameters are available:
|
Referenced by upscaledb::env::create(), and main().
UPS_EXPORT ups_status_t UPS_CALLCONV ups_env_create_db | ( | ups_env_t * | env, |
ups_db_t ** | db, | ||
uint16_t | name, | ||
uint32_t | flags, | ||
const ups_parameter_t * | params | ||
) |
Creates a new Database in a Database Environment
An Environment can contain a (limited) amount of Databases; the exact limit depends on the page size and is above 600.
Each Database in an Environment is identified by a positive 16bit value. 0 and values at or above 0xf000 are reserved.
This function initializes the ups_db_t handle (the second parameter). When the handle is no longer in use, it should be closed with ups_db_close. Alternatively, the Database handle is closed automatically if ups_env_close is called with the flag UPS_AUTO_CLEANUP.
A Database can (and should) be configured and optimized for the data that is inserted. The data is described through flags and parameters. upscaledb differentiates between several data characteristics, and offers predefined "types" to describe the keys. In general, the default key type (UPS_TYPE_BINARY) is slower than the other types, and fixed-length binary keys (UPS_TYPE_BINARY in combination with UPS_PARAM_KEY_SIZE) is faster than variable-length binary keys. It is therefore recommended to always set the key size and record size, although it is not required.
Internally, upscaledb uses two different layouts ("default" and "pax) depending on the settings specified by the user. The "default" layout is enabled for variable-length keys or if duplicate keys are enabled. For fixed-length keys (without duplicates) the "pax" layout is chosen. The "pax" layout is more compact and usually faster.
A word of warning regarding the use of fixed length binary keys (UPS_TYPE_CUSTOM or UPS_TYPE_BINARY in combination with UPS_PARAM_KEY_SIZE): if your key size is too large, only few keys will fit in a Btree node. The Btree fanout will be very high, which will decrease performance. In such cases it might be better to NOT specify the key size; then upscaledb will store keys as blobs if they are too large.
See the Wiki documentation for Evaluating and Benchmarking on how to test different configurations and optimize for performance.
The key type is set with UPS_PARAM_KEY_TYPE and the record type is set with UPS_PARAM_RECORD_TYPE. The types can have one of the following values:
If the type is ommitted then UPS_TYPE_BINARY is the default.
If binary/custom keys are so big that they cannot be stored in the Btree, then the full key will be stored in an overflow area, which has performance implications when accessing such keys.
In addition to the flags above, you can specify UPS_ENABLE_DUPLICATE_KEYS to insert duplicate keys, i.e. to model 1:n or n:m relationships.
If the size of the records is always constant, then UPS_PARAM_RECORD_SIZE should be used to specify this size. This allows upscaledb to optimize the record storage, and small records will automatically be stored in the Btree's leaf nodes instead of a separately allocated blob, allowing faster access. Setting a record size to 0 is valid and suited for boolean values ("key exists" vs "key doesn't exist"). The default record size is UPS_RECORD_SIZE_UNLIMITED.
Records can be compressed transparently in order to reduce I/O and disk space. Compression is enabled with UPS_PARAM_RECORD_COMPRESSION. Values are one of UPS_COMPRESSOR_ZLIB, UPS_COMPRESSOR_SNAPPY etc. See the upscaledb documentation for more details.
Keys can also be compressed by setting the parameter UPS_PARAM_KEY_COMPRESSION. See the upscaledb documentation for more details.
In addition, several integer compression algorithms are available for Databases created with the type UPS_TYPE_UINT32. Note that integer compression only works with the default page size of 16kb.
env | A valid Environment handle. |
db | A valid Database handle, which will point to the created Database. To close the handle, use ups_db_close. |
name | The name of the Database. If a Database with this name already exists, the function will fail with UPS_DATABASE_ALREADY_EXISTS. Database names from 0xf000 to 0xffff and 0 are reserved. |
flags | Optional flags for creating the Database, combined with bitwise OR. Possible flags are:
|
params | An array of ups_parameter_t structures. The following parameters are available:
|
Referenced by upscaledb::env::create_db(), and main().
UPS_EXPORT ups_status_t UPS_CALLCONV ups_env_erase_db | ( | ups_env_t * | env, |
uint16_t | name, | ||
uint32_t | flags | ||
) |
Deletes a Database from an Environment
env | A valid Environment handle |
name | The name of the Database to delete. If a Database with this name does not exist, the function will fail with UPS_DATABASE_NOT_FOUND. If the Database was already opened, the function will fail with UPS_DATABASE_ALREADY_OPEN. |
flags | Optional flags for deleting the Database; unused, set to 0. |
Referenced by upscaledb::env::erase_db().
UPS_EXPORT ups_status_t UPS_CALLCONV ups_env_flush | ( | ups_env_t * | env, |
uint32_t | flags | ||
) |
Flushes the Environment
This function flushes the Environment caches and writes the whole file to disk. All Databases of this Environment are flushed as well.
Since In-Memory Databases do not have a file on disk, the function will have no effect and will return UPS_SUCCESS.
env | A valid Environment handle |
flags | Optional flags for flushing; unused, set to 0 |
Referenced by upscaledb::env::flush().
UPS_EXPORT ups_status_t UPS_CALLCONV ups_env_get_database_names | ( | ups_env_t * | env, |
uint16_t * | names, | ||
uint32_t * | length | ||
) |
Returns the names of all Databases in an Environment
This function returns the names of all Databases and the number of Databases in an Environment.
The memory for names must be allocated by the user. length must be the length of names when calling the function, and will be the number of Databases when the function returns. The function returns UPS_LIMITS_REACHED if names is not big enough; in this case, the caller should resize the array and call the function again.
env | A valid Environment handle |
names | Pointer to an array for the Database names |
length | Pointer to the length of the array; will be used to store the number of Databases when the function returns. |
Referenced by upscaledb::env::get_database_names().
UPS_EXPORT ups_status_t UPS_CALLCONV ups_env_get_parameters | ( | ups_env_t * | env, |
ups_parameter_t * | param | ||
) |
Retrieve the current value for a given Environment setting
Only those values requested by the parameter array will be stored.
The following parameters are supported:
env | A valid Environment handle |
param | An array of ups_parameter_t structures |
Referenced by upscaledb::env::get_parameters().
UPS_EXPORT ups_status_t UPS_CALLCONV ups_env_open | ( | ups_env_t ** | env, |
const char * | filename, | ||
uint32_t | flags, | ||
const ups_parameter_t * | param | ||
) |
Opens an existing Database Environment
This function opens an existing Database Environment.
A Database Environment is a collection of Databases, which are all stored in one physical file (or in-memory).
Each Database in an Environment is identified by a positive 16bit value (except 0 and values at or above 0xf000). Databases in an Environment can be created with ups_env_create_db or opened with ups_env_open_db.
Specify a URL instead of a filename (i.e. "ups://localhost:8080/customers.db") to access a remote upscaledb Server.
Also see the documentation ups_env_create about Transactions, Recovery, AES encryption and the use of fsync.
If Transactions are enabled, a journal file is written in order to provide recovery if the system crashes. These journal files can be compressed by supplying the parameter UPS_PARAM_JOURNAL_COMPRESSION. Values are one of UPS_COMPRESSOR_ZLIB, UPS_COMPRESSOR_SNAPPY etc. See the upscaledb documentation for more details. This parameter is not persisted.
CRC32 checksums are stored when a page is flushed, and verified when it is fetched from disk if the flag UPS_ENABLE_CRC32 is set. API functions will return UPS_INTEGRITY_VIOLATED in case of failed verifications. This flag is not persisted.
env | A valid Environment handle |
filename | The filename of the Environment file, or URL of a upscaledb Server |
flags | Optional flags for opening the Environment, combined with bitwise OR. Possible flags are:
|
param | An array of ups_parameter_t structures. The following parameters are available:
|
Referenced by main(), and upscaledb::env::open().
UPS_EXPORT ups_status_t UPS_CALLCONV ups_env_open_db | ( | ups_env_t * | env, |
ups_db_t ** | db, | ||
uint16_t | name, | ||
uint32_t | flags, | ||
const ups_parameter_t * | params | ||
) |
Opens a Database in a Database Environment
Each Database in an Environment is identified by a positive 16bit value (except 0 and values at or above 0xf000).
This function initializes the ups_db_t handle (the second parameter). When the handle is no longer in use, it should be closed with ups_db_close. Alternatively, the Database handle is closed automatically if ups_env_close is called with the flag UPS_AUTO_CLEANUP.
If this database stores keys with a custom compare function then you have to install the compare function (ups_register_compare) prior to opening the database.
Records can be compressed transparently in order to reduce I/O and disk space. Compression is enabled with UPS_PARAM_ENABLE_RECORD_COMPRESSION. Values are one of UPS_COMPRESSOR_ZLIB, UPS_COMPRESSOR_SNAPPY etc. See the upscaledb documentation for more details. This parameter is not persisted.
env | A valid Environment handle |
db | A valid Database handle, which will point to the opened Database. To close the handle, use |
name | The name of the Database. If a Database with this name does not exist, the function will fail with UPS_DATABASE_NOT_FOUND. |
flags | Optional flags for opening the Database, combined with bitwise OR. Possible flags are:
|
params | Reserved; set to NULL |
Referenced by main(), and upscaledb::env::open_db().
UPS_EXPORT ups_status_t UPS_CALLCONV ups_env_rename_db | ( | ups_env_t * | env, |
uint16_t | oldname, | ||
uint16_t | newname, | ||
uint32_t | flags | ||
) |
Renames a Database in an Environment.
env | A valid Environment handle. |
oldname | The old name of the existing Database. If a Database with this name does not exist, the function will fail with UPS_DATABASE_NOT_FOUND. |
newname | The new name of this Database. If a Database with this name already exists, the function will fail with UPS_DATABASE_ALREADY_EXISTS. |
flags | Optional flags for renaming the Database, combined with bitwise OR; unused, set to 0. |
Referenced by upscaledb::env::rename_db().