* cause further writes to grow the database quickly, and
* stale locks can block further operation.
*
- * Fix: Terminate all programs using the database, or make
- * them close it. Next database user will reset the lockfile.
+ * Fix: Check for stale readers periodically, using the
+ * #mdb_reader_check function or the mdb_stat tool. Or just
+ * make all programs using the database close it; the lockfile
+ * is always reset on first open of the environment.
*
* - On BSD systems or others configured with MDB_USE_POSIX_SEM,
* startup can fail due to semaphores owned by another userid.
* ...when several processes can use a database concurrently:
*
* - Avoid aborting a process with an active transaction.
- * The transaction becomes "long-lived" as above until the lockfile
- * is reset, since the process may not remove it from the lockfile.
+ * The transaction becomes "long-lived" as above until a check
+ * for stale readers is performed or the lockfile is reset,
+ * since the process may not remove it from the lockfile.
*
- * - If you do that anyway, close the environment once in a while,
- * so the lockfile can get reset.
+ * - If you do that anyway, do a periodic check for stale readers. Or
+ * close the environment once in a while, so the lockfile can get reset.
*
* - Do not use MDB databases on remote filesystems, even between
* processes on the same host. This breaks flock() on some OSes,
#define MDB_PAGE_FULL (-30786)
/** Database contents grew beyond environment mapsize */
#define MDB_MAP_RESIZED (-30785)
- /** Database flags changed or would change */
+ /** MDB_INCOMPATIBLE: Operation and DB incompatible, or DB flags changed */
#define MDB_INCOMPATIBLE (-30784)
/** Invalid reuse of reader locktable slot */
#define MDB_BAD_RSLOT (-30783)
-#define MDB_LAST_ERRCODE MDB_BAD_RSLOT
+ /** Transaction cannot recover - it must be aborted */
+#define MDB_BAD_TXN (-30782)
+ /** Too big key/data, key is empty, or wrong DUPFIXED size */
+#define MDB_BAD_VALSIZE (-30781)
+#define MDB_LAST_ERRCODE MDB_BAD_VALSIZE
/** @} */
/** @brief Statistics for a database in the environment */
*/
int mdb_env_set_maxdbs(MDB_env *env, MDB_dbi dbs);
+ /** @brief Get the maximum size of a key for the environment.
+ *
+ * @param[in] env An environment handle returned by #mdb_env_create()
+ * @return The maximum size of a key. (#MDB_MAXKEYSIZE)
+ */
+int mdb_env_get_maxkeysize(MDB_env *env);
+
/** @brief Create a transaction for use with the environment.
*
* The transaction handle may be discarded using #mdb_txn_abort() or #mdb_txn_commit().
*/
int mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn);
+ /** @brief Returns the transaction's #MDB_env
+ *
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
+ */
+MDB_env *mdb_txn_env(MDB_txn *txn);
+
/** @brief Commit all the operations of a transaction into the database.
*
* The transaction handle is freed. It and its cursors must not be used
/** @brief Retrieve the DB flags for a database handle.
*
- * @param[in] env An environment handle returned by #mdb_env_create()
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
* @param[in] dbi A database handle returned by #mdb_dbi_open()
* @param[out] flags Address where the flags will be returned.
* @return A non-zero error value on failure and 0 on success.
*/
-int mdb_dbi_flags(MDB_env *env, MDB_dbi dbi, unsigned int *flags);
+int mdb_dbi_flags(MDB_txn *txn, MDB_dbi dbi, unsigned int *flags);
/** @brief Close a database handle.
*