From d95ad239bc3c55becc1e0037ef2e218adaf062af Mon Sep 17 00:00:00 2001 From: Russell Brown Date: Sat, 22 Dec 2012 11:27:43 +0000 Subject: [PATCH] Update for multi-node devrel (as per riak) Add stage / stagedevrel to readme --- README.md | 48 +++++++++++++++++++++++++++-------- riak_core.Makefile | 33 ++++++++++++++++++++---- riak_core.dev1.config | 13 ---------- riak_core.dev2.config | 13 ---------- riak_core.dev3.config | 13 ---------- riak_core.dev_vars.config.src | 17 +++++++++++++ riak_core.gen_dev | 24 ++++++++++++++++++ riak_core.reltool.config | 1 + riak_core.template | 7 +++-- 9 files changed, 111 insertions(+), 58 deletions(-) delete mode 100644 riak_core.dev1.config delete mode 100644 riak_core.dev2.config delete mode 100644 riak_core.dev3.config create mode 100644 riak_core.dev_vars.config.src create mode 100755 riak_core.gen_dev diff --git a/README.md b/README.md index 5632715..169667d 100644 --- a/README.md +++ b/README.md @@ -56,13 +56,13 @@ Now shut it down: devrel ---------- -Above we showed how to start a single node, but this isn't typically how other Riak Core based applications like Riak are tested. Instead, there is something called a _devrel_ that allows one to easily set up a local 3-node cluster. +Above we showed how to start a single node, but this isn't typically how other Riak Core based applications like Riak are tested. Instead, there is something called a _devrel_ that allows one to easily set up a local `N`-node cluster. By defauly `N` is 4. You can change this by either editing the `Makefile` and changing `DEVNODES` to your prefered `N`, or by setting the variable `DEVNODES` before running the commands below. Build the dev-nodes: make devrel -This did create 3 separate instances under the `dev/` dir; check it out: +This did create 4 separate instances under the `dev/` dir; check it out: ls dev @@ -74,9 +74,9 @@ Verify that the nodes are up and running: for d in dev/dev*; do $d/bin/firstapp ping; done -You should see three `pong` replies. At this point it is worth saying that you have three **INDIVIDUAL** firstapp nodes running. They are **NOT** aware of each other yet. In order to form a cluster you have to _join_ the nodes. That has to be done only once. If a node, or the entire cluster, goes down it will remember the nodes it was connected to. +You should see four `pong` replies. At this point it is worth saying that you have four **INDIVIDUAL** firstapp nodes running. They are **NOT** aware of each other yet. In order to form a cluster you have to _join_ the nodes. That has to be done only once. If a node, or the entire cluster, goes down it will remember the nodes it was connected to. - for d in dev/dev{2,3}; do $d/bin/firstapp-admin join firstapp1@127.0.0.1; done + for d in dev/dev{2,3,4}; do $d/bin/firstapp-admin join firstapp1@127.0.0.1; done Finally, to make sure they really all agree on the shape of the cluster you can ask if the _ring_ is "ready." @@ -84,9 +84,9 @@ Finally, to make sure they really all agree on the shape of the cluster you can Which returns something like: - TRUE All nodes agree on the ring ['firstapp1@127.0.0.1','firstapp2@127.0.0.1','firstapp3@127.0.0.1'] + TRUE All nodes agree on the ring ['firstapp1@127.0.0.1','firstapp2@127.0.0.1','firstapp3@127.0.0.1'],'firstapp4@127.0.0.1'] -To verify you have a 3 node cluster and to see the distribution of the ring, run the `member_status` command: +To verify you have a 4 node cluster and to see the distribution of the ring, run the `member_status` command: ./dev/dev1/bin/firstapp-admin member_status @@ -95,14 +95,42 @@ Which returns: ================================= Membership ================================== Status Ring Pending Node ------------------------------------------------------------------------------- - valid 34.4% -- 'firstapp1@127.0.0.1' - valid 32.8% -- 'firstapp2@127.0.0.1' - valid 32.8% -- 'firstapp3@127.0.0.1' + valid 25.0% -- 'firstapp1@127.0.0.1' + valid 25.0% -- 'firstapp2@127.0.0.1' + valid 25.0% -- 'firstapp3@127.0.0.1' + valid 25.0% -- 'firstapp4@127.0.0.1' ------------------------------------------------------------------------------- - Valid:3 / Leaving:0 / Exiting:0 / Joining:0 / Down:0 + Valid:4 / Leaving:0 / Exiting:0 / Joining:0 / Down:0 Pretty cool!! Your riak-core cluster is up and running. And in case you want to stop all the nodes: for d in dev/dev*; do $d/bin/firstapp stop; done + +stage and stagedevrel +---------- + +For rapid, iterative development both `make rel` and `make devrel` +have a `stage` counterpart. Running either: + + make stage + +or + + make stagedevrel + +will cause the `deps` and `apps` directories to be symlinked into the +release(s) `lib` directory. This means you can edit your apps source +code, recompile it, and load it on to the running node(s). You can +either start mochiweb reloader + + reloader:start(). + +when attached to the node(s), which will cause any changes to be +automatically reloaded. Or attach to a running node and run + + `l(mod_name)`. + +to reload a specific module. + diff --git a/riak_core.Makefile b/riak_core.Makefile index 4ce2d43..3c34f32 100644 --- a/riak_core.Makefile +++ b/riak_core.Makefile @@ -24,12 +24,35 @@ stage : rel $(foreach dep,$(wildcard deps/*), rm -rf rel/{{appid}}/lib/$(shell basename $(dep))-* && ln -sf $(abspath $(dep)) rel/{{appid}}/lib;) $(foreach app,$(wildcard apps/*), rm -rf rel/{{appid}}/lib/$(shell basename $(app))-* && ln -sf $(abspath $(app)) rel/{{appid}}/lib;) -devrel: all dev1 dev2 dev3 -dev1 dev2 dev3: +## +## Developer targets +## +## devN - Make a dev build for node N +## stagedevN - Make a stage dev build for node N (symlink libraries) +## devrel - Make a dev build for 1..$DEVNODES +## stagedevrel Make a stagedev build for 1..$DEVNODES +## +## Example, make a 68 node devrel cluster +## make stagedevrel DEVNODES=68 + +.PHONY : stagedevrel devrel +DEVNODES ?= 4 + +# 'seq' is not available on all *BSD, so using an alternate in awk +SEQ = $(shell awk 'BEGIN { for (i = 1; i < '$(DEVNODES)'; i++) printf("%i ", i); print i ;exit(0);}') + +$(eval stagedevrel : $(foreach n,$(SEQ),stagedev$(n))) +$(eval devrel : $(foreach n,$(SEQ),dev$(n))) + +dev% : all mkdir -p dev - (cd rel && ../rebar generate target_dir=../dev/$@ overlay_vars=vars/$@.config) + rel/gen_dev $@ rel/vars/dev_vars.config.src rel/vars/$@_vars.config + (cd rel && ../rebar generate target_dir=../dev/$@ overlay_vars=vars/$@_vars.config) + +stagedev% : dev% + $(foreach dep,$(wildcard deps/*), rm -rf dev/$^/lib/$(shell basename $(dep))* && ln -sf $(abspath $(dep)) dev/$^/lib;) + $(foreach app,$(wildcard apps/*), rm -rf dev/$^/lib/$(shell basename $(app))* && ln -sf $(abspath $(app)) dev/$^/lib;) -devclean: +devclean: clean rm -rf dev - diff --git a/riak_core.dev1.config b/riak_core.dev1.config deleted file mode 100644 index ff2e068..0000000 --- a/riak_core.dev1.config +++ /dev/null @@ -1,13 +0,0 @@ -%% -%% etc/app.config -%% -{ring_state_dir, "data/ring"}. -{web_ip, "127.0.0.1"}. -{web_port, "8091"}. -{handoff_port, "8101"}. - -%% -%% etc/vm.args -%% -{node, "{{appid}}1@127.0.0.1"}. -{cookie, "{{appid}}"}. \ No newline at end of file diff --git a/riak_core.dev2.config b/riak_core.dev2.config deleted file mode 100644 index e1e1373..0000000 --- a/riak_core.dev2.config +++ /dev/null @@ -1,13 +0,0 @@ -%% -%% etc/app.config -%% -{ring_state_dir, "data/ring"}. -{web_ip, "127.0.0.1"}. -{web_port, "8092"}. -{handoff_port, "8102"}. - -%% -%% etc/vm.args -%% -{node, "{{appid}}2@127.0.0.1"}. -{cookie, "{{appid}}"}. \ No newline at end of file diff --git a/riak_core.dev3.config b/riak_core.dev3.config deleted file mode 100644 index 5ef23c0..0000000 --- a/riak_core.dev3.config +++ /dev/null @@ -1,13 +0,0 @@ -%% -%% etc/app.config -%% -{ring_state_dir, "data/ring"}. -{web_ip, "127.0.0.1"}. -{web_port, "8093"}. -{handoff_port, "8103"}. - -%% -%% etc/vm.args -%% -{node, "{{appid}}3@127.0.0.1"}. -{cookie, "{{appid}}"}. \ No newline at end of file diff --git a/riak_core.dev_vars.config.src b/riak_core.dev_vars.config.src new file mode 100644 index 0000000..624d2ec --- /dev/null +++ b/riak_core.dev_vars.config.src @@ -0,0 +1,17 @@ +%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ft=erlang ts=4 sw=4 et + +%% +%% etc/app.config +%% +{ring_state_dir, "data/ring"}. +{web_ip, "127.0.0.1"}. +{web_port, @WEBPORT@}. +{handoff_port, @HANDOFFPORT@}. + +%% +%% etc/vm.args +%% +{node, "@NODE@"}. +{cookie, "{{appid}}"}. + diff --git a/riak_core.gen_dev b/riak_core.gen_dev new file mode 100755 index 0000000..04dc2fa --- /dev/null +++ b/riak_core.gen_dev @@ -0,0 +1,24 @@ +#! /bin/sh +# +# gen_dev dev4 vars.src vars +# +# Generate an overlay config for devNNN from vars.src and write to vars +# + +NAME=$1 +TEMPLATE=$2 +VARFILE=$3 + +## Allocate 10 ports per node +## .7 - http + +NUMBER=${NAME##dev} +BASE=$((10000 + 10 * $NUMBER)) +WEBPORT=$(($BASE + 8)) +HANDOFFPORT=$(($BASE + 9)) +NODENAME="{{appid}}$NUMBER@127.0.0.1" + +echo "Generating $NAME - node='$NODENAME' http=$WEBPORT handoff=$HANDOFFPORT" +sed -e "s/@NODE@/$NODENAME/" \ + -e "s/@WEBPORT@/$WEBPORT/" \ + -e "s/@HANDOFFPORT@/$HANDOFFPORT/" < $TEMPLATE > $VARFILE diff --git a/riak_core.reltool.config b/riak_core.reltool.config index 5965b3f..d7b5409 100644 --- a/riak_core.reltool.config +++ b/riak_core.reltool.config @@ -16,6 +16,7 @@ {profile, embedded}, {excl_sys_filters, ["^bin/.*", "^erts.*/bin/(dialyzer|typer)"]}, + {excl_archive_filters, [".*"]}, {app, sasl, [{incl_cond, include}]}, {app, {{appid}}, [{incl_cond, include}]} ]}. diff --git a/riak_core.template b/riak_core.template index cd6ddd1..dc56151 100644 --- a/riak_core.template +++ b/riak_core.template @@ -11,6 +11,8 @@ {dir, "rel"}. {template, "riak_core.reltool.config", "rel/reltool.config"}. {template, "riak_core.vars.config", "rel/vars.config"}. +{template, "riak_core.gen_dev", "rel/gen_dev"}. +{chmod, 8#744, "rel/gen_dev"}. {dir, "rel/files"}. {file, "riak_core.app.config", "rel/files/app.config"}. @@ -25,10 +27,7 @@ {file, "riak_core.vm.args", "rel/files/vm.args"}. {dir, "rel/vars"}. -{template, "riak_core.dev1.config", "rel/vars/dev1.config"}. -{template, "riak_core.dev2.config", "rel/vars/dev2.config"}. -{template, "riak_core.dev3.config", "rel/vars/dev3.config"}. - +{template, "riak_core.dev_vars.config.src", "rel/vars/dev_vars.config.src"}. %% ./src {dir, "src"}.