From 6f53dd0719d8977169d6d20bc8836eb6126bd6b6 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Fri, 9 Jun 2017 16:35:41 +0300 Subject: [PATCH] mdbx: add mdbx_dbi_flags_ex(). --- mdbx.h | 6 ++++++ src/bits.h | 12 ++++++------ src/mdbx.c | 12 ++++++++++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/mdbx.h b/mdbx.h index 8d5a6e2e..4fe0d908 100644 --- a/mdbx.h +++ b/mdbx.h @@ -1104,8 +1104,14 @@ LIBMDBX_API int mdbx_dbi_stat(MDBX_txn *txn, MDBX_dbi dbi, MDBX_stat *stat, * [in] txn A transaction handle returned by mdbx_txn_begin() * [in] dbi A database handle returned by mdbx_dbi_open() * [out] flags Address where the flags will be returned. + * [out] state Address where the state will be returned. * * Returns A non-zero error value on failure and 0 on success. */ +#define MDBX_TBL_DIRTY 0x01 /* DB was written in this txn */ +#define MDBX_TBL_STALE 0x02 /* Named-DB record is older than txnID */ +#define MDBX_TBL_NEW 0x04 /* Named-DB handle opened in this txn */ +LIBMDBX_API int mdbx_dbi_flags_ex(MDBX_txn *txn, MDBX_dbi dbi, unsigned *flags, + unsigned *state); LIBMDBX_API int mdbx_dbi_flags(MDBX_txn *txn, MDBX_dbi dbi, unsigned *flags); /* Close a database handle. Normally unnecessary. diff --git a/src/bits.h b/src/bits.h index 3753f7c0..90df0972 100644 --- a/src/bits.h +++ b/src/bits.h @@ -488,12 +488,12 @@ struct MDBX_txn { unsigned *mt_dbiseqs; /* Transaction DB Flags */ -#define DB_DIRTY 0x01 /* DB was written in this txn */ -#define DB_STALE 0x02 /* Named-DB record is older than txnID */ -#define DB_NEW 0x04 /* Named-DB handle opened in this txn */ -#define DB_VALID 0x08 /* DB handle is valid, see also MDBX_VALID */ -#define DB_USRVALID 0x10 /* As DB_VALID, but not set for FREE_DBI */ -#define DB_DUPDATA 0x20 /* DB is MDBX_DUPSORT data */ +#define DB_DIRTY MDBX_TBL_DIRTY /* DB was written in this txn */ +#define DB_STALE MDBX_TBL_STALE /* Named-DB record is older than txnID */ +#define DB_NEW MDBX_TBL_NEW /* Named-DB handle opened in this txn */ +#define DB_VALID 0x08 /* DB handle is valid, see also MDBX_VALID */ +#define DB_USRVALID 0x10 /* As DB_VALID, but not set for FREE_DBI */ +#define DB_DUPDATA 0x20 /* DB is MDBX_DUPSORT data */ /* In write txns, array of cursors for each DB */ MDBX_cursor **mt_cursors; /* Array of flags for each DB */ diff --git a/src/mdbx.c b/src/mdbx.c index 417595ad..13f4ee74 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -9470,8 +9470,9 @@ int mdbx_dbi_close(MDBX_env *env, MDBX_dbi dbi) { return rc; } -int mdbx_dbi_flags(MDBX_txn *txn, MDBX_dbi dbi, unsigned *flags) { - if (unlikely(!txn || !flags)) +int mdbx_dbi_flags_ex(MDBX_txn *txn, MDBX_dbi dbi, unsigned *flags, + unsigned *state) { + if (unlikely(!txn || !flags || !state)) return MDBX_EINVAL; if (unlikely(txn->mt_signature != MDBX_MT_SIGNATURE)) @@ -9484,9 +9485,16 @@ int mdbx_dbi_flags(MDBX_txn *txn, MDBX_dbi dbi, unsigned *flags) { return MDBX_EINVAL; *flags = txn->mt_dbs[dbi].md_flags & PERSISTENT_FLAGS; + *state = txn->mt_dbflags[dbi] & (DB_NEW | DB_DIRTY | DB_STALE); + return MDBX_SUCCESS; } +int mdbx_dbi_flags(MDBX_txn *txn, MDBX_dbi dbi, unsigned *flags) { + unsigned state; + return mdbx_dbi_flags_ex(txn, dbi, flags, &state); +} + /* Add all the DB's pages to the free list. * [in] mc Cursor on the DB to free. * [in] subs non-Zero to check for sub-DBs in this DB.