mdbx: cleanup/reformat after the merge.

Change-Id: I3e0fe8f1292a6387e8d3ff8b904170f05d8e1770
This commit is contained in:
Leo Yuriev 2017-07-04 09:24:10 +03:00
parent 594834bc9c
commit b34e92d308
2 changed files with 319 additions and 338 deletions

271
mdbx.h
View File

@ -639,8 +639,8 @@ LIBMDBX_API int mdbx_env_open_ex(MDBX_env *env, const char *path,
*
* [in] env An environment handle returned by mdbx_env_create(). It must
* have already been opened successfully.
* [in] path The directory in which the copy will reside. This directory must
* already exist and be writable but must otherwise be empty.
* [in] path The directory in which the copy will reside. This directory
* must already exist and be writable but must otherwise be empty.
* [in] flags Special options for this operation. This parameter must be set
* to 0 or by bitwise OR'ing together one or more of the values
* described here:
@ -723,10 +723,10 @@ LIBMDBX_API int mdbx_env_sync(MDBX_env *env, int force);
* [in] env An environment handle returned by mdbx_env_create()
* [in] dont_sync A dont'sync flag, if non-zero the last checkpoint (meta-page
* update) will be kept "as is" and may be still "weak" in the
* NOSYNC/MAPASYNC modes. Such "weak" checkpoint will be ignored
* on opening next time, and transactions since the last non-weak
* checkpoint (meta-page update) will rolledback for consistency
* guarantee. */
* NOSYNC/MAPASYNC modes. Such "weak" checkpoint will be
* ignored on opening next time, and transactions since the
* last non-weak checkpoint (meta-page update) will rolledback
* for consistency guarantee. */
LIBMDBX_API void mdbx_env_close(MDBX_env *env);
/* Set environment flags.
@ -949,8 +949,7 @@ LIBMDBX_API int mdbx_txn_begin(MDBX_env *env, MDBX_txn *parent, unsigned flags,
/* Returns the transaction's MDBX_env
*
* [in] txn A transaction handle returned by mdbx_txn_begin()
*/
* [in] txn A transaction handle returned by mdbx_txn_begin() */
LIBMDBX_API MDBX_env *mdbx_txn_env(MDBX_txn *txn);
/* Return the transaction's ID.
@ -1181,7 +1180,7 @@ LIBMDBX_API int mdbx_drop(MDBX_txn *txn, MDBX_dbi dbi, int del);
* [in] txn A transaction handle returned by mdbx_txn_begin()
* [in] dbi A database handle returned by mdbx_dbi_open()
* [in] key The key to search for in the database
* [out] data The data corresponding to the key
* [in,out] data The data corresponding to the key
*
* Returns A non-zero error value on failure and 0 on success, some
* possible errors are:
@ -1243,6 +1242,7 @@ LIBMDBX_API int mdbx_get(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
*
* Returns A non-zero error value on failure and 0 on success, some
* possible errors are:
* - MDBX_KEYEXIST
* - MDBX_MAP_FULL - the database is full, see mdbx_env_set_mapsize().
* - MDBX_TXN_FULL - the transaction has too many dirty pages.
* - MDBX_EACCES - an attempt was made to write in a read-only transaction.
@ -1358,7 +1358,7 @@ LIBMDBX_API int mdbx_cursor_get(MDBX_cursor *cursor, MDBX_val *key,
* [in] key The key operated on.
* [in] data The data operated on.
* [in] flags Options for this operation. This parameter
* must be set to 0 or one of the values described here.
* must be set to 0 or one of the values described here:
*
* - MDBX_CURRENT
* Replace the item at the current cursor position. The key parameter
@ -1635,160 +1635,153 @@ LIBMDBX_API int mdbx_dbi_sequence(MDBX_txn *txn, MDBX_dbi dbi, uint64_t *result,
/* attribute support functions for Nexenta */
typedef uint64_t mdbx_attr_t;
/** @brief Store by cursor with attribute.
/* Store by cursor with attribute.
*
* This function stores key/data pairs into the database.
* The cursor is positioned at the new item, or on failure usually near it.
* @note Internally based on #MDBX_RESERVE feature, therefore doesn't support #MDBX_DUPSORT.
* @note Earlier documentation incorrectly said errors would leave the
* state of the cursor unchanged.
* @param[in] cursor A cursor handle returned by #mdb_cursor_open()
* @param[in] key The key operated on.
* @param[in] data The data operated on.
* @param[in] attr The attribute.
* @param[in] flags Options for this operation. This parameter
* must be set to 0 or one of the values described here.
* <ul>
* <li>#MDBX_CURRENT - replace the item at the current cursor position.
* The \b key parameter must still be provided, and must match it.
* This is intended to be used when the
* new data is the same size as the old. Otherwise it will simply
* perform a delete of the old record followed by an insert.
* <li>#MDBX_NOOVERWRITE - enter the new key/data pair only if the key
* does not already appear in the database. The function will return
* #MDBX_KEYEXIST if the key already appears in the database.
* <li>#MDBX_RESERVE - reserve space for data of the given size, but
* don't copy the given data. Instead, return a pointer to the
* reserved space, which the caller can fill in later. This saves
* an extra memcpy if the data is being generated later.
* <li>#MDBX_APPEND - append the given key/data pair to the end of the
* database. No key comparisons are performed. This option allows
* fast bulk loading when keys are already known to be in the
* correct order. Loading unsorted keys with this flag will cause
* data corruption.
* </ul>
* @return A non-zero error value on failure and 0 on success. Some possible
* errors are:
* <ul>
* <li>#MDBX_MAP_FULL - the database is full, see #mdb_env_set_mapsize().
* <li>#MDBX_TXN_FULL - the transaction has too many dirty pages.
* <li>EACCES - an attempt was made to write in a read-only transaction.
* <li>EINVAL - an invalid parameter was specified.
* </ul>
*/
* This function stores key/data pairs into the database. The cursor is
* positioned at the new item, or on failure usually near it.
*
* NOTE: Internally based on MDBX_RESERVE feature,
* therefore doesn't support MDBX_DUPSORT.
*
* [in] cursor A cursor handle returned by mdbx_cursor_open()
* [in] key The key operated on.
* [in] data The data operated on.
* [in] attr The attribute.
* [in] flags Options for this operation. This parameter must be set to 0
* or one of the values described here:
*
* - MDBX_CURRENT
* Replace the item at the current cursor position. The key parameter
* must still be provided, and must match it, otherwise the function
* return MDBX_EKEYMISMATCH.
*
* - MDBX_APPEND
* Append the given key/data pair to the end of the database. No key
* comparisons are performed. This option allows fast bulk loading when
* keys are already known to be in the correct order. Loading unsorted
* keys with this flag will cause a MDBX_KEYEXIST error.
*
* Returns A non-zero error value on failure and 0 on success, some
* possible errors are:
* - MDBX_EKEYMISMATCH
* - MDBX_MAP_FULL - the database is full, see mdbx_env_set_mapsize().
* - MDBX_TXN_FULL - the transaction has too many dirty pages.
* - MDBX_EACCES - an attempt was made to write in a read-only transaction.
* - MDBX_EINVAL - an invalid parameter was specified. */
int mdbx_cursor_put_attr(MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data,
mdbx_attr_t attr, unsigned flags);
/** @brief Store items and attributes into a database.
/* Store items and attributes into a database.
*
* This function stores key/data pairs in the database. The default behavior
* is to enter the new key/data pair, replacing any previously existing key
* if duplicates are disallowed.
* @note Internally based on #MDBX_RESERVE feature, therefore doesn't support #MDBX_DUPSORT.
* @param[in] txn A transaction handle returned by #mdb_txn_begin()
* @param[in] dbi A database handle returned by #mdb_dbi_open()
* @param[in] key The key to store in the database
* @param[in] attr The attribute to store in the database
* @param[in,out] data The data to store
* @param[in] flags Special options for this operation. This parameter
* must be set to 0 or by bitwise OR'ing together one or more of the
* values described here.
* <ul>
* <li>#MDBX_NOOVERWRITE - enter the new key/data pair only if the key
* does not already appear in the database. The function will return
* #MDBX_KEYEXIST if the key already appears in the database. The \b data
* parameter will be set to point to the existing item.
* <li>#MDBX_RESERVE - reserve space for data of the given size, but
* don't copy the given data. Instead, return a pointer to the
* reserved space, which the caller can fill in later - before
* the next update operation or the transaction ends. This saves
* an extra memcpy if the data is being generated later.
* LMDB does nothing else with this memory, the caller is expected
* to modify all of the space requested.
* <li>#MDBX_APPEND - append the given key/data pair to the end of the
* database. This option allows fast bulk loading when keys are
* already known to be in the correct order. Loading unsorted keys
* with this flag will cause a #MDBX_KEYEXIST error.
* </ul>
* @return A non-zero error value on failure and 0 on success. Some possible
* errors are:
* <ul>
* <li>#MDBX_MAP_FULL - the database is full, see #mdb_env_set_mapsize().
* <li>#MDBX_TXN_FULL - the transaction has too many dirty pages.
* <li>EACCES - an attempt was made to write in a read-only transaction.
* <li>EINVAL - an invalid parameter was specified.
* </ul>
*/
*
* NOTE: Internally based on MDBX_RESERVE feature,
* therefore doesn't support MDBX_DUPSORT.
*
* [in] txn A transaction handle returned by mdbx_txn_begin().
* [in] dbi A database handle returned by mdbx_dbi_open().
* [in] key The key to store in the database.
* [in] attr The attribute to store in the database.
* [in,out] data The data to store.
* [in] flags Special options for this operation. This parameter must be
* set to 0 or by bitwise OR'ing together one or more of the
* values described here:
*
* - MDBX_NOOVERWRITE
* Enter the new key/data pair only if the key does not already appear
* in the database. The function will return MDBX_KEYEXIST if the key
* already appears in the database. The data parameter will be set to
* point to the existing item.
*
* - MDBX_CURRENT
* Update an single existing entry, but not add new ones. The function
* will return MDBX_NOTFOUND if the given key not exist in the database.
* Or the MDBX_EMULTIVAL in case duplicates for the given key.
*
* - MDBX_APPEND
* Append the given key/data pair to the end of the database. This option
* allows fast bulk loading when keys are already known to be in the
* correct order. Loading unsorted keys with this flag will cause
* a MDBX_EKEYMISMATCH error.
*
* Returns A non-zero error value on failure and 0 on success, some
* possible errors are:
* - MDBX_KEYEXIST
* - MDBX_MAP_FULL - the database is full, see mdbx_env_set_mapsize().
* - MDBX_TXN_FULL - the transaction has too many dirty pages.
* - MDBX_EACCES - an attempt was made to write in a read-only transaction.
* - MDBX_EINVAL - an invalid parameter was specified. */
int mdbx_put_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
mdbx_attr_t attr, unsigned flags);
/** @brief Set items attribute from a database.
/* Set items attribute from a database.
*
* This function stores key/data pairs attribute to the database.
* @note Internally based on #MDBX_RESERVE feature, therefore doesn't support #MDBX_DUPSORT.
*
* @param[in] txn A transaction handle returned by #mdb_txn_begin()
* @param[in] dbi A database handle returned by #mdb_dbi_open()
* @param[in] key The key to search for in the database
* @param[in] data The data to be stored or NULL to save previous value.
* @param[in] attr The attribute to be stored
* @return A non-zero error value on failure and 0 on success. Some possible
* errors are:
* <ul>
* <li>#MDBX_NOTFOUND - the key-value pair was not in the database.
* <li>EINVAL - an invalid parameter was specified.
* </ul>
*/
* NOTE: Internally based on MDBX_RESERVE feature,
* therefore doesn't support MDBX_DUPSORT.
*
* [in] txn A transaction handle returned by mdbx_txn_begin().
* [in] dbi A database handle returned by mdbx_dbi_open().
* [in] key The key to search for in the database.
* [in] data The data to be stored or NULL to save previous value.
* [in] attr The attribute to be stored.
*
* Returns A non-zero error value on failure and 0 on success, some
* possible errors are:
* - MDBX_NOTFOUND - the key-value pair was not in the database.
* - MDBX_EINVAL - an invalid parameter was specified. */
int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
mdbx_attr_t attr);
/** @brief Get items attribute from a database cursor.
/* Get items attribute from a database cursor.
*
* This function retrieves key/data pairs attribute from the database.
* The attribute of the specified key-value pair is returned in
* uint64_t to which \b attrptr refers.
* If the database supports duplicate keys (#MDBX_DUPSORT) then both
* key and data parameters are required, otherwise data could be NULL.
* This function retrieves key/data pairs from the database. The address and
* length of the key are returned in the object to which key refers (except
* for the case of the MDBX_SET option, in which the key object is unchanged),
* and the address and length of the data are returned in the object to which
* data refers. See mdbx_get() for restrictions on using the output values.
*
* @note Values returned from the database are valid only until a
* subsequent update operation, or the end of the transaction.
* @param[in] mc A database cursor pointing at the node
* @param[in] key The key to search for in the database
* @param[in,out] data The data for #MDBX_DUPSORT databases
* @param[out] attrptr The pointer to the result
* @param[in] op A cursor operation #MDBX_cursor_op
* @return A non-zero error value on failure and 0 on success. Some possible
* errors are:
* <ul>
* <li>#MDBX_NOTFOUND - the key-value pair was not in the database.
* <li>EINVAL - an invalid parameter was specified.
* </ul>
*/
* [in] cursor A cursor handle returned by mdbx_cursor_open()
* [in,out] key The key for a retrieved item
* [in,out] data The data of a retrieved item
* [in] op A cursor operation MDBX_cursor_op
*
* Returns A non-zero error value on failure and 0 on success, some
* possible errors are:
* - MDBX_NOTFOUND - no matching key found.
* - MDBX_EINVAL - an invalid parameter was specified. */
int mdbx_cursor_get_attr(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
mdbx_attr_t *attrptr, MDBX_cursor_op op);
/** @brief Get items attribute from a database.
/* Get items attribute from a database.
*
* This function retrieves key/data pairs attribute from the database.
* The attribute of the specified key-value pair is returned in
* uint64_t to which \b attrptr refers.
* If the database supports duplicate keys (#MDBX_DUPSORT) then both
* key and data parameters are required, otherwise data is ignored.
* This function retrieves key/data pairs from the database. The address
* and length of the data associated with the specified key are returned
* in the structure to which data refers.
* If the database supports duplicate keys (MDBX_DUPSORT) then the
* first data item for the key will be returned. Retrieval of other
* items requires the use of mdbx_cursor_get().
*
* @note Values returned from the database are valid only until a
* NOTE: The memory pointed to by the returned values is owned by the
* database. The caller need not dispose of the memory, and may not
* modify it in any way. For values returned in a read-only transaction
* any modification attempts will cause a SIGSEGV.
*
* NOTE: Values returned from the database are valid only until a
* subsequent update operation, or the end of the transaction.
* @param[in] txn A transaction handle returned by #mdb_txn_begin()
* @param[in] dbi A database handle returned by #mdb_dbi_open()
* @param[in] key The key to search for in the database
* @param[in] data The data for #MDBX_DUPSORT databases
* @param[out] attrptr The pointer to the result
* @return A non-zero error value on failure and 0 on success. Some possible
* errors are:
* <ul>
* <li>#MDBX_NOTFOUND - the key-value pair was not in the database.
* <li>EINVAL - an invalid parameter was specified.
* </ul>
*/
*
* [in] txn A transaction handle returned by mdbx_txn_begin()
* [in] dbi A database handle returned by mdbx_dbi_open()
* [in] key The key to search for in the database
* [in,out] data The data corresponding to the key
*
* Returns A non-zero error value on failure and 0 on success, some
* possible errors are:
* - MDBX_NOTFOUND - the key was not in the database.
* - MDBX_EINVAL - an invalid parameter was specified. */
int mdbx_get_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
mdbx_attr_t *attrptr);

