porpoise 0.9.3 → 0.9.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1bb9742ea2691c9286a6d5c59087aa574220e30a
4
- data.tar.gz: d35d5078dfa2725190f8298030c1d7aa3fcaf186
3
+ metadata.gz: f9c9fb178689e3d75dd5d7a2ddebcca83d20dc56
4
+ data.tar.gz: 749a0a5962cd8f37179f2e2eee29ceb595799bd1
5
5
  SHA512:
6
- metadata.gz: a2fac198b35735804800e2c18e7cc0a9240fe78f2ad93f7300c3d2b9e3ffdfb446a7ea57134651f4cf04d7a4f5d133872590387718ddec1effa294b9dfc7884a
7
- data.tar.gz: 9307bec54ebd9202dfa2a315a9930531b11ebe3562b2e0b98f5b495e9e66f322f6aa05324822f3ed14f1304cba2011ec1c3bd2b6b27d0b3a46c964f4563ccf51
6
+ metadata.gz: 1d55e8404beff9282361c901e822a76051583f88c6448d26a0d3ffd75bd6c20d3b2dafc4f5d29aa9fa550f8fd53dd6c26f904039503c20123ba09ce7281bd25c
7
+ data.tar.gz: '009bbfa5f4e889ba6a73521e7db653a9b1eb0bf3de124e1507cdbf178244cc59dd4dcc968208c8aba78558b272d4be4393ffb0a14e57e5097f42e7c55b96ff4b'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- porpoise (0.9.2)
4
+ porpoise (0.9.3)
5
5
  activerecord (>= 3.2)
6
6
  activesupport (>= 3.2)
7
7
  rails (>= 3.2)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- porpoise (0.9.2)
4
+ porpoise (0.9.3)
5
5
  activerecord (>= 3.2)
6
6
  activesupport (>= 3.2)
7
7
  rails (>= 3.2)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- porpoise (0.9.2)
4
+ porpoise (0.9.3)
5
5
  activerecord (>= 3.2)
6
6
  activesupport (>= 3.2)
7
7
  rails (>= 3.2)
@@ -27,7 +27,9 @@ module ActiveSupport
27
27
 
28
28
  def clear(options = nil)
29
29
  short_mem_reset
30
- Porpoise::KeyValueObject.where(["`key` LIKE ?", "#{@namespace}:%"]).delete_all
30
+ Porpoise::KeyValueObject.retry_lock_error(20) do
31
+ Porpoise::KeyValueObject.where(["`key` LIKE ?", "#{@namespace}:%"]).delete_all
32
+ end
31
33
  end
32
34
 
33
35
  def decrement(name, amount, options = nil)
@@ -97,6 +99,12 @@ module ActiveSupport
97
99
  return val.nil? ? nil : Marshal.load(val)
98
100
  rescue TypeError
99
101
  return val
102
+ rescue ArgumentError => e
103
+ if e.message =~ /marshal data too short/
104
+ return nil
105
+ else
106
+ raise e
107
+ end
100
108
  end
101
109
  end
102
110
 
@@ -110,6 +118,12 @@ module ActiveSupport
110
118
  result[name] = (val.nil? ? nil : Marshal.load(val))
111
119
  rescue TypeError
112
120
  result[name] = val
121
+ rescue ArgumentError => e
122
+ if e.message =~ /marshal data too short/
123
+ return nil
124
+ else
125
+ raise e
126
+ end
113
127
  end
114
128
  end
115
129
  return result
data/lib/porpoise/hash.rb CHANGED
@@ -118,7 +118,7 @@ module Porpoise
118
118
  elsif o.nil?
119
119
  o = Porpoise::KeyValueObject.new(key: key, value: ::Hash.new)
120
120
  elsif o.expired?
121
- o.delete
121
+ Porpoise::KeyValueObject.retry_lock_error(20) { o.delete }
122
122
  o = Porpoise::KeyValueObject.new(key: key, value: ::Hash.new)
123
123
  end
124
124
 
data/lib/porpoise/key.rb CHANGED
@@ -6,7 +6,7 @@ module Porpoise
6
6
  aff = 0
7
7
 
8
8
  unless o.nil?
9
- o.delete
9
+ Porpoise::KeyValueObject.retry_lock_error(20) { o.delete }
10
10
  aff += 1
