Skip to content

Instantly share code, notes, and snippets.

@bbrowning
Created April 1, 2010 10:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbrowning/351659 to your computer and use it in GitHub Desktop.
Save bbrowning/351659 to your computer and use it in GitHub Desktop.
%% Loading Erlang map/reduce modfuns into a running Riak cluster
%%
%% Run this code from an Erlang node that can communicate with your Riak cluster.
%% If Riak was installed from the .deb package here's an example of launching
%% such a node from the same host:
%% /usr/lib/riak/erts-5.7.4/bin/erl -name client@127.0.0.1 -setcookie riak
% RiakNode can be any of the nodes in your Riak cluster
RiakNode = 'riak@127.0.0.1'.
% Get the ring for the running cluster
{ok, Chstate} = rpc:call(RiakNode, riak_ring_manager, get_my_ring, []).
% Get all members of the running cluster
RiakNodes = rpc:call(RiakNode, riak_ring, all_members, [Chstate]).
% Load my_mapreduce_module into the running cluster
% replace my_mapreduce_module with your module's name
{Mod, Bin, File} = code:get_object_code(my_mapreduce_module).
{Replies, _} = rpc:multicall(RiakNodes, code, load_binary, [Mod, File, Bin]).
% The first list in Replies should have one tuple for every node of your cluster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment