Full_Name: Hallvard B Furuseth Version: lmdb 0.9.14 OS: URL: Submission from: (NULL) (81.191.45.22) Submitted by: hallvard
mdb_env_sync() works with MDB_RDONLY at least on Unix, but it syncs MDB_WRITEMAP changes incorrectly: fdatasync instead of msync because mdb_env_open() cleared MDB_WRITEMAP.
Users are likely doing the same thing anyway: Using MDB_RDONLY instead of MDB_RDONLY|MDB_WRITEMAP on WRITEMAP-written DBs.
Finally, writers committing with and without WRITEMAP will sync each others' commits incorrectly. lmdb.h does warn they will "not cooperate well", but it should warn it breaks ACID.
LMDBv2 can instead fix all this with 2 bits in MDB_meta: "Changed with/without WRITEMAP since last sync".
In LMDBv1, I think the smallest-impact fix is for env_sync to both msync and fdatasync when RDONLY is set and WRITEMAP is clear. A greedier fix would be to always sync both ways when the user calls env_sync.
Either way, it may be best to keep WRITEMAP when RDONLY. Only env_map() needs to deal with that.
Pushing suggestions except doc to "mdb/wmap-fix" in my repo.