consistent-cluster 1.0.3 → 1.0.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 +4 -4
- data/lib/consistent-cluster/sync-client.rb +80 -35
- data/lib/consistent-cluster/version.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d7447f969567786aef54f72b5c03abfa42bb860
|
4
|
+
data.tar.gz: a6b96f1db23abe63dc2b1411875c0fcb98a2bd4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad96b31d7dd661ca27464b94a8d84d1f7a332cb46d4f423825fbdf0884f1845984537131f02e6839b3a2ded5959acfa1403b85620f7f09babc1b5b4f33c0fb72
|
7
|
+
data.tar.gz: 03abd91418a5a9ddc432fd1448b1dbf3ca71cf93dc93a95fac6a1bdae41bf328753bd0fc17aa925249c8d019eeaa0273848e941f3f1022633f494f022ee5329f
|
@@ -11,6 +11,8 @@ module ConsistentCluster
|
|
11
11
|
|
12
12
|
def initialize(options)
|
13
13
|
|
14
|
+
@syncingMutex = Mutex.new
|
15
|
+
|
14
16
|
@data = {}
|
15
17
|
@cluster = {}
|
16
18
|
@node_register = {}
|
@@ -20,10 +22,19 @@ module ConsistentCluster
|
|
20
22
|
|
21
23
|
@create_proc = options[:create_proc]
|
22
24
|
@destroy_proc = options[:destroy_proc]
|
23
|
-
@after_sync_proc = options[:after_sync_proc]
|
25
|
+
@after_sync_proc = options[:after_sync_proc]
|
26
|
+
@log_proc = options[:log_proc]
|
27
|
+
|
28
|
+
@logger = if options[:log_file]
|
29
|
+
Logger.new(options[:log_file])
|
30
|
+
elsif STDERR || STDOUT
|
31
|
+
Logger.new(STDERR || STDOUT)
|
32
|
+
else
|
33
|
+
Logger.new(options[:nil])
|
34
|
+
end
|
35
|
+
|
36
|
+
@last_sync_at = 0
|
24
37
|
|
25
|
-
@to_sync,@syncing = false,false
|
26
|
-
|
27
38
|
@path = options[:zookeeper_path]
|
28
39
|
|
29
40
|
@zk = ZK.new(options[:zookeeper_service],reconnect: true)
|
@@ -65,47 +76,81 @@ module ConsistentCluster
|
|
65
76
|
server
|
66
77
|
end
|
67
78
|
|
79
|
+
def invoke_sync
|
80
|
+
sync_services
|
81
|
+
end
|
82
|
+
|
83
|
+
def local_version
|
84
|
+
@data
|
85
|
+
end
|
86
|
+
|
87
|
+
def remote_version
|
88
|
+
app_names = get_app_names(watch: false)
|
89
|
+
|
90
|
+
data = {}
|
91
|
+
app_names.each do |app_name|
|
92
|
+
app_content = get_app_content(app_name, watch: false)
|
93
|
+
data[app_name] = app_content
|
94
|
+
end
|
95
|
+
data
|
96
|
+
end
|
97
|
+
|
98
|
+
def zookeeper_path
|
99
|
+
@path
|
100
|
+
end
|
101
|
+
|
102
|
+
def last_sync_at
|
103
|
+
@last_sync_at
|
104
|
+
end
|
105
|
+
|
68
106
|
protected
|
69
107
|
|
70
108
|
def sync_services
|
71
|
-
@
|
72
|
-
if !@syncing
|
109
|
+
@syncingMutex.synchronize do
|
73
110
|
syncing_process
|
74
111
|
end
|
75
112
|
end
|
76
113
|
|
77
114
|
def syncing_process
|
78
|
-
|
79
|
-
|
80
|
-
@to_sync = false
|
81
|
-
app_names = get_app_names
|
82
|
-
current_app_names = @cluster.keys
|
83
|
-
|
84
|
-
to_update = current_app_names&app_names
|
85
|
-
to_create = app_names - current_app_names
|
86
|
-
to_destroy = current_app_names - app_names
|
87
|
-
|
88
|
-
to_update.each do |app_name|
|
89
|
-
update_service(app_name)
|
90
|
-
end
|
115
|
+
app_names = get_app_names
|
116
|
+
current_app_names = @cluster.keys
|
91
117
|
|
92
|
-
|
93
|
-
|
94
|
-
|
118
|
+
to_update = current_app_names&app_names
|
119
|
+
to_create = app_names - current_app_names
|
120
|
+
to_destroy = current_app_names - app_names
|
95
121
|
|
96
|
-
|
97
|
-
|
98
|
-
|
122
|
+
to_update.each do |app_name|
|
123
|
+
update_service(app_name)
|
124
|
+
end
|
125
|
+
|
126
|
+
to_create.each do |app_name|
|
127
|
+
create_service(app_name)
|
128
|
+
end
|
129
|
+
|
130
|
+
to_destroy.each do |app_name|
|
131
|
+
destroy_service(app_name)
|
99
132
|
end
|
100
|
-
|
101
|
-
|
133
|
+
|
134
|
+
@last_sync_at = Time.now.to_i
|
135
|
+
|
136
|
+
if @after_sync_proc || @log_proc
|
102
137
|
clone_data = Marshal.load(Marshal.dump(@data)) #avoid change outside
|
103
|
-
|
138
|
+
|
139
|
+
if @after_sync_proc
|
140
|
+
@after_sync_proc.call(clone_data)
|
141
|
+
end
|
142
|
+
|
143
|
+
if @log_proc
|
144
|
+
debugInfo = @log_proc.call(@data).to_s
|
145
|
+
if debugInfo != ""
|
146
|
+
@logger.info debugInfo
|
147
|
+
end
|
148
|
+
end
|
104
149
|
end
|
105
150
|
end
|
106
151
|
|
107
|
-
def get_app_names
|
108
|
-
@zk.children(@path, watch:
|
152
|
+
def get_app_names(options = {watch: true})
|
153
|
+
@zk.children(@path, watch: options[:watch])
|
109
154
|
end
|
110
155
|
|
111
156
|
def create_service(app_name)
|
@@ -130,7 +175,7 @@ module ConsistentCluster
|
|
130
175
|
end
|
131
176
|
|
132
177
|
rescue Exception => boom
|
133
|
-
|
178
|
+
@logger.error "syncClientError when create :#{app_name} raise #{boom.class} - #{boom.message}"
|
134
179
|
end
|
135
180
|
|
136
181
|
def destroy_service(app_name)
|
@@ -151,7 +196,7 @@ module ConsistentCluster
|
|
151
196
|
end
|
152
197
|
|
153
198
|
rescue Exception => boom
|
154
|
-
|
199
|
+
@logger.error "syncClientError when destroy :#{app_name} raise #{boom.class} - #{boom.message}"
|
155
200
|
end
|
156
201
|
|
157
202
|
def update_service(app_name)
|
@@ -166,15 +211,15 @@ module ConsistentCluster
|
|
166
211
|
create_service(app_name)
|
167
212
|
end
|
168
213
|
rescue Exception => boom
|
169
|
-
|
214
|
+
@logger.error "syncClientError when update :#{app_name} raise #{boom.class} - #{boom.message}"
|
170
215
|
end
|
171
216
|
|
172
|
-
def get_app_content(app_name)
|
217
|
+
def get_app_content(app_name, options={watch: true})
|
173
218
|
app_path = "#{@path}/#{app_name}"
|
174
|
-
content = @zk.get(app_path, watch:
|
219
|
+
content = @zk.get(app_path, watch: options[:watch]).first
|
175
220
|
content
|
176
221
|
end
|
177
222
|
|
178
223
|
end
|
179
224
|
|
180
|
-
end
|
225
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module ConsistentCluster
|
2
|
-
Version = "1.0.
|
3
|
-
end
|
2
|
+
Version = "1.0.4"
|
3
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consistent-cluster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jeffrey6052
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: atomic
|
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
62
|
version: '0'
|
63
63
|
requirements: []
|
64
64
|
rubyforge_project:
|
65
|
-
rubygems_version: 2.
|
65
|
+
rubygems_version: 2.5.1
|
66
66
|
signing_key:
|
67
67
|
specification_version: 4
|
68
68
|
summary: 一致性哈希集群
|