]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#8250 LMDB: add option MDB_ROTXN_RESET flag for txn_begin
authorJames Rouzier <rouzier@gmail.com>
Wed, 1 Apr 2015 15:17:12 +0000 (11:17 -0400)
committerHoward Chu <hyc@openldap.org>
Fri, 24 Apr 2026 19:01:52 +0000 (20:01 +0100)
Create a readonly txn in a reset state, it cannot be used until
mdb_txn_renew() is called.

libraries/liblmdb/lmdb.h
libraries/liblmdb/mdb.c

index da7b3c94a602248efca0c6a11c714decc212f9d6..3969ee81f7bfdebca7502842a3e36b94184799b4 100644 (file)
@@ -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.
         *      <li>#MDB_NOMETASYNC
         *              Flush system buffers but omit metadata flush when committing this transaction.
+        *      <li>#MDB_ROTXN_RESET
+        *              Must call #mdb_txn_renew() before using this readonly transaction.
         * </ul>
         * @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
index 03f0a19ea1a561b7c4f25d9d2547f6864f48e1d5..45d29f1f148631fe32ca34415ccb703dac691654 100644 (file)
@@ -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) {