Permalink
Browse files

Initial public commit

  • Loading branch information...
jtuple committed Apr 1, 2011
0 parents commit fd86eeec585c199b2e1f80c2b0b5ded6a1327544
@@ -0,0 +1,34 @@
+%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*-
+%% ex: ts=4 sw=4 etnnononono
+{application,riak_zab,
+ [{description,[]},
+ {vsn,"0.1.0"},
+ {registered,[]},
+ {applications, [
+ kernel,
+ stdlib,
+ riak_core
+ ]},
+ {mod,{riak_zab_app,[]}},
+ {env,[]},
+ {modules, [
+ riak_zab_app,
+ riak_zab_sup,
+ riak_zab_peer,
+ riak_zab_vnode,
+ riak_zab_ring_handler,
+ riak_zab_fast_election_fsm,
+ riak_zab_watcher,
+ riak_zab_backend,
+ riak_zab_bitcask_backend,
+ riak_zab_status,
+ riak_zab_console,
+ riak_zab_process,
+ riak_zab_process_sup,
+ riak_zab_ensemble_master,
+ riak_zab_ensemble_util,
+ riak_zab_util,
+ riak_zab_log,
+ riak_zab_leader_test
+ ]}
+ ]}.
@@ -0,0 +1,12 @@
+-include_lib("riak_core/include/riak_core_vnode.hrl").
+
+-type zsender() :: {fsm_sync, reference(), term()} |
+ {fsm_sync, undefined, undefined} |
+ sender().
+
+-record(riak_zab_proposal, {
+ preflist,
+ sender,
+ message}).
+
+-define(ZAB_PROPOSAL, #riak_zab_proposal).
@@ -0,0 +1,12 @@
+%-include_lib("riak_core/include/riak_core_vnode.hrl").
+
+-record(riak_zab_last_zxid, {}).
+-record(riak_zab_sync, {peer, idxs}).
+-record(riak_zab_req, {req, zxid, sender, leading}).
+-record(riak_zab_sync_data, {data}).
+
+-define(ZAB_LAST_ZXID, #riak_zab_last_zxid).
+-define(ZAB_SYNC, #riak_zab_sync).
+-define(ZAB_REQ, #riak_zab_req).
+-define(ZAB_SYNC_DATA, #riak_zab_sync_data).
+
BIN rebar
Binary file not shown.
@@ -0,0 +1,11 @@
+{require_otp_vsn, "R13B04|R14"}.
+{cover_enabled, true}.
+{erl_opts, [debug_info, fail_on_warning]}.
+
+{deps, [
+ {riak_core, "0.14..*", {git, "git://github.com/basho/riak_core",
+ {tag, "riak_core-0.14.1"}}},
+ {bitcask, "1.1.5", {git, "git://github.com/basho/bitcask",
+ {tag, "bitcask-1.1.5"}}},
+ {eprobe, "0.1.0", {git, "file:///repo/eprobe", {branch, "master"}}}
+ ]}.
@@ -0,0 +1,34 @@
+-module(riak_zab_app).
+
+-behaviour(application).
+
+%% Application callbacks
+-export([start/2, stop/1, full_stop/0, full_stop/1]).
+
+%% ===================================================================
+%% Application callbacks
+%% ===================================================================
+
+start(_StartType, _StartArgs) ->
+ riak_core_util:start_app_deps(riak_zab),
+
+ case riak_zab_sup:start_link() of
+ {ok, Pid} ->
+ ok = riak_core_ring_events:add_handler(riak_zab_ring_handler, []),
+ {ok, Pid};
+ {error, Reason} ->
+ {error, Reason}
+ end.
+
+stop(_State) ->
+ ok.
+
+
+%% @spec full_stop() -> ok
+%% @doc Stop the riak application and the calling process.
+full_stop() -> stop("riak stop requested").
+full_stop(Reason) ->
+ % we never do an application:stop because that makes it very hard
+ % to really halt the runtime, which is what we need here.
+ error_logger:info_msg(io_lib:format("~p~n",[Reason])),
+ init:stop().
@@ -0,0 +1,90 @@
+%% -------------------------------------------------------------------
+%%
+%% riak_zab_backend: Copy of riak_kv_backend to avoid requiring
+%% entire riak_kv app as a dependency.
+%%
+%% -------------------------------------------------------------------
+%%
+%% riak_kv_backend: Riak backend behaviour
+%%
+%% Copyright (c) 2007-2010 Basho Technologies, Inc. All Rights Reserved.
+%%
+%% This file is provided to you under the Apache License,
+%% Version 2.0 (the "License"); you may not use this file
+%% except in compliance with the License. You may obtain
+%% a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing,
+%% software distributed under the License is distributed on an
+%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+%% KIND, either express or implied. See the License for the
+%% specific language governing permissions and limitations
+%% under the License.
+%%
+%% -------------------------------------------------------------------
+
+-module(riak_zab_backend).
+-export([behaviour_info/1]).
+-export([callback_after/3]).
+-ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
+-export([standard_test/2]).
+-endif.
+
+-spec behaviour_info(atom()) -> 'undefined' | [{atom(), arity()}].
+behaviour_info(callbacks) ->
+ [{start,2}, % (Partition, Config)
+ {stop,1}, % (State)
+ {get,2}, % (State, BKey)
+ {put,3}, % (State, BKey, Val)
+ {list,1}, % (State)
+ {list_bucket,2}, % (State, Bucket)
+ {delete,2}, % (State, BKey)
+ {drop,1}, % (State)
+ {fold,3}, % (State, Folder, Acc), Folder({B,K},V,Acc)
+ {is_empty,1}, % (State)
+ {callback,3}]; % (State, Ref, Msg) ->
+behaviour_info(_Other) ->
+ undefined.
+
+%% Queue a callback for the backend after Time ms.
+-spec callback_after(integer(), reference(), term()) -> reference().
+callback_after(Time, Ref, Msg) when is_integer(Time), is_reference(Ref) ->
+ riak_core_vnode:send_command_after(Time, {backend_callback, Ref, Msg}).
+
+-ifdef(TEST).
+
+standard_test(BackendMod, Config) ->
+ {ok, S} = BackendMod:start(42, Config),
+ ?assertEqual(ok, BackendMod:put(S,{<<"b1">>,<<"k1">>},<<"v1">>)),
+ ?assertEqual(ok, BackendMod:put(S,{<<"b2">>,<<"k2">>},<<"v2">>)),
+ ?assertEqual({ok,<<"v2">>}, BackendMod:get(S,{<<"b2">>,<<"k2">>})),
+ ?assertEqual({error, notfound}, BackendMod:get(S, {<<"b1">>,<<"k3">>})),
+ ?assertEqual([{<<"b1">>,<<"k1">>},{<<"b2">>,<<"k2">>}],
+ lists:sort(BackendMod:list(S))),
+ ?assertEqual([<<"k2">>], BackendMod:list_bucket(S, <<"b2">>)),
+ ?assertEqual([<<"k1">>], BackendMod:list_bucket(S, <<"b1">>)),
+ ?assertEqual([<<"k1">>], BackendMod:list_bucket(
+ S, {filter, <<"b1">>, fun(_K) -> true end})),
+ ?assertEqual([], BackendMod:list_bucket(
+ S, {filter, <<"b1">>, fun(_K) -> false end})),
+ BucketList = BackendMod:list_bucket(S, '_'),
+ ?assert(lists:member(<<"b1">>, BucketList)),
+ ?assert(lists:member(<<"b2">>, BucketList)),
+ ?assertEqual(ok, BackendMod:delete(S,{<<"b2">>,<<"k2">>})),
+ ?assertEqual({error, notfound}, BackendMod:get(S, {<<"b2">>, <<"k2">>})),
+ ?assertEqual([{<<"b1">>, <<"k1">>}], BackendMod:list(S)),
+ Folder = fun(K, V, A) -> [{K,V}|A] end,
+ ?assertEqual([{{<<"b1">>,<<"k1">>},<<"v1">>}], BackendMod:fold(S, Folder, [])),
+ ?assertEqual(ok, BackendMod:put(S,{<<"b3">>,<<"k3">>},<<"v3">>)),
+ ?assertEqual([{{<<"b1">>,<<"k1">>},<<"v1">>},
+ {{<<"b3">>,<<"k3">>},<<"v3">>}], lists:sort(BackendMod:fold(S, Folder, []))),
+ ?assertEqual(false, BackendMod:is_empty(S)),
+ ?assertEqual(ok, BackendMod:delete(S,{<<"b1">>,<<"k1">>})),
+ ?assertEqual(ok, BackendMod:delete(S,{<<"b3">>,<<"k3">>})),
+ ?assertEqual(true, BackendMod:is_empty(S)),
+ ok = BackendMod:stop(S).
+
+-endif. % TEST
Oops, something went wrong.

0 comments on commit fd86eee

Please sign in to comment.