Skip to content

Commit

Permalink
Merge pull request #2 from vinoski/update-1.0
Browse files Browse the repository at this point in the history
minor changes and cleanup for 1.0
  • Loading branch information
rzezeski committed Oct 6, 2011
2 parents 2885299 + 649f1b7 commit e5d4287
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 82 deletions.
10 changes: 7 additions & 3 deletions README.md
Expand Up @@ -9,7 +9,11 @@ Install [rebar](https://github.com/basho/rebar). You can do that via homebrew:
brew update
brew install rebar

Drop these templates in `~/.rebar/templates/`, then:
Drop these templates in `~/.rebar/templates/`:

cp riak* ~/.rebar/templates

Then:

mkdir myapp
cd myapp
Expand All @@ -22,7 +26,7 @@ Integrate this app into your node's `rebar.config`:

...
{deps, [
{riak_core, "0.14.*", {git, "git://github.com/basho/riak_core", {tag, "riak_core-0.14.1"}}},
{riak_core, "1.0.*", {git, "git://github.com/basho/riak_core", "1.0"}},
{myapp, ".*", {git, "git@github.com:bij/myapp.git", "HEAD"}},
]}
...
Expand All @@ -36,4 +40,4 @@ function, which should return `{pong, Partition}`:
2> myapp:ping().
{pong,753586781748746817198774991869333432010090217472}

Hey, distributed unicorns!
Hey, distributed unicorns!
3 changes: 2 additions & 1 deletion riak_core.app.src
@@ -1,3 +1,4 @@
%% -*- erlang -*-
{application, {{appid}},
[
{description, ""},
Expand All @@ -10,4 +11,4 @@
]},
{mod, { {{appid}}_app, []}},
{env, []}
]}.
]}.
2 changes: 1 addition & 1 deletion riak_core.erl
Expand Up @@ -8,7 +8,7 @@

%% Public API

