Ruby interface to the corosync library
Ruby HTML
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
ffi
lib
spec
.gitignore
Gemfile
Gemfile.lock
LICENSE
README.md
Rakefile
VERSION
corosync.gemspec

README.md

ruby-corosync

Description

Ruby-corosync is a gem for interfacing ruby with the corosync cluster services.

Corosync is a cluster communication engine for communication between nodes operating as a cluster. The services it offers are as follows:

  • CPG - The CPG service which allows sending messages between nodes. Processes can join a 'group' and broadcast messages to that group. Order is preserved in that messages are guaranteed to arrive in the same order to all members.
  • SAM - SAM is a service which is meant to ensure processes remain operational. You can instruct corosync to start a process, and should that process die, corosync can notify you, and start it back up.
  • Quorum - The quorum service is a very basic service used for keeping track of whether the cluster has quorum or not.
  • Votequorum - The votequorum service is a more powerful version of the quorum service. It allows you to control the number of votes provided by any one node such that you can control the logic that determines whether the cluster is quorate.
  • CMAP - CMAP is a key/value store of the Corosync configuration database. You can get/set keys/values and watch them for changes.

Corosync offers these services through a C API. This gem utilizes ffi to provide the interface to that API.

Ruby stack size

Note that due to limitations in ruby versions prior to 2.0, usage of this gem is severely limited. As such the minimum ruby version supported is 2.0. See the threading notice section of the CPG documentation. Even with ruby 2.0, you must set the RUBY_THREAD_MACHINE_STACK_SIZE environment variable higher than 1mb, recommended value is 1572864 (1.5mb)

State

CPG, Quorum, Votequorum, and CMAP are feature complete. Possibly with bugs, but I personally use CPG very heavily, along the basic features of Quorum and CMAP.

Examples

There are fully functional example scripts in the examples directory. But below are some brief snippets.

CPG

require 'corosync/cpg'
cpg = Corosync::CPG.new('mygroup')
cpg.on_message do |sender, message|
  puts "Received #{message} from #{sender.nodeid}:#{sender.pid}"
end
puts "Member node IDs: #{cpg.members.map {|m| m.nodeid}.join(" ")}"
cpg.send "hello"
loop do
  cpg.dispatch
end

Quorum

require 'corosync/quorum'
quorum = Corosync::Quorum.new
quorum.on_notify do |quorate, member_list|
  puts "Cluster is#{quorate ? '' : ' not'} quorate"
  puts "  Members: #{member_list.join(' ')}"
end
quorum.connect(true)
loop do
  quorum.dispatch
end

CMAP

require 'corosync/cmap'
cmap = Corosync::CMAP.new
cmap.set('mykey.foo', :int32, -1234)
puts "mykey.foo is #{cmap.get('mykey.foo')}"

Contributions

I welcome any contributions in the form of bugs or pull requests. One thing to be aware of in terms of new features is that the goal of this gem is to provide a low level interface to the Corosync library. Features which simplify or abstract things should be implemented as separate gems. For example, my own corosync commander.

Versioning

I use a slight variant of semantic versioning. The scheme is: DESIGN.MAJOR.MINOR.PATCH

The DESIGN is used to indicate when not only is it no longer backwards compatable, but the fundamental design has changed. Meaning that it may take more than a little tweaking to accomidate for the changes. This should rarely, if ever, happen.