Class: LS4::MembershipManagerService

Inherits:
MembershipService show all
Defined in:
lib/ls4/service/membership.rb

Direct Known Subclasses

StandaloneMembershipService

Instance Method Summary collapse

Methods inherited from MembershipService

#get_active_rsids, #get_all_nodes, #get_node, #get_session_nid, #is_fault, #shutdown, #stat_fault_info, #stat_membership_info, #stat_replset_info

Methods inherited from Service

init

Methods included from EventBus::SingletonMixin

#ebus_bind!, #ebus_connect, extended

Methods included from EventBus::BusMixin

#ebus_all_slots, #ebus_disconnect!

Methods included from EventBus::DeclarerBase::Methods

#connect, #ebus_all_slots, #ebus_call_log, #ebus_call_slots, #ebus_signal_error, #ebus_signal_log, #ebus_signal_slots

Methods included from EventBus::DeclarerBase

#call_slot, #signal_slot

Constructor Details

#initializeMembershipManagerService

Returns a new instance of MembershipManagerService.



131
132
133
134
# File 'lib/ls4/service/membership.rb', line 131

def initialize
	super
	@fault_detector = FaultDetector.new
end

Instance Method Details

#on_fault_detector_changeObject



216
217
218
219
# File 'lib/ls4/service/membership.rb', line 216

def on_fault_detector_change
	@fault_list.update(@fault_detector.get_fault_nids)
	on_fault_list_change
end

#on_fault_list_changeObject



221
222
223
224
225
# File 'lib/ls4/service/membership.rb', line 221

def on_fault_list_change
	SyncBus.update(SYNC_FAULT_LIST,
						@fault_list, @fault_list.get_hash)
	super
end

#on_membership_changeObject



210
211
212
213
214
# File 'lib/ls4/service/membership.rb', line 210

def on_membership_change
	SyncBus.update(SYNC_MEMBERSHIP,
						@membership, @membership.get_hash)
	super
end

#on_timerObject



189
190
191
192
193
194
195
# File 'lib/ls4/service/membership.rb', line 189

def on_timer
	fault_nids = @fault_detector.forward_timer
	if !fault_nids.empty?
		$log.info "fault detected: #{fault_nids.join(', ')}"
		on_fault_detector_change
	end
end

#reset_fault_detector(nid) ⇒ Object



184
185
186
187
# File 'lib/ls4/service/membership.rb', line 184

def reset_fault_detector(nid)
	term = @fault_detector.update(nid)
	term
end

#rpc_add_node(nid, address, name, rsids, location) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/ls4/service/membership.rb', line 145

def rpc_add_node(nid, address, name, rsids, location)
	if @membership.include?(nid)
		if @membership.update_node_info(nid, address, name, rsids, location)
			$log.info "update node: nid=#{nid} name=#{name.dump} address=#{address} rsids=#{rsids.join(',')}"
		end
	else
		@membership.add_node(nid, address, name, rsids, location)
		$log.info "add node: nid=#{nid} name=#{name.dump} address=#{address} rsids=#{rsids.join(',')}"
	end
	@fault_detector.set_nid(nid)
	on_membership_change
	on_fault_detector_change
	true
end

#rpc_recover_node(nid) ⇒ Object



175
176
177
178
179
180
181
182
# File 'lib/ls4/service/membership.rb', line 175

def rpc_recover_node(nid)
	if @fault_detector.reset(nid)
		on_fault_detector_change
		true
	else
		nil
	end
end

#rpc_remove_node(nid) ⇒ Object



160
161
162
163
164
165
166
167
# File 'lib/ls4/service/membership.rb', line 160

def rpc_remove_node(nid)
	$log.info "remove node: nid=#{nid}"
	@membership.remove_node(nid)
	@fault_detector.delete_nid(nid)
	on_membership_change
	on_fault_detector_change
	true
end

#rpc_update_node_info(nid, address, name, rsids) ⇒ Object



169
170
171
172
173
# File 'lib/ls4/service/membership.rb', line 169

def rpc_update_node_info(nid, address, name, rsids)
	@membership.update_node_info(nid, address, name, rsids)
	on_membership_change
	true
end

#runObject



136
137
138
139
140
141
142
143
# File 'lib/ls4/service/membership.rb', line 136

def run
	super
	@fault_detector.set_init(
		@membership.get_all_nids,
		@fault_list.get_list)
	on_membership_change
	on_fault_detector_change
end