% @doc Pings a random vnode to make sure communication is functional
%% @doc Pings a random vnode to make sure communication is functional
ping() ->
DocIdx = riak_core_util:chash_key({<<"ping">>, term_to_binary(now())}),
PrefList = riak_core_apl:get_primary_apl(DocIdx, 1, {{appid}}),
Expand Down
1 change: 0 additions & 1 deletion riak_core.gitignore
Expand Up @@ -6,4 +6,3 @@ apps/{{appid}}/ebin
dev/*
doc/*
rel/{{nodeid}}

2 changes: 1 addition & 1 deletion riak_core.md
Expand Up @@ -10,4 +10,4 @@ following files:
* `src/riak_{{appid}}_vnode.erl`
* an implementation of the riak_core_vnode behaviour
* `src/{{appid}}.erl`
* the public API for interacting with your vnode
* the public API for interacting with your vnode
8 changes: 4 additions & 4 deletions riak_core.rebar.config
@@ -1,6 +1,6 @@
{sub_dirs, ["rel", "apps/{{appid}}"]}.
{cover_enabled, true.}
{erl_opts, [debug_info, fail_on_warning]}.
{deps, [{riak_core, "0.14..*",
{git, "git://github.com/basho/riak_core", "master"}}
{cover_enabled, true}.
{erl_opts, [debug_info, warnings_as_errors]}.
{deps, [{riak_core, "1.0.*",
{git, "git://github.com/basho/riak_core", {tag, "1.0.0"}}}
]}.
4 changes: 2 additions & 2 deletions riak_core.template
Expand Up @@ -4,7 +4,7 @@
{template, "riak_core.erl", "src/{{appid}}.erl"}.
{template, "riak_core.hrl", "src/{{appid}}.hrl"}.
{template, "riak_core_sup.erl", "src/{{appid}}_sup.erl"}.
{template, "riak_core_vnode.erl", "src/riak_{{appid}}_vnode.erl"}.
{template, "riak_core_vnode.erl", "src/{{appid}}_vnode.erl"}.
{template, "riak_core.rebar.config", "rebar.config"}.
{template, "riak_core.gitignore", ".gitignore"}.
{template, "riak_core.md", "README.md"}.
{template, "riak_core.md", "README.md"}.
24 changes: 13 additions & 11 deletions riak_core_multinode.Makefile
@@ -1,24 +1,26 @@
REBAR = $(shell pwd)/rebar

.PHONY: deps rel stagedevrel

all: deps compile

compile:
./rebar compile
$(REBAR) compile

deps:
./rebar get-deps
$(REBAR) get-deps

clean:
./rebar clean
$(REBAR) clean

distclean: clean devclean relclean
./rebar delete-deps
$(REBAR) delete-deps

test:
./rebar skip_deps=true eunit
$(REBAR) skip_deps=true eunit

rel: all
./rebar generate
$(REBAR) generate

relclean:
rm -rf rel/{{nodeid}}
Expand All @@ -29,7 +31,7 @@ devrel: dev1 dev2 dev3
### Docs
###
docs:
./rebar skip_deps=true doc
$(REBAR) skip_deps=true doc

##
## Developer targets
Expand All @@ -51,7 +53,7 @@ devclean:

dev1 dev2 dev3: all
mkdir -p dev
(cd rel && ../rebar generate target_dir=../dev/$@ overlay_vars=vars/$@.config)
(cd rel && $(REBAR) generate target_dir=../dev/$@ overlay_vars=vars/$@.config)


##
Expand Down Expand Up @@ -79,9 +81,9 @@ dialyzer: deps compile


cleanplt:
@echo
@echo
@echo "Are you sure? It takes about 1/2 hour to re-build."
@echo Deleting $(COMBO_PLT) in 5 seconds.
@echo
@echo
sleep 5
rm $(COMBO_PLT)
rm $(COMBO_PLT)
4 changes: 2 additions & 2 deletions riak_core_multinode.admin-runner 100644 → 100755
Expand Up @@ -16,7 +16,7 @@ if [ "$RUNNER_USER" -a "x$LOGNAME" != "x$RUNNER_USER" ]; then
exit 1
fi
echo "Attempting to restart script through sudo -u $RUNNER_USER"
exec sudo -u $RUNNER_USER -i $RUNNER_SCRIPT_DIR/$RUNNER_SCRIPT $@
exec sudo -u $RUNNER_USER -i $RUNNER_SCRIPT_DIR/$RUNNER_SCRIPT "$@"
fi

# Make sure CWD is set to runner base dir
Expand Down Expand Up @@ -145,7 +145,7 @@ case "$1" in
continue
fi

# Get the list of services that are available on the requested noe
# Get the list of services that are available on the requested node
SERVICES=`$NODETOOL rpcterms riak_core_node_watcher services "'${TARGETNODE}'."`
echo "$SERVICES" | grep "[[,]$SVC[],]" > /dev/null 2>&1
if [ "X$?" = "X0" ]; then
Expand Down
8 changes: 4 additions & 4 deletions riak_core_multinode.app.config
@@ -1,3 +1,4 @@
%% -*- erlang -*-
[
%% Riak Core config
{riak_core, [
Expand All @@ -18,19 +19,18 @@
% {certfile, "etc/cert.pem"},
% {keyfile, "etc/key.pem"}
% ]},

%% riak_handoff_port is the TCP port that Riak uses for
%% intra-cluster data handoff.
{handoff_port, {{handoff_port}} }
]},

%% SASL config
{sasl, [
{sasl_error_logger, {file, "log/sasl-error.log"}},
{errlog_type, error},
{error_logger_mf_dir, "log/sasl"}, % Log directory
{error_logger_mf_maxbytes, 10485760}, % 10 MB max file size
{error_logger_mf_maxfiles, 5} % 5 files max
]}
]}
].

82 changes: 36 additions & 46 deletions riak_core_multinode.console
Expand Up @@ -6,75 +6,65 @@
ringready/1]).

join([NodeStr]) ->
try
case riak_core:join(NodeStr) of
ok ->
io:format("Sent join request to ~s\n", [NodeStr]),
ok;
{error, not_reachable} ->
io:format("Node ~s is not reachable!\n", [NodeStr]),
error;
{error, different_ring_sizes} ->
io:format("Failed: ~s has a different ring_creation_size~n",
[NodeStr]),
error
end
try riak_core:join(NodeStr) of
ok ->
io:format("Sent join request to ~s\n", [NodeStr]),
ok;
{error, not_reachable} ->
io:format("Node ~s is not reachable!\n", [NodeStr]),
error;
{error, different_ring_sizes} ->
io:format("Failed: ~s has a different ring_creation_size~n",
[NodeStr]),
error
catch
Exception:Reason ->
lager:error("Join failed ~p:~p", [Exception,
Reason]),
lager:error("Join failed ~p:~p", [Exception, Reason]),
io:format("Join failed, see log for details~n"),
error
end.


leave([]) ->
remove_node(node()).


remove([Node]) ->
remove_node(list_to_atom(Node)).

remove_node(Node) when is_atom(Node) ->
try
case catch(riak_core:remove_from_cluster(Node)) of
{'EXIT', {badarg, [{erlang, hd, [[]]}|_]}} ->
%% This is a workaround because
%% riak_core_gossip:remove_from_cluster doesn't check if
%% the result of subtracting the current node from the
%% cluster member list results in the empty list. When
%% that code gets refactored this can probably go away.
io:format("Leave failed, this node is the only member.~n"),
error;
Res ->
io:format(" ~p\n", [Res])
end
try catch(riak_core:remove_from_cluster(Node)) of
{'EXIT', {badarg, [{erlang, hd, [[]]}|_]}} ->
%% This is a workaround because
%% riak_core_gossip:remove_from_cluster doesn't check if
%% the result of subtracting the current node from the
%% cluster member list results in the empty list. When
%% that code gets refactored this can probably go away.
io:format("Leave failed, this node is the only member.~n"),
error;
Res ->
io:format(" ~p\n", [Res])
catch
Exception:Reason ->
lager:error("Leave failed ~p:~p", [Exception,
Reason]),
lager:error("Leave failed ~p:~p", [Exception, Reason]),
io:format("Leave failed, see log for details~n"),
error
end.


-spec(ringready([]) -> ok | error).
ringready([]) ->
try
case riak_core_status:ringready() of
{ok, Nodes} ->
io:format("TRUE All nodes agree on the ring ~p\n", [Nodes]);
{error, {different_owners, N1, N2}} ->
io:format("FALSE Node ~p and ~p list different partition owners\n", [N1, N2]),
error;
{error, {nodes_down, Down}} ->
io:format("FALSE ~p down. All nodes need to be up to check.\n", [Down]),
error
end
try riak_core_status:ringready() of
{ok, Nodes} ->
io:format("TRUE All nodes agree on the ring ~p\n", [Nodes]);
{error, {different_owners, N1, N2}} ->
io:format("FALSE Node ~p and ~p list different partition owners\n",
[N1, N2]),
error;
{error, {nodes_down, Down}} ->
io:format("FALSE ~p down. All nodes need to be up to check.\n",
[Down]),
error
catch
Exception:Reason ->
lager:error("Ringready failed ~p:~p", [Exception,
Reason]),
lager:error("Ringready failed ~p:~p", [Exception, Reason]),
io:format("Ringready failed, see log for details~n"),
error
end.
4 changes: 2 additions & 2 deletions riak_core_multinode.erl.script
Expand Up @@ -4,7 +4,7 @@
## as escript depends on erl and in turn, erl depends on having access to a
## bootscript (start.boot). Note that this script is ONLY invoked as a side-effect
## of running escript -- the embedded node bypasses erl and uses erlexec directly
## (as it should).
## (as it should).
##
## Note that this script makes the assumption that there is a start_clean.boot
## file available in $ROOTDIR/release/VSN.
Expand All @@ -31,4 +31,4 @@ export ROOTDIR
export BINDIR
export PROGNAME

exec $CMD -boot $ROOTDIR/releases/$APP_VSN/start_clean ${1+"$@"}
exec $CMD -boot $ROOTDIR/releases/$APP_VSN/start_clean ${1+"$@"}
7 changes: 4 additions & 3 deletions riak_core_multinode.rebar.config
@@ -1,7 +1,8 @@
%% -*- erlang -*-
{sub_dirs, ["rel", "apps/{{appid}}"]}.
{cover_enabled, true}.
{erl_opts, [debug_info, fail_on_warning]}.
{erl_opts, [debug_info, warnings_as_errors]}.
{edoc_opts, [{dir, "../../doc"}]}.
{deps, [{riak_core, ".*",
{git, "git://github.com/basho/riak_core", "master"}}
{deps, [{riak_core, "1.0.*",
{git, "git://github.com/basho/riak_core", {tag, "1.0.0"}}}
]}.
2 changes: 1 addition & 1 deletion riak_core_vnode.erl
Expand Up @@ -26,7 +26,7 @@ start_vnode(I) ->
init([Partition]) ->
{ok, #state { partition=Partition }}.

% Sample command: respond to a ping
%% Sample command: respond to a ping
handle_command(ping, _Sender, State) ->
{reply, {pong, State#state.partition}, State};
handle_command(Message, _Sender, State) ->
Expand Down

0 comments on commit e5d4287

Please sign in to comment.