Class: Corosync::Quorum
- Inherits:
-
Object
- Object
- Corosync::Quorum
- Defined in:
- lib/corosync/quorum.rb
Overview
Quorum is used for tracking the health of the cluster. This simply reads the quorum state as defined by corosync. 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 Quorum 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.
-
#getquorate ⇒ Boolean
(also: #quorate?)
Get node quorum status.
-
#initialize(connect = false) ⇒ void
constructor
Creates a new Quorum instance.
-
#on_notify(&block) {|quorate, members| ... } ⇒ void
Proc to call when quorum state changes.
-
#start(initial_callback = false) ⇒ Boolean
Start monitoring for changes to quorum status.
-
#stop ⇒ void
Stop monitoring for changes to quorum status.
Constructor Details
#initialize(connect = false) ⇒ void
Creates a new Quorum instance
32 33 34 35 36 37 38 39 40 |
# File 'lib/corosync/quorum.rb', line 32 def initialize(connect = false) @handle = nil @fd = nil @callbacks = Corosync::QuorumCallbacksT.new @callbacks[:quorum_notify_fn] = self.method(:callback_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.
25 26 27 |
# File 'lib/corosync/quorum.rb', line 25 def fd @fd end |
Instance Method Details
#connect(start = false) ⇒ void
This method returns an undefined value.
Connect to the Quorum service
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/corosync/quorum.rb', line 45 def connect(start = false) handle_ptr = FFI::MemoryPointer.new(Corosync.find_type(:quorum_handle_t)) quorum_type_ptr = FFI::MemoryPointer.new(:uint32) Corosync.cs_send(:quorum_initialize, handle_ptr, @callbacks, quorum_type_ptr) @handle = handle_ptr.read_uint64 fd_ptr = FFI::MemoryPointer.new(:int) Corosync.cs_send(:quorum_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.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/corosync/quorum.rb', line 97 def dispatch(timeout = -1) if !timeout != 0 then timeout = nil if timeout == -1 select([@fd], [], [], timeout) end begin Corosync.cs_send!(:quorum_dispatch, @handle, Corosync::CS_DISPATCH_ONE_NONBLOCKING) rescue Corosync::TryAgainError => e raise e if e.depth > 1 # this exception is from a nested corosync function, not our quorum_dispatch we just called return false end return true end |
#finalize ⇒ void
This method returns an undefined value.
Shuts down the connection to the Quorum service
62 63 64 65 66 67 68 69 |
# File 'lib/corosync/quorum.rb', line 62 def finalize return if @handle.nil? Corosync.cs_send(:quorum_finalize, @handle) @handle = nil @fd = nil end |
#getquorate ⇒ Boolean Also known as: quorate?
Get node quorum status
136 137 138 139 140 141 |
# File 'lib/corosync/quorum.rb', line 136 def getquorate quorate_ptr = FFI::MemoryPointer.new(:int) Corosync.cs_send(:quorum_getquorate, @handle, quorate_ptr) quorate_ptr.read_int > 0 end |
#on_notify(&block) {|quorate, members| ... } ⇒ void
This method returns an undefined value.
Proc to call when quorum state changes.
118 119 120 |
# File 'lib/corosync/quorum.rb', line 118 def on_notify(&block) @callback_notify = block end |
#start(initial_callback = false) ⇒ Boolean
Start monitoring for changes to quorum status. This basically just enables triggering the callback. If not called you can still call #quorate? to get quorum state.
75 76 77 78 79 80 81 82 83 |
# File 'lib/corosync/quorum.rb', line 75 def start(initial_callback = false) connect if @handle.nil? Corosync.cs_send(:quorum_trackstart, @handle, Corosync::CS_TRACK_CHANGES) if initial_callback and @callback_notify then @callback_notify.call(quorate?, []) end end |