mirror of
https://github.com/isar/libmdbx.git
synced 2024-10-30 11:29:19 +08:00
mdbx: cleanup/reformat after the merge.
Change-Id: I3e0fe8f1292a6387e8d3ff8b904170f05d8e1770
This commit is contained in:
parent
594834bc9c
commit
b34e92d308
271
mdbx.h
271
mdbx.h
@ -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
|
* [in] env An environment handle returned by mdbx_env_create(). It must
|
||||||
* have already been opened successfully.
|
* have already been opened successfully.
|
||||||
* [in] path The directory in which the copy will reside. This directory must
|
* [in] path The directory in which the copy will reside. This directory
|
||||||
* already exist and be writable but must otherwise be empty.
|
* must already exist and be writable but must otherwise be empty.
|
||||||
* [in] flags Special options for this operation. This parameter must be set
|
* [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
|
* to 0 or by bitwise OR'ing together one or more of the values
|
||||||
* described here:
|
* 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] env An environment handle returned by mdbx_env_create()
|
||||||
* [in] dont_sync A dont'sync flag, if non-zero the last checkpoint (meta-page
|
* [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
|
* update) will be kept "as is" and may be still "weak" in the
|
||||||
* NOSYNC/MAPASYNC modes. Such "weak" checkpoint will be ignored
|
* NOSYNC/MAPASYNC modes. Such "weak" checkpoint will be
|
||||||
* on opening next time, and transactions since the last non-weak
|
* ignored on opening next time, and transactions since the
|
||||||
* checkpoint (meta-page update) will rolledback for consistency
|
* last non-weak checkpoint (meta-page update) will rolledback
|
||||||
* guarantee. */
|
* for consistency guarantee. */
|
||||||
LIBMDBX_API void mdbx_env_close(MDBX_env *env);
|
LIBMDBX_API void mdbx_env_close(MDBX_env *env);
|
||||||
|
|
||||||
/* Set environment flags.
|
/* 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
|
/* 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);
|
LIBMDBX_API MDBX_env *mdbx_txn_env(MDBX_txn *txn);
|
||||||
|
|
||||||
/* Return the transaction's ID.
|
/* 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] txn A transaction handle returned by mdbx_txn_begin()
|
||||||
* [in] dbi A database handle returned by mdbx_dbi_open()
|
* [in] dbi A database handle returned by mdbx_dbi_open()
|
||||||
* [in] key The key to search for in the database
|
* [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
|
* Returns A non-zero error value on failure and 0 on success, some
|
||||||
* possible errors are:
|
* 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
|
* Returns A non-zero error value on failure and 0 on success, some
|
||||||
* possible errors are:
|
* possible errors are:
|
||||||
|
* - MDBX_KEYEXIST
|
||||||
* - MDBX_MAP_FULL - the database is full, see mdbx_env_set_mapsize().
|
* - MDBX_MAP_FULL - the database is full, see mdbx_env_set_mapsize().
|
||||||
* - MDBX_TXN_FULL - the transaction has too many dirty pages.
|
* - MDBX_TXN_FULL - the transaction has too many dirty pages.
|
||||||
* - MDBX_EACCES - an attempt was made to write in a read-only transaction.
|
* - 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] key The key operated on.
|
||||||
* [in] data The data operated on.
|
* [in] data The data operated on.
|
||||||
* [in] flags Options for this operation. This parameter
|
* [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
|
* - MDBX_CURRENT
|
||||||
* Replace the item at the current cursor position. The key parameter
|
* 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 */
|
/* attribute support functions for Nexenta */
|
||||||
typedef uint64_t mdbx_attr_t;
|
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.
|
* This function stores key/data pairs into the database. The cursor is
|
||||||
* The cursor is positioned at the new item, or on failure usually near it.
|
* 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
|
* NOTE: Internally based on MDBX_RESERVE feature,
|
||||||
* state of the cursor unchanged.
|
* therefore doesn't support MDBX_DUPSORT.
|
||||||
* @param[in] cursor A cursor handle returned by #mdb_cursor_open()
|
*
|
||||||
* @param[in] key The key operated on.
|
* [in] cursor A cursor handle returned by mdbx_cursor_open()
|
||||||
* @param[in] data The data operated on.
|
* [in] key The key operated on.
|
||||||
* @param[in] attr The attribute.
|
* [in] data The data operated on.
|
||||||
* @param[in] flags Options for this operation. This parameter
|
* [in] attr The attribute.
|
||||||
* must be set to 0 or one of the values described here.
|
* [in] flags Options for this operation. This parameter must be set to 0
|
||||||
* <ul>
|
* or one of the values described here:
|
||||||
* <li>#MDBX_CURRENT - replace the item at the current cursor position.
|
*
|
||||||
* The \b key parameter must still be provided, and must match it.
|
* - MDBX_CURRENT
|
||||||
* This is intended to be used when the
|
* Replace the item at the current cursor position. The key parameter
|
||||||
* new data is the same size as the old. Otherwise it will simply
|
* must still be provided, and must match it, otherwise the function
|
||||||
* perform a delete of the old record followed by an insert.
|
* return MDBX_EKEYMISMATCH.
|
||||||
* <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_APPEND
|
||||||
* #MDBX_KEYEXIST if the key already appears in the database.
|
* Append the given key/data pair to the end of the database. No key
|
||||||
* <li>#MDBX_RESERVE - reserve space for data of the given size, but
|
* comparisons are performed. This option allows fast bulk loading when
|
||||||
* don't copy the given data. Instead, return a pointer to the
|
* keys are already known to be in the correct order. Loading unsorted
|
||||||
* reserved space, which the caller can fill in later. This saves
|
* keys with this flag will cause a MDBX_KEYEXIST error.
|
||||||
* an extra memcpy if the data is being generated later.
|
*
|
||||||
* <li>#MDBX_APPEND - append the given key/data pair to the end of the
|
* Returns A non-zero error value on failure and 0 on success, some
|
||||||
* database. No key comparisons are performed. This option allows
|
* possible errors are:
|
||||||
* fast bulk loading when keys are already known to be in the
|
* - MDBX_EKEYMISMATCH
|
||||||
* correct order. Loading unsorted keys with this flag will cause
|
* - MDBX_MAP_FULL - the database is full, see mdbx_env_set_mapsize().
|
||||||
* data corruption.
|
* - MDBX_TXN_FULL - the transaction has too many dirty pages.
|
||||||
* </ul>
|
* - MDBX_EACCES - an attempt was made to write in a read-only transaction.
|
||||||
* @return A non-zero error value on failure and 0 on success. Some possible
|
* - MDBX_EINVAL - an invalid parameter was specified. */
|
||||||
* 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>
|
|
||||||
*/
|
|
||||||
int mdbx_cursor_put_attr(MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data,
|
int mdbx_cursor_put_attr(MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data,
|
||||||
mdbx_attr_t attr, unsigned flags);
|
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
|
* 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
|
* is to enter the new key/data pair, replacing any previously existing key
|
||||||
* if duplicates are disallowed.
|
* 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()
|
* NOTE: Internally based on MDBX_RESERVE feature,
|
||||||
* @param[in] dbi A database handle returned by #mdb_dbi_open()
|
* therefore doesn't support MDBX_DUPSORT.
|
||||||
* @param[in] key The key to store in the database
|
*
|
||||||
* @param[in] attr The attribute to store in the database
|
* [in] txn A transaction handle returned by mdbx_txn_begin().
|
||||||
* @param[in,out] data The data to store
|
* [in] dbi A database handle returned by mdbx_dbi_open().
|
||||||
* @param[in] flags Special options for this operation. This parameter
|
* [in] key The key to store in the database.
|
||||||
* must be set to 0 or by bitwise OR'ing together one or more of the
|
* [in] attr The attribute to store in the database.
|
||||||
* values described here.
|
* [in,out] data The data to store.
|
||||||
* <ul>
|
* [in] flags Special options for this operation. This parameter must be
|
||||||
* <li>#MDBX_NOOVERWRITE - enter the new key/data pair only if the key
|
* set to 0 or by bitwise OR'ing together one or more of the
|
||||||
* does not already appear in the database. The function will return
|
* values described here:
|
||||||
* #MDBX_KEYEXIST if the key already appears in the database. The \b data
|
*
|
||||||
* parameter will be set to point to the existing item.
|
* - MDBX_NOOVERWRITE
|
||||||
* <li>#MDBX_RESERVE - reserve space for data of the given size, but
|
* Enter the new key/data pair only if the key does not already appear
|
||||||
* don't copy the given data. Instead, return a pointer to the
|
* in the database. The function will return MDBX_KEYEXIST if the key
|
||||||
* reserved space, which the caller can fill in later - before
|
* already appears in the database. The data parameter will be set to
|
||||||
* the next update operation or the transaction ends. This saves
|
* point to the existing item.
|
||||||
* an extra memcpy if the data is being generated later.
|
*
|
||||||
* LMDB does nothing else with this memory, the caller is expected
|
* - MDBX_CURRENT
|
||||||
* to modify all of the space requested.
|
* Update an single existing entry, but not add new ones. The function
|
||||||
* <li>#MDBX_APPEND - append the given key/data pair to the end of the
|
* will return MDBX_NOTFOUND if the given key not exist in the database.
|
||||||
* database. This option allows fast bulk loading when keys are
|
* Or the MDBX_EMULTIVAL in case duplicates for the given key.
|
||||||
* already known to be in the correct order. Loading unsorted keys
|
*
|
||||||
* with this flag will cause a #MDBX_KEYEXIST error.
|
* - MDBX_APPEND
|
||||||
* </ul>
|
* Append the given key/data pair to the end of the database. This option
|
||||||
* @return A non-zero error value on failure and 0 on success. Some possible
|
* allows fast bulk loading when keys are already known to be in the
|
||||||
* errors are:
|
* correct order. Loading unsorted keys with this flag will cause
|
||||||
* <ul>
|
* a MDBX_EKEYMISMATCH error.
|
||||||
* <li>#MDBX_MAP_FULL - the database is full, see #mdb_env_set_mapsize().
|
*
|
||||||
* <li>#MDBX_TXN_FULL - the transaction has too many dirty pages.
|
* Returns A non-zero error value on failure and 0 on success, some
|
||||||
* <li>EACCES - an attempt was made to write in a read-only transaction.
|
* possible errors are:
|
||||||
* <li>EINVAL - an invalid parameter was specified.
|
* - MDBX_KEYEXIST
|
||||||
* </ul>
|
* - 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,
|
int mdbx_put_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
|
||||||
mdbx_attr_t attr, unsigned flags);
|
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.
|
* 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()
|
* NOTE: Internally based on MDBX_RESERVE feature,
|
||||||
* @param[in] dbi A database handle returned by #mdb_dbi_open()
|
* therefore doesn't support MDBX_DUPSORT.
|
||||||
* @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.
|
* [in] txn A transaction handle returned by mdbx_txn_begin().
|
||||||
* @param[in] attr The attribute to be stored
|
* [in] dbi A database handle returned by mdbx_dbi_open().
|
||||||
* @return A non-zero error value on failure and 0 on success. Some possible
|
* [in] key The key to search for in the database.
|
||||||
* errors are:
|
* [in] data The data to be stored or NULL to save previous value.
|
||||||
* <ul>
|
* [in] attr The attribute to be stored.
|
||||||
* <li>#MDBX_NOTFOUND - the key-value pair was not in the database.
|
*
|
||||||
* <li>EINVAL - an invalid parameter was specified.
|
* Returns A non-zero error value on failure and 0 on success, some
|
||||||
* </ul>
|
* 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,
|
int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
|
||||||
mdbx_attr_t attr);
|
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.
|
* This function retrieves key/data pairs from the database. The address and
|
||||||
* The attribute of the specified key-value pair is returned in
|
* length of the key are returned in the object to which key refers (except
|
||||||
* uint64_t to which \b attrptr refers.
|
* for the case of the MDBX_SET option, in which the key object is unchanged),
|
||||||
* If the database supports duplicate keys (#MDBX_DUPSORT) then both
|
* and the address and length of the data are returned in the object to which
|
||||||
* key and data parameters are required, otherwise data could be NULL.
|
* data refers. See mdbx_get() for restrictions on using the output values.
|
||||||
*
|
*
|
||||||
* @note Values returned from the database are valid only until a
|
* [in] cursor A cursor handle returned by mdbx_cursor_open()
|
||||||
* subsequent update operation, or the end of the transaction.
|
* [in,out] key The key for a retrieved item
|
||||||
* @param[in] mc A database cursor pointing at the node
|
* [in,out] data The data of a retrieved item
|
||||||
* @param[in] key The key to search for in the database
|
* [in] op A cursor operation MDBX_cursor_op
|
||||||
* @param[in,out] data The data for #MDBX_DUPSORT databases
|
*
|
||||||
* @param[out] attrptr The pointer to the result
|
* Returns A non-zero error value on failure and 0 on success, some
|
||||||
* @param[in] op A cursor operation #MDBX_cursor_op
|
* possible errors are:
|
||||||
* @return A non-zero error value on failure and 0 on success. Some possible
|
* - MDBX_NOTFOUND - no matching key found.
|
||||||
* errors are:
|
* - MDBX_EINVAL - an invalid parameter was specified. */
|
||||||
* <ul>
|
|
||||||
* <li>#MDBX_NOTFOUND - the key-value pair was not in the database.
|
|
||||||
* <li>EINVAL - an invalid parameter was specified.
|
|
||||||
* </ul>
|
|
||||||
*/
|
|
||||||
int mdbx_cursor_get_attr(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
|
int mdbx_cursor_get_attr(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
|
||||||
mdbx_attr_t *attrptr, MDBX_cursor_op op);
|
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.
|
* This function retrieves key/data pairs from the database. The address
|
||||||
* The attribute of the specified key-value pair is returned in
|
* and length of the data associated with the specified key are returned
|
||||||
* uint64_t to which \b attrptr refers.
|
* in the structure to which data refers.
|
||||||
* If the database supports duplicate keys (#MDBX_DUPSORT) then both
|
* If the database supports duplicate keys (MDBX_DUPSORT) then the
|
||||||
* key and data parameters are required, otherwise data is ignored.
|
* 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.
|
* 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()
|
* [in] txn A transaction handle returned by mdbx_txn_begin()
|
||||||
* @param[in] key The key to search for in the database
|
* [in] dbi A database handle returned by mdbx_dbi_open()
|
||||||
* @param[in] data The data for #MDBX_DUPSORT databases
|
* [in] key The key to search for in the database
|
||||||
* @param[out] attrptr The pointer to the result
|
* [in,out] data The data corresponding to the key
|
||||||
* @return A non-zero error value on failure and 0 on success. Some possible
|
*
|
||||||
* errors are:
|
* Returns A non-zero error value on failure and 0 on success, some
|
||||||
* <ul>
|
* possible errors are:
|
||||||
* <li>#MDBX_NOTFOUND - the key-value pair was not in the database.
|
* - MDBX_NOTFOUND - the key was not in the database.
|
||||||
* <li>EINVAL - an invalid parameter was specified.
|
* - MDBX_EINVAL - an invalid parameter was specified. */
|
||||||
* </ul>
|
|
||||||
*/
|
|
||||||
int mdbx_get_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
|
int mdbx_get_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
|
||||||
mdbx_attr_t *attrptr);
|
mdbx_attr_t *attrptr);
|
||||||
|
|
||||||
|
68
src/mdbx.c
68
src/mdbx.c
@ -11101,24 +11101,21 @@ int mdbx_dbi_sequence(MDBX_txn *txn, MDBX_dbi dbi, uint64_t *result,
|
|||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/* attribute support functions for Nexenta */
|
/* attribute support functions for Nexenta */
|
||||||
|
|
||||||
static __inline int
|
static __inline int mdbx_attr_peek(MDBX_val *data, mdbx_attr_t *attrptr) {
|
||||||
mdbx_attr_peek(MDBX_val *data, mdbx_attr_t *attrptr)
|
|
||||||
{
|
|
||||||
if (unlikely(data->iov_len < sizeof(mdbx_attr_t)))
|
if (unlikely(data->iov_len < sizeof(mdbx_attr_t)))
|
||||||
return MDBX_INCOMPATIBLE;
|
return MDBX_INCOMPATIBLE;
|
||||||
|
|
||||||
if (likely(attrptr != NULL))
|
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_len -= sizeof(mdbx_attr_t);
|
||||||
data->iov_base = likely(data->iov_len > 0)
|
data->iov_base =
|
||||||
? ((mdbx_attr_t*) data->iov_base) + 1 : NULL;
|
likely(data->iov_len > 0) ? ((mdbx_attr_t *)data->iov_base) + 1 : NULL;
|
||||||
|
|
||||||
return MDBX_SUCCESS;
|
return MDBX_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline int
|
static __inline int mdbx_attr_poke(MDBX_val *reserved, MDBX_val *data,
|
||||||
mdbx_attr_poke(MDBX_val *reserved, MDBX_val *data, mdbx_attr_t attr, unsigned flags)
|
mdbx_attr_t attr, unsigned flags) {
|
||||||
{
|
|
||||||
mdbx_attr_t *space = reserved->iov_base;
|
mdbx_attr_t *space = reserved->iov_base;
|
||||||
if (flags & MDBX_RESERVE) {
|
if (flags & MDBX_RESERVE) {
|
||||||
if (likely(data != NULL)) {
|
if (likely(data != NULL)) {
|
||||||
@ -11127,17 +11124,15 @@ mdbx_attr_poke(MDBX_val *reserved, MDBX_val *data, mdbx_attr_t attr, unsigned fl
|
|||||||
} else {
|
} else {
|
||||||
*space = attr;
|
*space = attr;
|
||||||
if (likely(data != NULL)) {
|
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;
|
return MDBX_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int mdbx_cursor_get_attr(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
|
||||||
mdbx_cursor_get_attr(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
|
mdbx_attr_t *attrptr, MDBX_cursor_op op) {
|
||||||
mdbx_attr_t *attrptr, MDBX_cursor_op op)
|
|
||||||
{
|
|
||||||
int rc = mdbx_cursor_get(mc, key, data, op);
|
int rc = mdbx_cursor_get(mc, key, data, op);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
return rc;
|
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);
|
return mdbx_attr_peek(data, attrptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int mdbx_get_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
|
||||||
mdbx_get_attr(MDBX_txn *txn, MDBX_dbi dbi,
|
uint64_t *attrptr) {
|
||||||
MDBX_val *key, MDBX_val *data, uint64_t *attrptr)
|
|
||||||
{
|
|
||||||
int rc = mdbx_get(txn, dbi, key, data);
|
int rc = mdbx_get(txn, dbi, key, data);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
return rc;
|
return rc;
|
||||||
@ -11156,14 +11149,11 @@ mdbx_get_attr(MDBX_txn *txn, MDBX_dbi dbi,
|
|||||||
return mdbx_attr_peek(data, attrptr);
|
return mdbx_attr_peek(data, attrptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int mdbx_put_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
|
||||||
mdbx_put_attr(MDBX_txn *txn, MDBX_dbi dbi,
|
mdbx_attr_t attr, unsigned flags) {
|
||||||
MDBX_val *key, MDBX_val *data, mdbx_attr_t attr, unsigned flags)
|
MDBX_val reserve = {.iov_base = NULL,
|
||||||
{
|
.iov_len =
|
||||||
MDBX_val reserve = {
|
(data ? data->iov_len : 0) + sizeof(mdbx_attr_t)};
|
||||||
.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);
|
int rc = mdbx_put(txn, dbi, key, &reserve, flags | MDBX_RESERVE);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
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,
|
int mdbx_cursor_put_attr(MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data,
|
||||||
mdbx_attr_t attr, unsigned flags)
|
mdbx_attr_t attr, unsigned flags) {
|
||||||
{
|
MDBX_val reserve = {.iov_base = NULL,
|
||||||
MDBX_val reserve = {
|
.iov_len =
|
||||||
.iov_base = NULL,
|
(data ? data->iov_len : 0) + sizeof(mdbx_attr_t)};
|
||||||
.iov_len = (data ? data->iov_len : 0) + sizeof(mdbx_attr_t)
|
|
||||||
};
|
|
||||||
|
|
||||||
int rc = mdbx_cursor_put(cursor, key, &reserve, flags | MDBX_RESERVE);
|
int rc = mdbx_cursor_put(cursor, key, &reserve, flags | MDBX_RESERVE);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
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);
|
return mdbx_attr_poke(&reserve, data, attr, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi,
|
int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
|
||||||
MDBX_val *key, MDBX_val *data, mdbx_attr_t attr)
|
mdbx_attr_t attr) {
|
||||||
{
|
|
||||||
MDBX_cursor mc;
|
MDBX_cursor mc;
|
||||||
MDBX_xcursor mx;
|
MDBX_xcursor mx;
|
||||||
MDBX_val old_data;
|
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)))
|
if (unlikely(!TXN_DBI_EXIST(txn, dbi, DB_USRVALID)))
|
||||||
return EINVAL;
|
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;
|
return (txn->mt_flags & MDBX_TXN_RDONLY) ? EACCES : MDBX_BAD_TXN;
|
||||||
|
|
||||||
mdbx_cursor_init(&mc, txn, dbi, &mx);
|
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))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
if (old_attr == attr && (!data ||
|
if (old_attr == attr && (!data || (data->iov_len == old_data.iov_len &&
|
||||||
(data->iov_len == old_data.iov_len
|
memcpy(data->iov_base, old_data.iov_base,
|
||||||
&& memcpy(data->iov_base, old_data.iov_base, old_data.iov_len) == 0)))
|
old_data.iov_len) == 0)))
|
||||||
return MDBX_SUCCESS;
|
return MDBX_SUCCESS;
|
||||||
|
|
||||||
mc.mc_next = txn->mt_cursors[dbi];
|
mc.mc_next = txn->mt_cursors[dbi];
|
||||||
txn->mt_cursors[dbi] = &mc;
|
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;
|
txn->mt_cursors[dbi] = mc.mc_next;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user