From 209b56fead1afe8273db6c714c0a74a9c09b9cf6 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Mon, 21 Dec 2015 02:36:20 +0000 Subject: [PATCH] ITS#8324 fix for WRITEMAP We called FlushViewOfFile with (map,mapsize) which worked fine when we had allocated the entire map already. Now we have to make sure to only flush as much as was actually written. Add a numpgs argument to tell how much to flush in env_sync0(). --- libraries/liblmdb/mdb.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index c6a6802e3f..a02ce5c108 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -2643,7 +2643,7 @@ fail: } int -mdb_env_sync(MDB_env *env, int force) +mdb_env_sync0(MDB_env *env, int force, pgno_t numpgs) { int rc = 0; if (env->me_flags & MDB_RDONLY) @@ -2652,7 +2652,7 @@ mdb_env_sync(MDB_env *env, int force) if (env->me_flags & MDB_WRITEMAP) { int flags = ((env->me_flags & MDB_MAPASYNC) && !force) ? MS_ASYNC : MS_SYNC; - if (MDB_MSYNC(env->me_map, env->me_mapsize, flags)) + if (MDB_MSYNC(env->me_map, env->me_psize * numpgs, flags)) rc = ErrCode(); #ifdef _WIN32 else if (flags == MS_SYNC && MDB_FDATASYNC(env->me_fd)) @@ -2672,6 +2672,13 @@ mdb_env_sync(MDB_env *env, int force) return rc; } +int +mdb_env_sync(MDB_env *env, int force) +{ + MDB_meta *m = mdb_env_pick_meta(env); + return mdb_env_sync0(env, force, m->mm_last_pg+1); +} + /** Back up parent txn's cursors, then grab the originals for tracking */ static int mdb_cursor_shadow(MDB_txn *src, MDB_txn *dst) @@ -3813,7 +3820,7 @@ mdb_txn_commit(MDB_txn *txn) if ((rc = mdb_page_flush(txn, 0))) goto fail; if (!F_ISSET(txn->mt_flags, MDB_TXN_NOSYNC) && - (rc = mdb_env_sync(env, 0))) + (rc = mdb_env_sync0(env, 0, txn->mt_next_pgno))) goto fail; if ((rc = mdb_env_write_meta(txn))) goto fail; -- 2.39.5