Diff

mod_storage_lmdb/mod_storage_lmdb.lua @ 1983:f7fc5088b340

mod_storage_lmdb: Allow passing a transaction flag so we can run get operations in a read-only transaction
author Kim Alvefur <zash@zash.se>
date Sat, 19 Dec 2015 00:34:55 +0100
parent 1982:bb0b2eae5563
child 1984:2ed6f6eeeaba
line wrap: on
line diff
--- a/mod_storage_lmdb/mod_storage_lmdb.lua	Sat Dec 19 00:25:30 2015 +0100
+++ b/mod_storage_lmdb/mod_storage_lmdb.lua	Sat Dec 19 00:34:55 2015 +0100
@@ -20,9 +20,9 @@
 local serialize = serialization.serialize;
 local deserialize = serialization.deserialize;
 
-local function transaction(env, func, ...)
+local function transaction(env, flag, func, ...)
 	local args, n_args = {...}, select("#", ...);
-	local t = env:txn_begin(nil, 0);
+	local t = env:txn_begin(nil, flag);
 	local function f() return func(t, unpack(args, 1, n_args)); end
 	local success, a, b, c = xpcall(f, traceback);
 	if not success then
@@ -66,11 +66,11 @@
 	if value ~= nil then
 		value = serialize(value);
 	end
-	return transaction(self.env, keyvalue_set, self.db, key, value);
+	return transaction(self.env, 0, keyvalue_set, self.db, key, value);
 end
 
 function keyval:get(key)
-	local ok, data = transaction(self.env, keyvalue_get, self.db, key);
+	local ok, data = transaction(self.env, lmdb.MDB_RDONLY, keyvalue_get, self.db, key);
 	if not ok then return ok, data; end
 	return deserialize(data);
 end