diff --git a/libraries/liblmdb/lmdb.h b/libraries/liblmdb/lmdb.h
index da7b3c94a6..3969ee81f7 100644
--- a/libraries/liblmdb/lmdb.h
+++ b/libraries/liblmdb/lmdb.h
@@ -372,6 +372,13 @@ typedef void (MDB_sum_func)(const MDB_val *src, MDB_val *dst, const MDB_val *key
#define MDB_REMAP_CHUNKS 0x4000000
/** @} */
+/** @defgroup mdb_txn_begin Transaction Flags
+ * @{
+ */
+ /** don't initialize read-only txn; #mdb_txn_renew() must be called before first use */
+#define MDB_ROTXN_RESET 0x8000000
+/** @} */
+
/** @defgroup mdb_dbi_open Database Flags
* @{
*/
@@ -1143,6 +1150,8 @@ int mdb_env_set_checksum(MDB_env *env, MDB_sum_func *func, unsigned int size);
* Don't flush system buffers to disk when committing this transaction.
*
#MDB_NOMETASYNC
* Flush system buffers but omit metadata flush when committing this transaction.
+ * #MDB_ROTXN_RESET
+ * Must call #mdb_txn_renew() before using this readonly transaction.
*
* @param[out] txn Address where the new #MDB_txn handle will be stored
* @return A non-zero error value on failure and 0 on success. Some possible
diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c
index 03f0a19ea1..45d29f1f14 100644
--- a/libraries/liblmdb/mdb.c
+++ b/libraries/liblmdb/mdb.c
@@ -1512,7 +1512,7 @@ struct MDB_txn {
* @{
*/
/** #mdb_txn_begin() flags */
-#define MDB_TXN_BEGIN_FLAGS (MDB_NOMETASYNC|MDB_NOSYNC|MDB_RDONLY)
+#define MDB_TXN_BEGIN_FLAGS (MDB_NOMETASYNC|MDB_NOSYNC|MDB_RDONLY|MDB_ROTXN_RESET)
#define MDB_TXN_NOMETASYNC MDB_NOMETASYNC /**< don't sync meta for this txn on commit */
#define MDB_TXN_NOSYNC MDB_NOSYNC /**< don't sync this txn on commit */
#define MDB_TXN_RDONLY MDB_RDONLY /**< read-only transaction */
@@ -3487,6 +3487,9 @@ mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **ret)
if (env->me_flags & MDB_RDONLY & ~flags) /* write txn in RDONLY env */
return MDB_IS_READONLY;
+ if ((flags & MDB_ROTXN_RESET) && !(flags & MDB_RDONLY)) /* MDB_ROTXN_RESET requires MDB_RDONLY */
+ return EINVAL;
+
if (parent) {
/* Nested transactions:
* Only write txns may have nested txns;
@@ -3606,7 +3609,12 @@ mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **ret)
} else { /* MDB_RDONLY */
txn->mt_dbiseqs = env->me_dbiseqs;
renew:
- rc = mdb_txn_renew0(txn);
+ if (F_ISSET(flags, MDB_ROTXN_RESET)) {
+ rc = MDB_SUCCESS;
+ flags ^= (MDB_ROTXN_RESET|MDB_TXN_FINISHED);
+ } else {
+ rc = mdb_txn_renew0(txn);
+ }
}
if (rc) {
if (txn != env->me_txn0) {