@@ -1239,7 +1239,7 @@ typedef struct MDB_pgstate {
1239
1239
struct MDB_env {
1240
1240
HANDLE me_fd ; /**< The main data file */
1241
1241
HANDLE me_lfd ; /**< The lock file */
1242
- HANDLE me_mfd ; /**< just for writing the meta pages */
1242
+ HANDLE me_mfd ; /**< For writing and syncing the meta pages */
1243
1243
/** Failed to update the meta page. Probably an I/O error. */
1244
1244
#define MDB_FATAL_ERROR 0x80000000U
1245
1245
/** Some fields are initialized. */
@@ -3827,7 +3827,10 @@ mdb_env_write_meta(MDB_txn *txn)
3827
3827
len = sizeof (MDB_meta ) - off ;
3828
3828
off += (char * )mp - env -> me_map ;
3829
3829
3830
- /* Write to the SYNC fd */
3830
+ /* Write to the SYNC fd unless MDB_NOSYNC/MDB_NOMETASYNC.
3831
+ * (me_mfd goes to the same file as me_fd, but writing to it
3832
+ * also syncs to disk. Avoids a separate fdatasync() call.)
3833
+ */
3831
3834
mfd = (flags & (MDB_NOSYNC |MDB_NOMETASYNC )) ? env -> me_fd : env -> me_mfd ;
3832
3835
#ifdef _WIN32
3833
3836
{
@@ -4156,7 +4159,7 @@ enum mdb_fopen_type {
4156
4159
/* A comment in mdb_fopen() explains some O_* flag choices. */
4157
4160
MDB_O_RDONLY = O_RDONLY , /**< for RDONLY me_fd */
4158
4161
MDB_O_RDWR = O_RDWR |O_CREAT , /**< for me_fd */
4159
- MDB_O_META = O_RDWR |MDB_DSYNC |MDB_CLOEXEC , /**< for me_mfd */
4162
+ MDB_O_META = O_WRONLY |MDB_DSYNC |MDB_CLOEXEC , /**< for me_mfd */
4160
4163
MDB_O_COPY = O_WRONLY |O_CREAT |O_EXCL |MDB_CLOEXEC , /**< for #mdb_env_copy() */
4161
4164
/** Bitmask for open() flags in enum #mdb_fopen_type. The other bits
4162
4165
* distinguish otherwise-equal MDB_O_* constants from each other.
@@ -4217,6 +4220,7 @@ mdb_fopen(const MDB_env *env, MDB_name *fname,
4217
4220
disp = OPEN_EXISTING ;
4218
4221
break ;
4219
4222
case MDB_O_META : /* for writing metapages */
4223
+ acc = GENERIC_WRITE ;
4220
4224
disp = OPEN_EXISTING ;
4221
4225
attrs = FILE_ATTRIBUTE_NORMAL |FILE_FLAG_WRITE_THROUGH ;
4222
4226
break ;
@@ -4955,9 +4959,7 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode
4955
4959
}
4956
4960
4957
4961
if ((rc = mdb_env_open2 (env )) == MDB_SUCCESS ) {
4958
- if (flags & (MDB_RDONLY |MDB_WRITEMAP )) {
4959
- env -> me_mfd = env -> me_fd ;
4960
- } else {
4962
+ if (!(flags & (MDB_RDONLY |MDB_WRITEMAP ))) {
4961
4963
/* Synchronous fd for meta writes. Needed even with
4962
4964
* MDB_NOSYNC/MDB_NOMETASYNC, in case these get reset.
4963
4965
*/
@@ -5040,7 +5042,7 @@ mdb_env_close0(MDB_env *env, int excl)
5040
5042
if (env -> me_map ) {
5041
5043
munmap (env -> me_map , env -> me_mapsize );
5042
5044
}
5043
- if (env -> me_mfd != env -> me_fd && env -> me_mfd != INVALID_HANDLE_VALUE )
5045
+ if (env -> me_mfd != INVALID_HANDLE_VALUE )
5044
5046
(void ) close (env -> me_mfd );
5045
5047
if (env -> me_fd != INVALID_HANDLE_VALUE )
5046
5048
(void ) close (env -> me_fd );
0 commit comments