}
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)
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))
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)
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;