KellyMahan-memcachedb-client 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ = 1.1.1
2
+
3
+ merged changes from memcache-client 1.6.4
4
+
5
+ "Add runtime check for unsafe multithreaded usage, to ward off bug reports."
6
+
1
7
  = 1.1
2
8
 
3
9
  added get_range method.
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.0.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
 
@@ -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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: KellyMahan-memcachedb-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Mahan