about summary refs log tree commit
path: root/lib/metropolis/tc/hdb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-11-23 19:45:52 -0800
committerEric Wong <normalperson@yhbt.net>2010-11-23 19:45:52 -0800
commit61120b1268679bb8ffa157736e91e6846fd2a372 (patch)
tree26ca738b3208164e7438599b7f25b3248cf76db8 /lib/metropolis/tc/hdb
parent0f3c1c14630fda58363ffd7d3a942041ca2419eb (diff)
downloadmetropolis-61120b1268679bb8ffa157736e91e6846fd2a372.tar.gz
tc/hdb: add exclusive mode, lock disabling
The :exclusive mode behaves like TokyoTyrant and keeps the
database opened in read-write mode, preventing other processes
from accessing the database.  This will be useful on Rubies
without a GVL.

:readonly no longer disables locking by default
instead "rdlock=false" must be passed in the query
parameter.  Write locks may also be disabled with
the "wrlock=false" query parameter.
Diffstat (limited to 'lib/metropolis/tc/hdb')
-rw-r--r--lib/metropolis/tc/hdb/ex.rb18
-rw-r--r--lib/metropolis/tc/hdb/ro.rb1
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/metropolis/tc/hdb/ex.rb b/lib/metropolis/tc/hdb/ex.rb
new file mode 100644
index 0000000..5bc7f39
--- /dev/null
+++ b/lib/metropolis/tc/hdb/ex.rb
@@ -0,0 +1,18 @@
+module Metropolis::TC::HDB::EX
+  def self.extended(obj)
+   obj.instance_eval do
+      @wr_flags |= @rd_flags
+      @rd_flags = nil
+      @dbv.each { |(hdb, path)|
+        hdb.open(path, @wr_flags) or ex!(:open, hdb)
+      }
+      @ex_dbv = @dbv.map { |(hdb,_)| hdb }
+    end
+  end
+
+  def reader(key)
+    yield @ex_dbv[key.hash % @nr_slots]
+  end
+
+  alias_method :writer, :reader
+end
diff --git a/lib/metropolis/tc/hdb/ro.rb b/lib/metropolis/tc/hdb/ro.rb
index fddd73c..62ededc 100644
--- a/lib/metropolis/tc/hdb/ro.rb
+++ b/lib/metropolis/tc/hdb/ro.rb
@@ -6,7 +6,6 @@ module Metropolis::TC::HDB::RO
   def self.extended(obj)
    obj.instance_eval do
       @wr_flags = nil
-      @rd_flags |= TokyoCabinet::HDB::ONOLCK
       @dbv.each { |(hdb, path)|
         hdb.open(path, @rd_flags) or ex!(:open, hdb)
       }