From bc62b22ae489996f2efe94ad21626b25375be42e Mon Sep 17 00:00:00 2001 From: Doug Hoyte Date: Fri, 7 May 2021 14:32:35 -0400 Subject: [PATCH] fix test suite on openbsd, document openbsd limitations fixes #6 --- README.md | 13 +++++++++++++ check.cc | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0868844..11fa3ab 100644 --- a/README.md +++ b/README.md @@ -329,6 +329,19 @@ possible LMDB error conditions: * `MDB_KEYEXIST` and `MDB_NOTFOUND` are handled specially by some functions. + +## OpenBSD + +OpenBSD is only partially supported by LMDB. The issue is that OpenBSD does not have a unified buffer cache. This means that modifications made to a file through `write()` will not be visible to processes that have memory mapped the file. This is something that [may be fixed some day](http://openbsd-archive.7691.n7.nabble.com/Will-mmap-and-the-read-buffer-cache-be-unified-anyone-working-with-it-td271270.html). + +In the mean-time, on OpenBSD you should always open environments with the `MDB_WRITEMAP` flag: + + env.open("/path/to/db/", MDB_WRITEMAP); + +Because nested transactions are incompatible with `MDB_WRITEMAP`, they cannot be used on OpenBSD. The test suite disables the nested transaction tests on OpenBSD. + + + ## Support To report a bug or submit a patch for lmdb++, please file an issue in the [issue tracker on GitHub](https://github.com/hoytech/lmdbxx/issues). diff --git a/check.cc b/check.cc index 333a9c2..43245f3 100644 --- a/check.cc +++ b/check.cc @@ -7,12 +7,19 @@ int main() { + unsigned int envFlags = 0; + +#ifdef __OpenBSD__ + envFlags = MDB_WRITEMAP; +#endif + + std::string longLivedValue; try { auto env = lmdb::env::create(); env.set_max_dbs(64); - env.open("testdb/"); + env.open("testdb/", envFlags); lmdb::dbi mydb; lmdb::dbi mydbdups; @@ -250,6 +257,8 @@ int main() { // Nested transactions + // These tests will fail when WRITEMAP enabled, which must be done on OpenBSD +#ifndef __OpenBSD__ { auto txn = lmdb::txn::begin(env); @@ -332,6 +341,7 @@ int main() { if (!caught) throw std::runtime_error("bad nested tx 5"); } +#endif @@ -374,7 +384,7 @@ int main() { auto env = lmdb::env::create(); env.set_max_dbs(64); env.set_mapsize(30000); - env.open("testdb/"); + env.open("testdb/", envFlags); lmdb::dbi mydb;