#include "lmdbbackend.hh"
+#define SCHEMAVERSION 1
+
LMDBBackend::LMDBBackend(const std::string& suffix)
{
setArgPrefix("lmdb"+suffix);
auto pdnsdbi = d_tdomains->getEnv()->openDB("pdns", MDB_CREATE);
auto txn = d_tdomains->getEnv()->getRWTransaction();
+ MDBOutVal _schemaversion;
+ if(!txn.get(pdnsdbi, "schemaversion", _schemaversion)) {
+ auto schemaversion = _schemaversion.get<uint32_t>();
+ if (schemaversion != SCHEMAVERSION) {
+ throw std::runtime_error("Expected LMDB schema version "+std::to_string(SCHEMAVERSION)+" but got "+std::to_string(schemaversion));
+ }
+ }
+ else {
+ txn.put(pdnsdbi, "schemaversion", SCHEMAVERSION);
+ }
MDBOutVal shards;
if(!txn.get(pdnsdbi, "shards", shards)) {
else {
d_shards = atoi(getArg("shards").c_str());
txn.put(pdnsdbi, "shards", d_shards);
- txn.commit();
}
- d_trecords.resize(d_shards);
+ txn.commit();
+ d_trecords.resize(d_shards);
d_dolog = ::arg().mustDo("query-logging");
}