KellyMahan-memcachedb-client 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/lib/memcache_db.rb +17 -2
- data/test/test_mem_cache_db.rb +26 -0
- metadata +1 -1
data/History.txt
CHANGED
data/lib/memcache_db.rb
CHANGED
@@ -17,8 +17,7 @@ class MemCacheDb
|
|
17
17
|
##
|
18
18
|
# The version of MemCacheDb you are using.
|
19
19
|
|
20
|
-
VERSION = '1.
|
21
|
-
|
20
|
+
VERSION = '1.1.1'
|
22
21
|
##
|
23
22
|
# Default options for the cache object.
|
24
23
|
|
@@ -120,6 +119,8 @@ class MemCacheDb
|
|
120
119
|
|
121
120
|
logger.info { "memcachedb-client #{VERSION} #{Array(servers).inspect}" } if logger
|
122
121
|
|
122
|
+
Thread.current[:memcachedb_client] = self.object_id if !@multithread
|
123
|
+
|
123
124
|
self.servers = servers
|
124
125
|
end
|
125
126
|
|
@@ -692,6 +693,8 @@ class MemCacheDb
|
|
692
693
|
# failures (but does still apply to unexpectedly lost connections etc.).
|
693
694
|
|
694
695
|
def with_socket_management(server, &block)
|
696
|
+
check_multithread_status!
|
697
|
+
|
695
698
|
@mutex.lock if @multithread
|
696
699
|
retried = false
|
697
700
|
|
@@ -783,6 +786,18 @@ class MemCacheDb
|
|
783
786
|
((total_servers * Continuum::POINTS_PER_SERVER * server.weight) / Float(total_weight)).floor
|
784
787
|
end
|
785
788
|
|
789
|
+
def check_multithread_status!
|
790
|
+
return if @multithread
|
791
|
+
|
792
|
+
if Thread.current[:memcachedb_client] != self.object_id
|
793
|
+
raise MemCacheDbError, <<-EOM
|
794
|
+
You are accessing this memcachedb-client instance from multiple threads but have not enabled multithread support.
|
795
|
+
Normally: MemCacheDb.new(['localhost:21201'], :multithread => true)
|
796
|
+
In Rails: config.cache_store = [:mem_cache_db_store, 'localhost:21201', { :multithread => true }]
|
797
|
+
EOM
|
798
|
+
end
|
799
|
+
end
|
800
|
+
|
786
801
|
##
|
787
802
|
# This class represents a memcachedb server instance.
|
788
803
|
|
data/test/test_mem_cache_db.rb
CHANGED
@@ -333,6 +333,32 @@ class TestMemCacheDb < Test::Unit::TestCase
|
|
333
333
|
assert !server.alive?
|
334
334
|
end
|
335
335
|
|
336
|
+
def test_multithread_error
|
337
|
+
server = FakeServer.new
|
338
|
+
|
339
|
+
# Write two messages to the socket to test failover
|
340
|
+
server.socket.data.write "bogus response\r\nbogus response\r\n"
|
341
|
+
server.socket.data.rewind
|
342
|
+
|
343
|
+
@cache.servers = []
|
344
|
+
@cache.servers << server
|
345
|
+
|
346
|
+
assert_nothing_raised do
|
347
|
+
@cache.set 'a', 1
|
348
|
+
end
|
349
|
+
|
350
|
+
passed = true
|
351
|
+
Thread.new do
|
352
|
+
begin
|
353
|
+
@cache.set 'b', 2
|
354
|
+
passed = false
|
355
|
+
rescue MemCacheDb::MemCacheError => me
|
356
|
+
passed = me.message =~ /multiple threads/
|
357
|
+
end
|
358
|
+
end
|
359
|
+
assert passed
|
360
|
+
end
|
361
|
+
|
336
362
|
def test_initialize
|
337
363
|
cache = MemCacheDb.new :namespace => 'my_namespace', :readonly => true
|
338
364
|
|