mirror of
https://github.com/isar/libmdbx.git
synced 2025-03-10 19:18:14 +08:00
mdbx: добавление в API mdbx_txn_release_all_cursors_ex()
и изменение семантики результата mdbx_txn_release_all_cursors()
(backport).
По недосмотру в выпусках остался предварительный/черновой вариант функции mdbx_txn_release_all_cursors(), который смешивает в возвращаемом значении информацию об ошибке/успехе и количество обработанных курсоров. За-за чего невозможно отличить одно от другого, например ошибку EPERM на Linux от одного успешно закрытого курсора. Теперь mdbx_txn_release_all_cursors() возвращает только код ошибки, а для получения кол-ва закрытых курсоров в API добавлена функция mdbx_txn_release_all_cursors_ex().
This commit is contained in:
parent
0604accecf
commit
94a2abaf31
31
mdbx.h
31
mdbx.h
@ -5230,14 +5230,39 @@ LIBMDBX_API void mdbx_cursor_close(MDBX_cursor *cursor);
|
||||
* \param [in] txn A transaction handle returned by \ref mdbx_txn_begin().
|
||||
* \param [in] unbind If non-zero, unbinds cursors and leaves ones reusable.
|
||||
* Otherwise close and dispose cursors.
|
||||
* \param [in,out] count An optional pointer to return the number of cursors
|
||||
* processed by the requested operation.
|
||||
*
|
||||
* \returns A negative error value on failure or the number of closed cursors
|
||||
* on success, some possible errors are:
|
||||
* \returns A non-zero error value on failure and 0 on success,
|
||||
* some possible errors are:
|
||||
* \retval MDBX_THREAD_MISMATCH Given transaction is not owned
|
||||
* by current thread.
|
||||
* \retval MDBX_BAD_TXN Given transaction is invalid or has
|
||||
* a child/nested transaction transaction. */
|
||||
LIBMDBX_API int mdbx_txn_release_all_cursors(const MDBX_txn *txn, bool unbind);
|
||||
LIBMDBX_API int mdbx_txn_release_all_cursors_ex(const MDBX_txn *txn, bool unbind, size_t *count);
|
||||
|
||||
/** \brief Unbind or closes all cursors of a given transaction.
|
||||
* \ingroup c_cursors
|
||||
*
|
||||
* Unbinds either closes all cursors associated (opened or renewed) with
|
||||
* a given transaction in a bulk with minimal overhead.
|
||||
*
|
||||
* \see mdbx_cursor_unbind()
|
||||
* \see mdbx_cursor_close()
|
||||
*
|
||||
* \param [in] txn A transaction handle returned by \ref mdbx_txn_begin().
|
||||
* \param [in] unbind If non-zero, unbinds cursors and leaves ones reusable.
|
||||
* Otherwise close and dispose cursors.
|
||||
*
|
||||
* \returns A non-zero error value on failure and 0 on success,
|
||||
* some possible errors are:
|
||||
* \retval MDBX_THREAD_MISMATCH Given transaction is not owned
|
||||
* by current thread.
|
||||
* \retval MDBX_BAD_TXN Given transaction is invalid or has
|
||||
* a child/nested transaction transaction. */
|
||||
LIBMDBX_INLINE_API(int, mdbx_txn_release_all_cursors, (const MDBX_txn *txn, bool unbind)) {
|
||||
return mdbx_txn_release_all_cursors_ex(txn, unbind, NULL);
|
||||
}
|
||||
|
||||
/** \brief Renew a cursor handle for use within the given transaction.
|
||||
* \ingroup c_cursors
|
||||
|
@ -216,14 +216,15 @@ again:
|
||||
return MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
int mdbx_txn_release_all_cursors(const MDBX_txn *txn, bool unbind) {
|
||||
int mdbx_txn_release_all_cursors_ex(const MDBX_txn *txn, bool unbind, size_t *count) {
|
||||
int rc = check_txn(txn, MDBX_TXN_FINISHED | MDBX_TXN_HAS_CHILD);
|
||||
size_t n = 0;
|
||||
if (likely(rc == MDBX_SUCCESS)) {
|
||||
TXN_FOREACH_DBI_FROM(txn, i, MAIN_DBI) {
|
||||
while (txn->cursors[i]) {
|
||||
++n;
|
||||
MDBX_cursor *mc = txn->cursors[i];
|
||||
ENSURE(nullptr, mc->signature == cur_signature_live && (mc->next != mc) && !mc->backup);
|
||||
rc = likely(rc < INT_MAX) ? rc + 1 : rc;
|
||||
txn->cursors[i] = mc->next;
|
||||
mc->next = mc;
|
||||
if (unbind) {
|
||||
@ -236,9 +237,10 @@ int mdbx_txn_release_all_cursors(const MDBX_txn *txn, bool unbind) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
eASSERT(nullptr, rc < 0);
|
||||
LOG_IFERR(rc);
|
||||
}
|
||||
if (count)
|
||||
*count = n;
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user