mirror of
https://github.com/isar/libmdbx.git
synced 2025-03-10 07:08:13 +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
37
mdbx.h
37
mdbx.h
@ -5227,17 +5227,42 @@ LIBMDBX_API void mdbx_cursor_close(MDBX_cursor *cursor);
|
|||||||
* \see mdbx_cursor_unbind()
|
* \see mdbx_cursor_unbind()
|
||||||
* \see mdbx_cursor_close()
|
* \see mdbx_cursor_close()
|
||||||
*
|
*
|
||||||
* \param [in] txn A transaction handle returned by \ref mdbx_txn_begin().
|
* \param [in] txn A transaction handle returned by \ref mdbx_txn_begin().
|
||||||
* \param [in] unbind If non-zero, unbinds cursors and leaves ones reusable.
|
* \param [in] unbind If non-zero, unbinds cursors and leaves ones reusable.
|
||||||
* Otherwise close and dispose cursors.
|
* 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
|
* \returns A non-zero error value on failure and 0 on success,
|
||||||
* on success, some possible errors are:
|
* some possible errors are:
|
||||||
* \retval MDBX_THREAD_MISMATCH Given transaction is not owned
|
* \retval MDBX_THREAD_MISMATCH Given transaction is not owned
|
||||||
* by current thread.
|
* by current thread.
|
||||||
* \retval MDBX_BAD_TXN Given transaction is invalid or has
|
* \retval MDBX_BAD_TXN Given transaction is invalid or has
|
||||||
* a child/nested transaction transaction. */
|
* 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.
|
/** \brief Renew a cursor handle for use within the given transaction.
|
||||||
* \ingroup c_cursors
|
* \ingroup c_cursors
|
||||||
|
@ -216,14 +216,15 @@ again:
|
|||||||
return MDBX_SUCCESS;
|
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);
|
int rc = check_txn(txn, MDBX_TXN_FINISHED | MDBX_TXN_HAS_CHILD);
|
||||||
|
size_t n = 0;
|
||||||
if (likely(rc == MDBX_SUCCESS)) {
|
if (likely(rc == MDBX_SUCCESS)) {
|
||||||
TXN_FOREACH_DBI_FROM(txn, i, MAIN_DBI) {
|
TXN_FOREACH_DBI_FROM(txn, i, MAIN_DBI) {
|
||||||
while (txn->cursors[i]) {
|
while (txn->cursors[i]) {
|
||||||
|
++n;
|
||||||
MDBX_cursor *mc = txn->cursors[i];
|
MDBX_cursor *mc = txn->cursors[i];
|
||||||
ENSURE(nullptr, mc->signature == cur_signature_live && (mc->next != mc) && !mc->backup);
|
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;
|
txn->cursors[i] = mc->next;
|
||||||
mc->next = mc;
|
mc->next = mc;
|
||||||
if (unbind) {
|
if (unbind) {
|
||||||
@ -236,9 +237,10 @@ int mdbx_txn_release_all_cursors(const MDBX_txn *txn, bool unbind) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
eASSERT(nullptr, rc < 0);
|
|
||||||
LOG_IFERR(rc);
|
LOG_IFERR(rc);
|
||||||
}
|
}
|
||||||
|
if (count)
|
||||||
|
*count = n;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user