Revert ITS#7789 commits, let's try this again.

Revert "ITS#7789 Fix resize vs MDB_NOMETASYNC, and a comment."
Revert "ITS#7789 more"
Revert "Revert "ITS#7789 update RESIZED errmsg text""
Revert "ITS#7789 update RESIZED errmsg text"
Revert "ITS#7789 persist mapsize changes"

This reverts commit 02285aca58.
This reverts commit 38e71c68de.
This reverts commit a5e4eecb1e.
This reverts commit d8e18551c3.
This reverts commit 5926e54bba.
vl32
Howard Chu 10 years ago
parent 015d6b909a
commit 7ef970436d
  1. 7
      libraries/liblmdb/lmdb.h
  2. 50
      libraries/liblmdb/mdb.c

@ -411,7 +411,7 @@ typedef enum MDB_cursor_op {
#define MDB_CURSOR_FULL (-30787) #define MDB_CURSOR_FULL (-30787)
/** Page has not enough space - internal error */ /** Page has not enough space - internal error */
#define MDB_PAGE_FULL (-30786) #define MDB_PAGE_FULL (-30786)
/** Environment mapsize was changed by another process */ /** Database contents grew beyond environment mapsize */
#define MDB_MAP_RESIZED (-30785) #define MDB_MAP_RESIZED (-30785)
/** MDB_INCOMPATIBLE: Operation and DB incompatible, or DB flags changed */ /** MDB_INCOMPATIBLE: Operation and DB incompatible, or DB flags changed */
#define MDB_INCOMPATIBLE (-30784) #define MDB_INCOMPATIBLE (-30784)
@ -785,10 +785,7 @@ int mdb_env_get_fd(MDB_env *env, mdb_filehandle_t *fd);
* This function should be called after #mdb_env_create() and before #mdb_env_open(). * This function should be called after #mdb_env_create() and before #mdb_env_open().
* It may be called at later times if no transactions are active in * It may be called at later times if no transactions are active in
* this process. Note that the library does not check for this condition, * this process. Note that the library does not check for this condition,
* the caller must ensure it explicitly. The new size takes effect * the caller must ensure it explicitly.
* immediately for the current process but will not be persisted to
* any others until a write transaction has been committed by the
* current process.
* *
* If the mapsize is changed by another process, #mdb_txn_begin() will * If the mapsize is changed by another process, #mdb_txn_begin() will
* return #MDB_MAP_RESIZED. This function may be called with a size * return #MDB_MAP_RESIZED. This function may be called with a size

@ -1074,8 +1074,6 @@ struct MDB_env {
HANDLE me_mfd; /**< just for writing the meta pages */ HANDLE me_mfd; /**< just for writing the meta pages */
/** Failed to update the meta page. Probably an I/O error. */ /** Failed to update the meta page. Probably an I/O error. */
#define MDB_FATAL_ERROR 0x80000000U #define MDB_FATAL_ERROR 0x80000000U
/** We're explicitly changing the mapsize. */
#define MDB_RESIZING 0x40000000U
/** Some fields are initialized. */ /** Some fields are initialized. */
#define MDB_ENV_ACTIVE 0x20000000U #define MDB_ENV_ACTIVE 0x20000000U
/** me_txkey is set */ /** me_txkey is set */
@ -2537,9 +2535,7 @@ mdb_txn_renew0(MDB_txn *txn)
} }
txn->mt_dbflags[0] = txn->mt_dbflags[1] = DB_VALID; txn->mt_dbflags[0] = txn->mt_dbflags[1] = DB_VALID;
/* If we didn't ask for a resize, but the size grew, fail */ if (env->me_maxpg < txn->mt_next_pgno) {
if (!(env->me_flags & MDB_RESIZING)
&& env->me_mapsize < meta->mm_mapsize) {
mdb_txn_reset0(txn, "renew0-mapfail"); mdb_txn_reset0(txn, "renew0-mapfail");
if (new_notls) { if (new_notls) {
txn->mt_u.reader->mr_pid = 0; txn->mt_u.reader->mr_pid = 0;
@ -3277,13 +3273,8 @@ mdb_txn_commit(MDB_txn *txn)
mdb_cursors_close(txn, 0); mdb_cursors_close(txn, 0);
if (!txn->mt_u.dirty_list[0].mid && if (!txn->mt_u.dirty_list[0].mid &&
!(txn->mt_flags & (MDB_TXN_DIRTY|MDB_TXN_SPILLS))) { !(txn->mt_flags & (MDB_TXN_DIRTY|MDB_TXN_SPILLS)))
if ((env->me_flags & MDB_RESIZING)
&& (rc = mdb_env_write_meta(txn))) {
goto fail;
}
goto done; goto done;
}
DPRINTF(("committing txn %"Z"u %p on mdbenv %p, root page %"Z"u", DPRINTF(("committing txn %"Z"u %p on mdbenv %p, root page %"Z"u",
txn->mt_txnid, (void*)txn, (void*)env, txn->mt_dbs[MAIN_DBI].md_root)); txn->mt_txnid, (void*)txn, (void*)env, txn->mt_dbs[MAIN_DBI].md_root));
@ -3324,6 +3315,7 @@ mdb_txn_commit(MDB_txn *txn)
#endif #endif
if ((rc = mdb_page_flush(txn, 0)) || if ((rc = mdb_page_flush(txn, 0)) ||
(rc = mdb_env_sync(env, 0)) ||
(rc = mdb_env_write_meta(txn))) (rc = mdb_env_write_meta(txn)))
goto fail; goto fail;
@ -3480,7 +3472,7 @@ mdb_env_init_meta(MDB_env *env, MDB_meta *meta)
static int static int
mdb_env_write_meta(MDB_txn *txn) mdb_env_write_meta(MDB_txn *txn)
{ {
MDB_env *env = txn->mt_env; MDB_env *env;
MDB_meta meta, metab, *mp; MDB_meta meta, metab, *mp;
off_t off; off_t off;
int rc, len, toggle; int rc, len, toggle;
@ -3492,22 +3484,17 @@ mdb_env_write_meta(MDB_txn *txn)
int r2; int r2;
#endif #endif
/* Sync data and previous metapage before writing a new metapage */
if ((rc = mdb_env_sync(env, 0)) != MDB_SUCCESS)
return rc;
toggle = txn->mt_txnid & 1; toggle = txn->mt_txnid & 1;
DPRINTF(("writing meta page %d for root page %"Z"u", DPRINTF(("writing meta page %d for root page %"Z"u",
toggle, txn->mt_dbs[MAIN_DBI].md_root)); toggle, txn->mt_dbs[MAIN_DBI].md_root));
env = txn->mt_env;
mp = env->me_metas[toggle]; mp = env->me_metas[toggle];
if (env->me_flags & MDB_WRITEMAP) { if (env->me_flags & MDB_WRITEMAP) {
/* Persist any changes of mapsize config */ /* Persist any increases of mapsize config */
if (env->me_flags & MDB_RESIZING) { if (env->me_mapsize > mp->mm_mapsize)
mp->mm_mapsize = env->me_mapsize; mp->mm_mapsize = env->me_mapsize;
env->me_flags ^= MDB_RESIZING;
}
mp->mm_dbs[0] = txn->mt_dbs[0]; mp->mm_dbs[0] = txn->mt_dbs[0];
mp->mm_dbs[1] = txn->mt_dbs[1]; mp->mm_dbs[1] = txn->mt_dbs[1];
mp->mm_last_pg = txn->mt_next_pgno - 1; mp->mm_last_pg = txn->mt_next_pgno - 1;
@ -3535,11 +3522,10 @@ mdb_env_write_meta(MDB_txn *txn)
metab.mm_last_pg = env->me_metas[toggle]->mm_last_pg; metab.mm_last_pg = env->me_metas[toggle]->mm_last_pg;
ptr = (char *)&meta; ptr = (char *)&meta;
if (env->me_flags & MDB_RESIZING) { if (env->me_mapsize > mp->mm_mapsize) {
/* Persist any changes of mapsize config */ /* Persist any increases of mapsize config */
meta.mm_mapsize = env->me_mapsize; meta.mm_mapsize = env->me_mapsize;
off = offsetof(MDB_meta, mm_mapsize); off = offsetof(MDB_meta, mm_mapsize);
env->me_flags ^= MDB_RESIZING;
} else { } else {
off = offsetof(MDB_meta, mm_dbs[0].md_depth); off = offsetof(MDB_meta, mm_dbs[0].md_depth);
} }
@ -3728,14 +3714,13 @@ mdb_env_set_mapsize(MDB_env *env, size_t size)
* sure there are no active txns. * sure there are no active txns.
*/ */
if (env->me_map) { if (env->me_map) {
int rc, change = 0; int rc;
void *old; void *old;
if (env->me_txn) if (env->me_txn)
return EINVAL; return EINVAL;
if (!size) if (!size)
size = env->me_metas[mdb_env_pick_meta(env)]->mm_mapsize; size = env->me_metas[mdb_env_pick_meta(env)]->mm_mapsize;
else { else if (size < env->me_mapsize) {
if (size < env->me_mapsize) {
/* If the configured size is smaller, make sure it's /* If the configured size is smaller, make sure it's
* still big enough. Silently round up to minimum if not. * still big enough. Silently round up to minimum if not.
*/ */
@ -3743,19 +3728,12 @@ mdb_env_set_mapsize(MDB_env *env, size_t size)
if (size < minsize) if (size < minsize)
size = minsize; size = minsize;
} }
/* nothing actually changed */
if (size == env->me_mapsize)
return MDB_SUCCESS;
change = 1;
}
munmap(env->me_map, env->me_mapsize); munmap(env->me_map, env->me_mapsize);
env->me_mapsize = size; env->me_mapsize = size;
old = (env->me_flags & MDB_FIXEDMAP) ? env->me_map : NULL; old = (env->me_flags & MDB_FIXEDMAP) ? env->me_map : NULL;
rc = mdb_env_map(env, old); rc = mdb_env_map(env, old);
if (rc) if (rc)
return rc; return rc;
if (change)
env->me_flags |= MDB_RESIZING;
} }
env->me_mapsize = size; env->me_mapsize = size;
if (env->me_psize) if (env->me_psize)
@ -3828,8 +3806,7 @@ mdb_env_open2(MDB_env *env)
* else use the size recorded in the existing env. * else use the size recorded in the existing env.
*/ */
env->me_mapsize = newenv ? DEFAULT_MAPSIZE : meta.mm_mapsize; env->me_mapsize = newenv ? DEFAULT_MAPSIZE : meta.mm_mapsize;
} else { } else if (env->me_mapsize < meta.mm_mapsize) {
if (env->me_mapsize < meta.mm_mapsize) {
/* If the configured size is smaller, make sure it's /* If the configured size is smaller, make sure it's
* still big enough. Silently round up to minimum if not. * still big enough. Silently round up to minimum if not.
*/ */
@ -3837,9 +3814,6 @@ mdb_env_open2(MDB_env *env)
if (env->me_mapsize < minsize) if (env->me_mapsize < minsize)
env->me_mapsize = minsize; env->me_mapsize = minsize;
} }
if (env->me_mapsize != meta.mm_mapsize)
env->me_flags |= MDB_RESIZING;
}
rc = mdb_env_map(env, (flags & MDB_FIXEDMAP) ? meta.mm_address : NULL); rc = mdb_env_map(env, (flags & MDB_FIXEDMAP) ? meta.mm_address : NULL);
if (rc) if (rc)

Loading…
Cancel
Save