From f314cd6b922ba4370a51d71adb22c091df1e4d10 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Fri, 15 Jun 2018 02:54:41 +0300 Subject: [PATCH] mdbx: windows - fix truncation race while unmap. Change-Id: I93983d100c78aa3e57c5a7ebd9d5bf2a96081ed7 --- src/mdbx.c | 5 +++++ src/osal.c | 12 +++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/mdbx.c b/src/mdbx.c index e4c5248c..18be2e55 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -2041,6 +2041,11 @@ static int mdbx_mapresize(MDBX_env *env, const pgno_t size_pgno, bailout: if (rc == MDBX_SUCCESS) { +#if defined(_WIN32) || defined(_WIN64) + assert(size_bytes == env->me_dxb_mmap.current); + assert(size_bytes <= env->me_dxb_mmap.filesize); + assert(limit_bytes == env->me_dxb_mmap.length); +#endif env->me_dbgeo.now = size_bytes; env->me_dbgeo.upper = limit_bytes; if (env->me_txn) { diff --git a/src/osal.c b/src/osal.c index f079bb96..6fda36a2 100644 --- a/src/osal.c +++ b/src/osal.c @@ -892,11 +892,6 @@ int mdbx_munmap(mdbx_mmap_t *map) { if (!NT_SUCCESS(rc)) ntstatus2errcode(rc); - if (map->filesize != map->current && - mdbx_filesize(map->fd, &map->filesize) == MDBX_SUCCESS && - map->filesize != map->current) - (void)mdbx_ftruncate(map->fd, map->current); - map->length = 0; map->current = 0; map->address = nullptr; @@ -922,8 +917,11 @@ int mdbx_mresize(int flags, mdbx_mmap_t *map, size_t size, size_t limit) { /* growth rw-section */ SectionSize.QuadPart = size; status = NtExtendSection(map->section, &SectionSize); - if (NT_SUCCESS(status)) - map->filesize = map->current = size; + if (NT_SUCCESS(status)) { + map->current = size; + if (map->filesize < size) + map->filesize = size; + } return ntstatus2errcode(status); }