Class: Corosync::Votequorum
- Inherits:
-
Object
- Object
- Corosync::Votequorum
- Defined in:
- lib/corosync/votequorum.rb
Overview
Votequorum is used for tracking the health of the cluster. This monitors the quorum state as configured. Whenever the node gains or loses quorum, a notification callback is called. You can also poll the quorum state instead of using a callback.
Instance Attribute Summary collapse
-
#fd ⇒ IO
readonly
The IO object containing the file descriptor notifications come across.
Instance Method Summary collapse
-
#connect(start = false) ⇒ void
Connect to the Votequorum service.
-
#dispatch(timeout = -1)) ⇒ Boolean
Checks for a single pending event and triggers the appropriate callback if found.
-
#finalize ⇒ void
Shuts down the connection to the Quorum service.
-
#info(node_id = 0) ⇒ OpenStruct
Get the votequorum info about a node.
-
#initialize(connect = false) ⇒ void
constructor
Creates a new Votequorum instance.
-
#on_expectedvotes_notify(&block) {|expected_votes| ... } ⇒ void
Proc to call when the number of expected votes changes.
-
#on_notify(&block) {|quorate, nodes| ... } ⇒ void
Proc to call when quorum state changes.
-
#quorate? ⇒ Boolean
Get whether this node is quorate or not Shorthand for #info.flags.include?(:quorate).
-
#set_expected(count) ⇒ void
(also: #expected=)
Set the number of expected votes for this node.
-
#set_votes(count, node_id = 0) ⇒ void
Set the number of votes contributed by the specified node.
-
#start(initial_callback = false) ⇒ Boolean
Start monitoring for changes to quorum status/config.
-
#stop ⇒ void
Stop monitoring for changes.
-
#votes=(count) ⇒ Object
Set the number of votes contributed by this node.
Constructor Details
#initialize(connect = false) ⇒ void
Creates a new Votequorum instance
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/corosync/votequorum.rb', line 36 def initialize(connect = false) @handle = nil @fd = nil @callbacks = Corosync::VotequorumCallbacksT.new @callbacks[:votequorum_notify_fn] = self.method(:callback_notify) @callbacks[:votequorum_expectedvotes_notify_fn] = self.method(:callback_expectedvotes_notify) self.connect if connect end |
Instance Attribute Details
#fd ⇒ IO (readonly)
The IO object containing the file descriptor notifications come across. You can use this to check for activity, but do not read anything from it.
29 30 31 |
# File 'lib/corosync/votequorum.rb', line 29 def fd @fd end |
Instance Method Details
#connect(start = false) ⇒ void
This method returns an undefined value.
Connect to the Votequorum service
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/corosync/votequorum.rb', line 50 def connect(start = false) handle_ptr = FFI::MemoryPointer.new(Corosync.find_type(:votequorum_handle_t)) Corosync.cs_send(:votequorum_initialize, handle_ptr, @callbacks) @handle = handle_ptr.read_uint64 fd_ptr = FFI::MemoryPointer.new(:int) Corosync.cs_send(:votequorum_fd_get, @handle, fd_ptr) @fd = IO.new(fd_ptr.read_int) self.start if start end |
#dispatch(timeout = -1)) ⇒ Boolean
Checks for a single pending event and triggers the appropriate callback if found.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/corosync/votequorum.rb', line 101 def dispatch(timeout = -1) if !timeout != 0 then timeout = nil if timeout == -1 select([@fd], [], [], timeout) end begin Corosync.cs_send(:votequorum_dispatch, @handle, Corosync::CS_DISPATCH_ONE_NONBLOCKING) rescue Corosync::TryAgainError return false end return true end |
#finalize ⇒ void
This method returns an undefined value.
Shuts down the connection to the Quorum service
66 67 68 69 70 71 72 73 |
# File 'lib/corosync/votequorum.rb', line 66 def finalize return if @handle.nil? Corosync.cs_send(:votequorum_finalize, @handle) @handle = nil @fd = nil end |
#info(node_id = 0) ⇒ OpenStruct
Get the votequorum info about a node. The return openstruct will contain the following keys
* node_id - Integer
* node_state - Symbol: :member or :dead or :leaving
* node_votes - Integer
* node_expected_votes - Integer
* highest_expected - Integer
* total_votes - Integer
* quorum - Integer
* flags - Array<Symbol> where each symbol is one of: :twonode, :quorate, :wait_for_all, :last_man_standing, :auto_tie_breaker, :allow_downscale, :qdevice_registered, :qdevice_alive, :qdevice_cast_vote, or :qdevice_master_wins
* qdevice_votes - Integer
* qdevice_name - String
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/corosync/votequorum.rb', line 171 def info(node_id = 0) info = Corosync::VotequorumInfo.new Corosync.cs_send(:votequorum_getinfo, @handle, node_id, info) info = OpenStruct.new(Hash[info.members.zip(info.values)]) info.qdevice_name = info.qdevice_name.to_s flags = info.flags info.flags = [] [:twonode,:quorate,:wait_for_all,:last_man_standing,:auto_tie_breaker,:allow_downscale,:qdevice_registered,:qdevice_alive,:qdevice_cast_vote,:qdevice_master_wins].each do |flag_name| flag_value = Corosync.const_get("VOTEQUORUM_INFO_#{flag_name.to_s.upcase}") info.flags << flag_name if flags & flag_value >= 1 end info #Corosync::Votequorum::Info.new info end |
#on_expectedvotes_notify(&block) {|expected_votes| ... } ⇒ void
This method returns an undefined value.
Proc to call when the number of expected votes changes.
147 148 149 |
# File 'lib/corosync/votequorum.rb', line 147 def on_expectedvotes_notify(&block) @callback_expectedvotes_notify = block end |
#on_notify(&block) {|quorate, nodes| ... } ⇒ void
This method returns an undefined value.
Proc to call when quorum state changes.
122 123 124 |
# File 'lib/corosync/votequorum.rb', line 122 def on_notify(&block) @callback_notify = block end |
#quorate? ⇒ Boolean
Get whether this node is quorate or not Shorthand for #info.flags.include?(:quorate)
215 216 217 |
# File 'lib/corosync/votequorum.rb', line 215 def quorate? self.info.flags.include?(:quorate) end |
#set_expected(count) ⇒ void Also known as: expected=
This method returns an undefined value.
Set the number of expected votes for this node
194 195 196 |
# File 'lib/corosync/votequorum.rb', line 194 def set_expected(count) Corosync.cs_send(:votequorum_setexpected, @handle, count) end |
#set_votes(count, node_id = 0) ⇒ void
This method returns an undefined value.
Set the number of votes contributed by the specified node.
203 204 205 |
# File 'lib/corosync/votequorum.rb', line 203 def set_votes(count, node_id = 0) Corosync.cs_send(:votequorum_setvotes, @handle, node_id, count) end |
#start(initial_callback = false) ⇒ Boolean
Start monitoring for changes to quorum status/config. This basically just enables triggering the callback. If not called you can still call #quorate? to get quorum state.
79 80 81 82 83 84 85 86 87 |
# File 'lib/corosync/votequorum.rb', line 79 def start(initial_callback = false) connect if @handle.nil? Corosync.cs_send(:votequorum_trackstart, @handle, 0, Corosync::CS_TRACK_CHANGES) if initial_callback and @callback_notify then @callback_notify.call(quorate?) end end |
#stop ⇒ void
This method returns an undefined value.
Stop monitoring for changes.
91 92 93 |
# File 'lib/corosync/votequorum.rb', line 91 def stop Corosync.cs_send(:votequorum_trackstop, @handle) end |
#votes=(count) ⇒ Object
Set the number of votes contributed by this node. Shorthand for #set_votes(count)
208 209 210 |
# File 'lib/corosync/votequorum.rb', line 208 def votes=(count) set_votes(count) end |