View File

@ -11101,24 +11101,21 @@ int mdbx_dbi_sequence(MDBX_txn *txn, MDBX_dbi dbi, uint64_t *result,
/*----------------------------------------------------------------------------*/
/* attribute support functions for Nexenta */
static __inline int
mdbx_attr_peek(MDBX_val *data, mdbx_attr_t *attrptr)
{
static __inline int mdbx_attr_peek(MDBX_val *data, mdbx_attr_t *attrptr) {
if (unlikely(data->iov_len < sizeof(mdbx_attr_t)))
return MDBX_INCOMPATIBLE;
if (likely(attrptr != NULL))
*attrptr = *(mdbx_attr_t*) data->iov_base;
*attrptr = *(mdbx_attr_t *)data->iov_base;
data->iov_len -= sizeof(mdbx_attr_t);
data->iov_base = likely(data->iov_len > 0)
? ((mdbx_attr_t*) data->iov_base) + 1 : NULL;
data->iov_base =
likely(data->iov_len > 0) ? ((mdbx_attr_t *)data->iov_base) + 1 : NULL;
return MDBX_SUCCESS;
}
static __inline int
mdbx_attr_poke(MDBX_val *reserved, MDBX_val *data, mdbx_attr_t attr, unsigned flags)
{
static __inline int mdbx_attr_poke(MDBX_val *reserved, MDBX_val *data,
mdbx_attr_t attr, unsigned flags) {
mdbx_attr_t *space = reserved->iov_base;
if (flags & MDBX_RESERVE) {
if (likely(data != NULL)) {
@ -11127,17 +11124,15 @@ mdbx_attr_poke(MDBX_val *reserved, MDBX_val *data, mdbx_attr_t attr, unsigned fl
} else {
*space = attr;
if (likely(data != NULL)) {
memcpy(space + 1, data->iov_base, data->iov_len );
memcpy(space + 1, data->iov_base, data->iov_len);
}
}
return MDBX_SUCCESS;
}
int
mdbx_cursor_get_attr(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
mdbx_attr_t *attrptr, MDBX_cursor_op op)
{
int mdbx_cursor_get_attr(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
mdbx_attr_t *attrptr, MDBX_cursor_op op) {
int rc = mdbx_cursor_get(mc, key, data, op);
if (unlikely(rc != MDBX_SUCCESS))
return rc;
@ -11145,10 +11140,8 @@ mdbx_cursor_get_attr(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
return mdbx_attr_peek(data, attrptr);
}
int
mdbx_get_attr(MDBX_txn *txn, MDBX_dbi dbi,
MDBX_val *key, MDBX_val *data, uint64_t *attrptr)
{
int mdbx_get_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
uint64_t *attrptr) {
int rc = mdbx_get(txn, dbi, key, data);
if (unlikely(rc != MDBX_SUCCESS))
return rc;
@ -11156,14 +11149,11 @@ mdbx_get_attr(MDBX_txn *txn, MDBX_dbi dbi,
return mdbx_attr_peek(data, attrptr);
}
int
mdbx_put_attr(MDBX_txn *txn, MDBX_dbi dbi,
MDBX_val *key, MDBX_val *data, mdbx_attr_t attr, unsigned flags)
{
MDBX_val reserve = {
.iov_base = NULL,
.iov_len = (data ? data->iov_len : 0) + sizeof(mdbx_attr_t)
};
int mdbx_put_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
mdbx_attr_t attr, unsigned flags) {
MDBX_val reserve = {.iov_base = NULL,
.iov_len =
(data ? data->iov_len : 0) + sizeof(mdbx_attr_t)};
int rc = mdbx_put(txn, dbi, key, &reserve, flags | MDBX_RESERVE);
if (unlikely(rc != MDBX_SUCCESS))
@ -11173,12 +11163,10 @@ mdbx_put_attr(MDBX_txn *txn, MDBX_dbi dbi,
}
int mdbx_cursor_put_attr(MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data,
mdbx_attr_t attr, unsigned flags)
{
MDBX_val reserve = {
.iov_base = NULL,
.iov_len = (data ? data->iov_len : 0) + sizeof(mdbx_attr_t)
};
mdbx_attr_t attr, unsigned flags) {
MDBX_val reserve = {.iov_base = NULL,
.iov_len =
(data ? data->iov_len : 0) + sizeof(mdbx_attr_t)};
int rc = mdbx_cursor_put(cursor, key, &reserve, flags | MDBX_RESERVE);
if (unlikely(rc != MDBX_SUCCESS))
@ -11187,9 +11175,8 @@ int mdbx_cursor_put_attr(MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data,
return mdbx_attr_poke(&reserve, data, attr, flags);
}
int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi,
MDBX_val *key, MDBX_val *data, mdbx_attr_t attr)
{
int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
mdbx_attr_t attr) {
MDBX_cursor mc;
MDBX_xcursor mx;
MDBX_val old_data;
@ -11205,7 +11192,7 @@ int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi,
if (unlikely(!TXN_DBI_EXIST(txn, dbi, DB_USRVALID)))
return EINVAL;
if (unlikely(txn->mt_flags & (MDBX_TXN_RDONLY|MDBX_TXN_BLOCKED)))
if (unlikely(txn->mt_flags & (MDBX_TXN_RDONLY | MDBX_TXN_BLOCKED)))
return (txn->mt_flags & MDBX_TXN_RDONLY) ? EACCES : MDBX_BAD_TXN;
mdbx_cursor_init(&mc, txn, dbi, &mx);
@ -11224,14 +11211,15 @@ int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi,
if (unlikely(rc != MDBX_SUCCESS))
return rc;
if (old_attr == attr && (!data ||
(data->iov_len == old_data.iov_len
&& memcpy(data->iov_base, old_data.iov_base, old_data.iov_len) == 0)))
if (old_attr == attr && (!data || (data->iov_len == old_data.iov_len &&
memcpy(data->iov_base, old_data.iov_base,
old_data.iov_len) == 0)))
return MDBX_SUCCESS;
mc.mc_next = txn->mt_cursors[dbi];
txn->mt_cursors[dbi] = &mc;
rc = mdbx_cursor_put_attr(&mc, key, data ? data : &old_data, attr, MDBX_CURRENT);
rc = mdbx_cursor_put_attr(&mc, key, data ? data : &old_data, attr,
MDBX_CURRENT);
txn->mt_cursors[dbi] = mc.mc_next;
return rc;
}