about summary refs log tree commit
path: root/lib/metropolis/tc
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-10 19:49:12 -0800
committerEric Wong <normalperson@yhbt.net>2010-12-10 19:49:12 -0800
commit5d6dc5c742f827350490d8f33c4c89b203ae7460 (patch)
tree9fc79f0ead7a407f7a7c636a92ed372870e5565a /lib/metropolis/tc
parent8791d27f34d618bc7979b56da7e068b79a79b229 (diff)
downloadmetropolis-5d6dc5c742f827350490d8f33c4c89b203ae7460.tar.gz
String#hash is not stable across processes :<
We need to implement our own hash functions for splitting
databases across multiple files.  This was totally fucking up
Rainbows!
Diffstat (limited to 'lib/metropolis/tc')
-rw-r--r--lib/metropolis/tc/hdb.rb6
-rw-r--r--lib/metropolis/tc/hdb/ex.rb2
-rw-r--r--lib/metropolis/tc/hdb/ro.rb2
3 files changed, 6 insertions, 4 deletions
diff --git a/lib/metropolis/tc/hdb.rb b/lib/metropolis/tc/hdb.rb
index d0833f8..e63b015 100644
--- a/lib/metropolis/tc/hdb.rb
+++ b/lib/metropolis/tc/hdb.rb
@@ -68,6 +68,8 @@ module Metropolis::TC::HDB
       end
       [ hdb, path ]
     end
+    @multi_hash ||= :digest_sha1
+    extend Metropolis::MultiHash
     extend(RO) if @readonly
     extend(EX) if @exclusive
   end
@@ -77,7 +79,7 @@ module Metropolis::TC::HDB
   end
 
   def writer(key, &block)
-    hdb, path = @dbv[key.hash % @nr_slots]
+    hdb, path = @dbv[multi_hash(key) % @nr_slots]
     hdb.open(path, @wr_flags) or ex!(:open, hdb)
     yield hdb
     ensure
@@ -85,7 +87,7 @@ module Metropolis::TC::HDB
   end
 
   def reader(key)
-    hdb, path = @dbv[key.hash % @nr_slots]
+    hdb, path = @dbv[multi_hash(key) % @nr_slots]
     hdb.open(path, @rd_flags) or ex!(:open, hdb)
     yield hdb
     ensure
diff --git a/lib/metropolis/tc/hdb/ex.rb b/lib/metropolis/tc/hdb/ex.rb
index 5bc7f39..d205a76 100644
--- a/lib/metropolis/tc/hdb/ex.rb
+++ b/lib/metropolis/tc/hdb/ex.rb
@@ -11,7 +11,7 @@ module Metropolis::TC::HDB::EX
   end
 
   def reader(key)
-    yield @ex_dbv[key.hash % @nr_slots]
+    yield @ex_dbv[multi_hash(key) % @nr_slots]
   end
 
   alias_method :writer, :reader
diff --git a/lib/metropolis/tc/hdb/ro.rb b/lib/metropolis/tc/hdb/ro.rb
index 62ededc..72fa968 100644
--- a/lib/metropolis/tc/hdb/ro.rb
+++ b/lib/metropolis/tc/hdb/ro.rb
@@ -14,6 +14,6 @@ module Metropolis::TC::HDB::RO
   end
 
   def reader(key)
-    yield @ro_dbv[key.hash % @nr_slots]
+    yield @ro_dbv[multi_hash(key) % @nr_slots]
   end
 end