diff --git a/libraries/liblmdb/lmdb.h b/libraries/liblmdb/lmdb.h
index 7719e32..aaaa292 100644
--- a/libraries/liblmdb/lmdb.h
+++ b/libraries/liblmdb/lmdb.h
@@ -353,7 +353,9 @@ typedef enum MDB_cursor_op {
#define MDB_CURSOR_FULL (-30787)
/** Page has not enough space - internal error */
#define MDB_PAGE_FULL (-30786)
-#define MDB_LAST_ERRCODE MDB_PAGE_FULL
+ /** Database contents grew beyond environment mapsize */
+#define MDB_MAP_RESIZED (-30785)
+#define MDB_LAST_ERRCODE MDB_MAP_RESIZED
/** @} */
/** @brief Statistics for a database in the environment */
@@ -675,7 +677,9 @@ int mdb_env_set_maxdbs(MDB_env *env, MDB_dbi dbs);
* errors are:
*
* - #MDB_PANIC - a fatal error occurred earlier and the environment
- * must be shut down.
+- * must be shut down.
+ *
- #MDB_MAP_RESIZED - another process wrote data beyond this MDB_env's
+ * mapsize and the environment must be shut down.
*
- ENOMEM - out of memory, or a read-only transaction was requested and
* the reader lock table is full. See #mdb_env_set_maxreaders().
*
diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c
index 7bfdfc2..40b9bda 100644
--- a/libraries/liblmdb/mdb.c
+++ b/libraries/liblmdb/mdb.c
@@ -1054,7 +1054,8 @@ static char *const mdb_errstr[] = {
"MDB_TLS_FULL: Thread-local storage keys full - too many environments open",
"MDB_TXN_FULL: Transaction has too many dirty pages - transaction too big",
"MDB_CURSOR_FULL: Internal error - cursor stack limit reached",
- "MDB_PAGE_FULL: Internal error - page has no more space"
+ "MDB_PAGE_FULL: Internal error - page has no more space",
+ "MDB_MAP_RESIZED: Database contents grew beyond environment mapsize",
};
char *
@@ -1818,6 +1819,11 @@ mdb_txn_renew0(MDB_txn *txn)
if (txn->mt_numdbs > 2)
memset(txn->mt_dbflags+2, DB_STALE, txn->mt_numdbs-2);
+ if (env->me_maxpg < txn->mt_next_pgno) {
+ mdb_txn_reset0(txn);
+ return MDB_MAP_RESIZED;
+ }
+
return MDB_SUCCESS;
}