public
Description: `gen_cluster` is an erlang behavior for pid clustering. It is a cascading behavior that builds on `gen_server`.
Homepage:
Clone URL: git://github.com/jashmenn/gen_cluster.git
name age message
file .gitignore Tue Aug 18 14:02:58 -0700 2009 added empty file for ebin directory [jashmenn]
file Emakefile Tue Aug 18 14:03:55 -0700 2009 correct Emakefile caps [jashmenn]
file Makefile Tue Aug 18 18:12:01 -0700 2009 Added basic makefile [auser]
file README.mkd Tue Aug 04 11:02:26 -0700 2009 updated readme [jashmenn]
file Rakefile Tue Aug 18 18:05:39 -0700 2009 Cleaned up run_tests output [auser]
directory ebin/ Tue Aug 18 14:02:58 -0700 2009 added empty file for ebin directory [jashmenn]
directory include/ Mon Aug 03 15:54:53 -0700 2009 pulled over much more code from stoplight [jashmenn]
directory priv/ Tue Aug 04 08:05:46 -0700 2009 get srv name from cli, todo mv into gen_cluster [jashmenn]
directory src/ Fri Aug 28 08:49:09 -0700 2009 added rallying point fail over [jashmenn]
directory test/ Fri Aug 28 08:49:09 -0700 2009 added rallying point fail over [jashmenn]
README.mkd

gen_cluster

Summary

gen_cluster is an erlang behavior for pid clustering. It is a cascading behavior that builds on gen_server.

Status

Early alpha. Feel free to use this in production code as long as you know that nobody else is.

Motivation

Erlang provides many BIFs for dealing with nodes, node clustering, monitoring etc. However, one often wants to build a cluster of processes rather than entire nodes.

This module is a starting point for creating your own gen_server clusters. It aims to deal with common roles, actions, and callbacks one often deals with when making a cluster.

As usual, there are a number of subtleties that crop up when trying to create a cluster. The goal is for gen_cluster to allow one to gloss-over these details and simply provide an easy-to-use foundation for cluster-based erlang projects.

Features

Current features include:

  • Joining a cluster based on a given seed node
  • Storing the list of all current nodes in the cluster
  • Callbacks when a node joins or leaves

Usage

Add the behaviour directive to your module, implement the callbacks for both gen_server and gen_cluster. See example_cluster_srv.erl for full example and function signatures.

-behaviour(gen_cluster).

% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).

% gen_cluster callback
-export([handle_join/3, handle_node_joined/3, handle_leave/4]).

Try it out

Open up three terminals and do the following commands. This will start up three nodes that will join the first node. On q(). of any one of the nodes the other two will see that the node left and update the pidlist accordingly.

# term 1
rake server:start1

# term 2
rake server:start2

# term 3
rake server:start3

# term 2 again
q().

Plans

(features not yet implemented)

  • Globally registered name needs to be taken over by another node if the globally registered node dies. This is an important TODO and will be handled shortly.
  • TCP-layer option, rather than straight distributed erlang
  • Possible integration with Chordjerl

Authors

  • Nate Murray <nmurray [AT] attinteractive.com> github
  • Ari Lerner github