mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-04 16:14:12 +08:00
mdbx: fix new API function after the merge.
Change-Id: Ic929444ceb137ccaa2ab4fe82b4f93a3cb5a92aa
This commit is contained in:
parent
b34e92d308
commit
aec35300c4
24
mdbx.h
24
mdbx.h
@ -1633,7 +1633,7 @@ 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 uint_fast64_t mdbx_attr_t;
|
||||||
|
|
||||||
/* Store by cursor with attribute.
|
/* Store by cursor with attribute.
|
||||||
*
|
*
|
||||||
@ -1668,8 +1668,9 @@ typedef uint64_t mdbx_attr_t;
|
|||||||
* - 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.
|
||||||
* - MDBX_EINVAL - an invalid parameter was specified. */
|
* - MDBX_EINVAL - an invalid parameter was specified. */
|
||||||
int mdbx_cursor_put_attr(MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data,
|
LIBMDBX_API int mdbx_cursor_put_attr(MDBX_cursor *cursor, MDBX_val *key,
|
||||||
mdbx_attr_t attr, unsigned flags);
|
MDBX_val *data, mdbx_attr_t attr,
|
||||||
|
unsigned flags);
|
||||||
|
|
||||||
/* Store items and attributes into a database.
|
/* Store items and attributes into a database.
|
||||||
*
|
*
|
||||||
@ -1713,8 +1714,8 @@ int mdbx_cursor_put_attr(MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data,
|
|||||||
* - 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.
|
||||||
* - MDBX_EINVAL - an invalid parameter was specified. */
|
* - MDBX_EINVAL - an invalid parameter was specified. */
|
||||||
int mdbx_put_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
|
LIBMDBX_API int mdbx_put_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
|
||||||
mdbx_attr_t attr, unsigned flags);
|
MDBX_val *data, mdbx_attr_t attr, unsigned flags);
|
||||||
|
|
||||||
/* Set items attribute from a database.
|
/* Set items attribute from a database.
|
||||||
*
|
*
|
||||||
@ -1733,8 +1734,8 @@ int mdbx_put_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
|
|||||||
* possible errors are:
|
* possible errors are:
|
||||||
* - MDBX_NOTFOUND - the key-value pair was not in the database.
|
* - MDBX_NOTFOUND - the key-value pair was not in the database.
|
||||||
* - MDBX_EINVAL - an invalid parameter was specified. */
|
* - MDBX_EINVAL - an invalid parameter was specified. */
|
||||||
int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
|
LIBMDBX_API int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
|
||||||
mdbx_attr_t attr);
|
MDBX_val *data, mdbx_attr_t attr);
|
||||||
|
|
||||||
/* Get items attribute from a database cursor.
|
/* Get items attribute from a database cursor.
|
||||||
*
|
*
|
||||||
@ -1753,8 +1754,9 @@ int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
|
|||||||
* possible errors are:
|
* possible errors are:
|
||||||
* - MDBX_NOTFOUND - no matching key found.
|
* - MDBX_NOTFOUND - no matching key found.
|
||||||
* - MDBX_EINVAL - an invalid parameter was specified. */
|
* - MDBX_EINVAL - an invalid parameter was specified. */
|
||||||
int mdbx_cursor_get_attr(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
|
LIBMDBX_API int mdbx_cursor_get_attr(MDBX_cursor *mc, MDBX_val *key,
|
||||||
mdbx_attr_t *attrptr, MDBX_cursor_op op);
|
MDBX_val *data, mdbx_attr_t *attrptr,
|
||||||
|
MDBX_cursor_op op);
|
||||||
|
|
||||||
/* Get items attribute from a database.
|
/* Get items attribute from a database.
|
||||||
*
|
*
|
||||||
@ -1782,8 +1784,8 @@ int mdbx_cursor_get_attr(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
|
|||||||
* possible errors are:
|
* possible errors are:
|
||||||
* - MDBX_NOTFOUND - the key was not in the database.
|
* - MDBX_NOTFOUND - the key was not in the database.
|
||||||
* - MDBX_EINVAL - an invalid parameter was specified. */
|
* - MDBX_EINVAL - an invalid parameter was specified. */
|
||||||
int mdbx_get_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
|
LIBMDBX_API int mdbx_get_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
|
||||||
mdbx_attr_t *attrptr);
|
MDBX_val *data, mdbx_attr_t *attrptr);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
24
src/mdbx.c
24
src/mdbx.c
@ -11151,9 +11151,9 @@ int mdbx_get_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,
|
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) {
|
||||||
MDBX_val reserve = {.iov_base = NULL,
|
MDBX_val reserve;
|
||||||
.iov_len =
|
reserve.iov_base = NULL;
|
||||||
(data ? data->iov_len : 0) + sizeof(mdbx_attr_t)};
|
reserve.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))
|
||||||
@ -11164,9 +11164,9 @@ int mdbx_put_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
|
|||||||
|
|
||||||
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 =
|
reserve.iov_base = NULL;
|
||||||
(data ? data->iov_len : 0) + sizeof(mdbx_attr_t)};
|
reserve.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))
|
||||||
@ -11177,12 +11177,6 @@ int mdbx_cursor_put_attr(MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data,
|
|||||||
|
|
||||||
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) {
|
||||||
MDBX_cursor mc;
|
|
||||||
MDBX_xcursor mx;
|
|
||||||
MDBX_val old_data;
|
|
||||||
mdbx_attr_t old_attr;
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
if (unlikely(!key || !txn))
|
if (unlikely(!key || !txn))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
@ -11195,8 +11189,11 @@ int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
|
|||||||
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 mc;
|
||||||
|
MDBX_xcursor mx;
|
||||||
|
MDBX_val old_data;
|
||||||
mdbx_cursor_init(&mc, txn, dbi, &mx);
|
mdbx_cursor_init(&mc, txn, dbi, &mx);
|
||||||
rc = mdbx_cursor_set(&mc, key, &old_data, MDBX_SET, NULL);
|
int rc = mdbx_cursor_set(&mc, key, &old_data, MDBX_SET, NULL);
|
||||||
if (unlikely(rc != MDBX_SUCCESS)) {
|
if (unlikely(rc != MDBX_SUCCESS)) {
|
||||||
if (rc == MDBX_NOTFOUND && data) {
|
if (rc == MDBX_NOTFOUND && data) {
|
||||||
mc.mc_next = txn->mt_cursors[dbi];
|
mc.mc_next = txn->mt_cursors[dbi];
|
||||||
@ -11207,6 +11204,7 @@ int mdbx_set_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mdbx_attr_t old_attr;
|
||||||
rc = mdbx_attr_peek(&old_data, &old_attr);
|
rc = mdbx_attr_peek(&old_data, &old_attr);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
return rc;
|
return rc;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user