11
11
  end
12
12
 
@@ -21,7 +21,9 @@ module Porpoise
21
21
 
22
22
  def del_matched(matcher)
23
23
  matcher = Porpoise::key_with_namespace(matcher.gsub("*", "%"))
24
- Porpoise::KeyValueObject.not_expired.where(["`key` LIKE ?", matcher]).delete_all
24
+ Porpoise::KeyValueObject.retry_lock_error(20) do
25
+ Porpoise::KeyValueObject.not_expired.where(["`key` LIKE ?", matcher]).delete_all
26
+ end
25
27
  end
26
28
 
27
29
  def dump(key)
@@ -58,10 +60,13 @@ module Porpoise
58
60
  o = find_stored_object(key, true)
59
61
  no = find_stored_object(newkey)
60
62
 
61
- no.delete unless no.nil?
63
+ unless no.nil?
64
+ Porpoise::KeyValueObject.retry_lock_error(20) { no.delete }
65
+ end
66
+
62
67
  no = o.dup
63
68
  no.key = newkey
64
- o.delete
69
+ Porpoise::KeyValueObject.retry_lock_error(20) { o.delete }
65
70
 
66
71
  no.save
67
72
  end
@@ -103,7 +108,7 @@ module Porpoise
103
108
  if raise_on_not_found && o.nil?
104
109
  raise Porpoise::KeyNotFound.new("Key #{key} could not be found")
105
110
  elsif !o.nil? && o.expired?
106
- o.delete
111
+ Porpoise::KeyValueObject.retry_lock_error(20) { o.delete }
107
112
  o = nil
108
113
  raise Porpoise::KeyNotFound.new("Key #{key} could not be found") if raise_on_not_found
109
114
  end
@@ -20,6 +20,8 @@ class Porpoise::KeyValueObject < ActiveRecord::Base
20
20
  end
21
21
  # :nocov:
22
22
 
23
+ DEADLOCK_RETRY_COUNT = 20
24
+
23
25
  serialize :value
24
26
 
25
27
  if ActiveRecord::VERSION::MAJOR == 3
@@ -33,6 +35,22 @@ class Porpoise::KeyValueObject < ActiveRecord::Base
33
35
 
34
36
  scope :not_expired, -> { where(['(expiration_date IS NOT NULL AND expiration_date > ?) OR expiration_date IS NULL', Time.now]) }
35
37
 
38
+ def self.retry_lock_error(retries = 20, &block)
39
+ begin
40
+ yield
41
+ rescue ActiveRecord::StatementInvalid => e
42
+ if e.message =~ /Deadlock found when trying to get lock/ and (retries.nil? || retries > 0)
43
+ retry_lock_error(retries ? retries - 1 : nil, &block)
44
+ else
45
+ raise e
46
+ end
47
+ rescue ActiveRecord::TransactionIsolationConflict
48
+ if retries.nil? || retries > 0
49
+ retry_lock_error(retries ? retries - 1 : nil, &block)
50
+ end
51
+ end
52
+ end
53
+
36
54
  def expired?
37
55
  !self.expiration_date.nil? && self.expiration_date < Time.now
38
56
  end
data/lib/porpoise/set.rb CHANGED
@@ -183,7 +183,7 @@ module Porpoise
183
183
  elsif o.nil?
184
184
  o = Porpoise::KeyValueObject.new(key: key, value: ::Array.new)
185
185
  elsif o.expired?
186
- o.delete
186
+ Porpoise::KeyValueObject.retry_lock_error(20) { o.delete }
187
187
  o = Porpoise::KeyValueObject.new(key: key, value: ::Array.new)
188
188
  end
189
189
 
@@ -144,7 +144,7 @@ module Porpoise
144
144
  elsif o.nil?
145
145
  o = Porpoise::KeyValueObject.new(key: key, value: ::String.new)
146
146
  elsif o.expired?
147
- o.delete
147
+ Porpoise::KeyValueObject.retry_lock_error(20) { o.delete }
148
148
  o = Porpoise::KeyValueObject.new(key: key, value: ::String.new)
149
149
  end
150
150
 
@@ -1,3 +1,3 @@
1
1
  module Porpoise
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: porpoise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wessel van Heerde
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-30 00:00:00.000000000 Z
11
+ date: 2017-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler