railhead_handlersocket 0.0.1 → 0.0.2
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/lib/railhead_handlersocket.rb +55 -19
- data/railhead_handlersocket.gemspec +3 -3
- metadata +7 -7
@@ -42,15 +42,27 @@ class HandlerSocket
|
|
42
42
|
result
|
43
43
|
end
|
44
44
|
end
|
45
|
+
|
46
|
+
def execute_delete_with_error(*args)
|
47
|
+
result = execute_delete(*args)
|
48
|
+
if result.nil?
|
49
|
+
raise HandlerSocketError, 'nil returned (execute delete)'
|
50
|
+
elsif result[0] != 0
|
51
|
+
raise HandlerSocketError, result[1]
|
52
|
+
else
|
53
|
+
result
|
54
|
+
end
|
55
|
+
end
|
45
56
|
end
|
46
57
|
|
47
58
|
|
48
59
|
class ActiveRecord::Base
|
49
60
|
|
50
|
-
def self.use_handlersocket(host = '127.0.0.1', port =
|
61
|
+
def self.use_handlersocket(host = '127.0.0.1', port = 9999)
|
51
62
|
@@hs = HandlerSocket.new(host, port)
|
52
63
|
@@hs_db_name = connection.instance_variable_get(:@config)[:database]
|
53
64
|
@@hs_indexes = {}
|
65
|
+
alias_method_chain :destroy, :handlersocket
|
54
66
|
|
55
67
|
class << self
|
56
68
|
alias_method_chain :find_one, :handlersocket
|
@@ -63,16 +75,39 @@ class ActiveRecord::Base
|
|
63
75
|
def self.reconnect_handlersocket
|
64
76
|
@@hs.reconnect
|
65
77
|
@@hs_indexes = {}
|
66
|
-
|
78
|
+
end
|
79
|
+
|
80
|
+
def destroy_with_handlersocket
|
81
|
+
begin
|
82
|
+
self.class.del_through_handlersocket(self.id) unless new_record?
|
83
|
+
@destroyed = true
|
84
|
+
freeze
|
85
|
+
rescue
|
86
|
+
destroy_without_handlersocket
|
87
|
+
end
|
67
88
|
end
|
68
89
|
|
69
90
|
class << self
|
70
91
|
|
71
92
|
def open_index(index_name)
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
93
|
+
hs_reconnected = false
|
94
|
+
begin
|
95
|
+
unless index = @@hs_indexes["#{@@hs_db_name}.#{table_name} #{index_name}"]
|
96
|
+
index = @@hs_indexes.size
|
97
|
+
logger.debug "HS: open index #{@@hs_db_name}.#{table_name} #{index_name}"
|
98
|
+
@@hs.open_index_with_error(index, @@hs_db_name, table_name, index_name, column_names.join(','))
|
99
|
+
@@hs_indexes["#{@@hs_db_name}.#{table_name} #{index_name}"] = index
|
100
|
+
end
|
101
|
+
rescue HandlerSocket::HandlerSocketError => e
|
102
|
+
unless hs_reconnected
|
103
|
+
logger.info "HS: reconnecting"
|
104
|
+
hs_reconnected = true
|
105
|
+
ActiveRecord::Base.reconnect_handlersocket
|
106
|
+
retry
|
107
|
+
else
|
108
|
+
logger.info "HS: reconnection failed"
|
109
|
+
raise e
|
110
|
+
end
|
76
111
|
end
|
77
112
|
index
|
78
113
|
end
|
@@ -87,19 +122,7 @@ class ActiveRecord::Base
|
|
87
122
|
|
88
123
|
def get_through_handlersocket(ids, index_name = 'PRIMARY')
|
89
124
|
unless ids.nil?
|
90
|
-
|
91
|
-
begin
|
92
|
-
index = open_index(index_name)
|
93
|
-
rescue HandlerSocket::HandlerSocketError => e
|
94
|
-
unless @hs_reconnected
|
95
|
-
logger.info "HS: reconnecting"
|
96
|
-
ActiveRecord::Base.reconnect_handlersocket
|
97
|
-
retry
|
98
|
-
else
|
99
|
-
logger.info "HS: reconnection failed"
|
100
|
-
raise e
|
101
|
-
end
|
102
|
-
end
|
125
|
+
index = open_index(index_name)
|
103
126
|
begin
|
104
127
|
logger.debug "HS: #{@@hs_db_name}.#{table_name} #{index_name} #{ids.inspect}"
|
105
128
|
if ids.is_a?(Array)
|
@@ -114,6 +137,19 @@ class ActiveRecord::Base
|
|
114
137
|
end
|
115
138
|
end
|
116
139
|
|
140
|
+
def del_through_handlersocket(id, index_name = 'PRIMARY')
|
141
|
+
unless id.nil?
|
142
|
+
index = open_index(index_name)
|
143
|
+
begin
|
144
|
+
logger.debug "HS: #{@@hs_db_name}.#{table_name} #{index_name} DELETE #{id}"
|
145
|
+
@@hs.execute_delete_with_error(index, '=', [id], 1, 0)
|
146
|
+
rescue HandlerSocket::HandlerSocketError => e
|
147
|
+
logger.debug "HS: delete failed - #{e.message}"
|
148
|
+
raise e
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
117
153
|
def find_one_with_handlersocket(ids, options = {})
|
118
154
|
get_through_handlersocket(ids) rescue find_one_without_handlersocket(ids, options)
|
119
155
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "railhead_handlersocket"
|
3
|
-
s.version = "0.0.
|
4
|
-
s.date = "2011-
|
5
|
-
s.summary = "Hacks for ActiveRecord 2.x to working with HandlerSocket.
|
3
|
+
s.version = "0.0.2"
|
4
|
+
s.date = "2011-06-10"
|
5
|
+
s.summary = "Hacks for ActiveRecord 2.x to working with HandlerSocket."
|
6
6
|
s.email = "nagybence@tipogral.hu"
|
7
7
|
s.homepage = "http://github.com/nagybence/railhead_cacheify"
|
8
8
|
s.description = "Hacks for ActiveRecord 2.x to working with HandlerSocket."
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: railhead_handlersocket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bence Nagy
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-06-10 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -64,9 +64,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
requirements: []
|
65
65
|
|
66
66
|
rubyforge_project:
|
67
|
-
rubygems_version: 1.
|
67
|
+
rubygems_version: 1.3.7
|
68
68
|
signing_key:
|
69
69
|
specification_version: 3
|
70
|
-
summary: Hacks for ActiveRecord 2.x to working with HandlerSocket.
|
70
|
+
summary: Hacks for ActiveRecord 2.x to working with HandlerSocket.
|
71
71
|
test_files: []
|
72
72
|
|