Skip to content

Commit

Permalink
V0.10.1 release
Browse files Browse the repository at this point in the history
Update riak_core_vnode API

reconstruct

format

format with Erlang version 23

Removed duplicate API call for send event

format

Fixed #70

Moved proper to project_plugins (#72)

Merge with "Finish removing bucket properties and buckets"

Insert the commit "Unused riak_core_bas64url module"

Finish removing bucket properties and buckets (#75)

* Removed bucket properties
* Removed unused functions
* Removed not needed riak_core_rand backwards-compatibility layer
* Changed variable call name and removed legacy state from riak_core_vnode_master
* Formated Mod -> Module for better graph and convention of variable Mod calls

make format

Update README.md

Added example references for riak_core_lite to the readme
  • Loading branch information
Albert Schimpf committed Jul 13, 2021
1 parent d2180df commit 4ffcfb7
Show file tree
Hide file tree
Showing 33 changed files with 997 additions and 1,829 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ dialyzer:
${REBAR} dialyzer

lint:
${REBAR} as lint lint
${REBAR} lint
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,11 @@ something Core related
* If you've found a bug in riak_core_lite,
[file](https://github.com/riak-core-lite/riak_core_lite/issues) a clear, concise,
explanatory issue against this repo.

## Reference Implementation

For some reference on how `riak_core_lite` can be used, you can read about projects which are using `riak_core_lite` as a library:

- [rcl_memkv](https://github.com/albsch/rcl_memkv): A minimalistic in-memory key-value store to understand how to implement the handoff behavior properly
- [rclref](https://github.com/wattlebirdaz/rclref): A reference implementation of a distributed key-value store using riak_core_lite featuring quorum reads and writes.
- [AntidoteDB](https://github.com/AntidoteDB/antidote): A a highly available geo-replicated key-value database which uses riak_core_lite for sharding of data centers.
11 changes: 3 additions & 8 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{xref_checks, [ undefined_function_calls, locals_not_used, deprecated_function_calls ]}.

%% Code formatter
{plugins, [rebar3_format, rebar3_proper]}.
{project_plugins, [rebar3_format, rebar3_lint, rebar3_proper]}.
{format, [ {formatter, otp_formatter} ]}.

%%-------------------------------------------------------------------
Expand All @@ -21,17 +21,12 @@
{plugins, [{coveralls, {git, "https://github.com/markusn/coveralls-erl", {branch, "master"}}}]},
{deps, [meck]}
]},
{docs, [{deps, [{edown, "0.7.0"}]}]},
{proper, [
{erl_opts, [nowarn_export_all,{d, 'PROPER'}, {d, 'TEST'}]},
{erl_opts, [nowarn_export_all, {d, 'PROPER'}, {d, 'TEST'}]},
{plugins, [{coveralls, {git, "https://github.com/markusn/coveralls-erl", {branch, "master"}}}]},
{deps, [meck, {proper, "1.3.0"}, recon]}
]},
{lint, [
{plugins, [
{rebar3_lint, {git, "https://github.com/project-fifo/rebar3_lint.git", {tag, "0.1.11"}}}
]}
]}
{docs, [{deps, [{edown, "0.7.0"}]}]}
]}.

{cover_enabled, true}.
Expand Down
84 changes: 44 additions & 40 deletions src/gen_fsm_compat.erl
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
%%% start_link(Name, Mod, Args, Options) where:
%%% Name ::= {local, atom()} | {global, term()} | {via, atom(), term()}
%%% Mod ::= atom(), callback module implementing the 'real' fsm
%%% Args ::= term(), init arguments (to Mod:init/1)
%%% Args ::= term(), init arguments (to Module:init/1)
%%% Options ::= [{debug, [Flag]}]
%%% Flag ::= trace | log | {logfile, File} | statistics | debug
%%% (debug == log && statistics)
Expand All @@ -233,8 +233,8 @@ stop(Name, Reason, Timeout) ->

send_event({global, Name}, Event) ->
catch global:send(Name, {'$gen_event', Event}), ok;
send_event({via, Mod, Name}, Event) ->
catch Mod:send(Name, {'$gen_event', Event}), ok;
send_event({via, Module, Name}, Event) ->
catch Module:send(Name, {'$gen_event', Event}), ok;
send_event(Name, Event) ->
Name ! {'$gen_event', Event}, ok.

Expand All @@ -260,8 +260,9 @@ send_all_state_event({global, Name}, Event) ->
catch global:send(Name,
{'$gen_all_state_event', Event}),
ok;
send_all_state_event({via, Mod, Name}, Event) ->
catch Mod:send(Name, {'$gen_all_state_event', Event}),
send_all_state_event({via, Module, Name}, Event) ->
catch Module:send(Name,
{'$gen_all_state_event', Event}),
ok;
send_all_state_event(Name, Event) ->
Name ! {'$gen_all_state_event', Event}, ok.
Expand Down Expand Up @@ -349,25 +350,26 @@ enter_loop(Mod, Options, StateName, StateData,
%%% ---------------------------------------------------
%%% Initiate the new process.
%%% Register the name using the Rfunc function
%%% Calls the Mod:init/Args function.
%%% Calls the Moduleinit/Args function.
%%% Finally an acknowledge is sent to Parent and the main
%%% loop is entered.
%%% ---------------------------------------------------
init_it(Starter, self, Name, Mod, Args, Options) ->
init_it(Starter, self(), Name, Mod, Args, Options);
init_it(Starter, Parent, Name0, Mod, Args, Options) ->
init_it(Starter, Parent, Name0, Module, Args,
Options) ->
Name = gen:name(Name0),
Debug = gen:debug_options(Name, Options),
HibernateAfterTimeout = gen:hibernate_after(Options),
case catch Mod:init(Args) of
case catch Module:init(Args) of
{ok, StateName, StateData} ->
proc_lib:init_ack(Starter, {ok, self()}),
loop(Parent, Name, StateName, StateData, Mod, infinity,
HibernateAfterTimeout, Debug);
loop(Parent, Name, StateName, StateData, Module,
infinity, HibernateAfterTimeout, Debug);
{ok, StateName, StateData, Timeout} ->
proc_lib:init_ack(Starter, {ok, self()}),
loop(Parent, Name, StateName, StateData, Mod, Timeout,
HibernateAfterTimeout, Debug);
loop(Parent, Name, StateName, StateData, Module,
Timeout, HibernateAfterTimeout, Debug);
{stop, Reason} ->
gen:unregister_name(Name0),
proc_lib:init_ack(Starter, {error, Reason}),
Expand Down Expand Up @@ -457,15 +459,15 @@ system_terminate(Reason, _Parent, Debug,
terminate(Reason, Name, [], Mod, StateName, StateData,
Debug).

system_code_change([Name, StateName, StateData, Mod,
system_code_change([Name, StateName, StateData, Module,
Time, HibernateAfterTimeout],
_Module, OldVsn, Extra) ->
case catch Mod:code_change(OldVsn, StateName, StateData,
Extra)
case catch Module:code_change(OldVsn, StateName,
StateData, Extra)
of
{ok, NewStateName, NewStateData} ->
{ok,
[Name, NewStateName, NewStateData, Mod, Time,
[Name, NewStateName, NewStateData, Module, Time,
HibernateAfterTimeout]};
Else -> Else
end.
Expand Down Expand Up @@ -602,27 +604,27 @@ handle_msg(Msg, Parent, Name, StateName, StateData, Mod,
StateName, StateData, Debug)
end.

dispatch({'$gen_event', Event}, Mod, StateName,
dispatch({'$gen_event', Event}, Module, StateName,
StateData) ->
Mod:StateName(Event, StateData);
dispatch({'$gen_all_state_event', Event}, Mod,
Module:StateName(Event, StateData);
dispatch({'$gen_all_state_event', Event}, Module,
StateName, StateData) ->
Mod:handle_event(Event, StateName, StateData);
dispatch({'$gen_sync_event', From, Event}, Mod,
Module:handle_event(Event, StateName, StateData);
dispatch({'$gen_sync_event', From, Event}, Module,
StateName, StateData) ->
Mod:StateName(Event, From, StateData);
Module:StateName(Event, From, StateData);
dispatch({'$gen_sync_all_state_event', From, Event},
Mod, StateName, StateData) ->
Mod:handle_sync_event(Event, From, StateName,
StateData);
dispatch({timeout, Ref, {'$gen_timer', Msg}}, Mod,
Module, StateName, StateData) ->
Module:handle_sync_event(Event, From, StateName,
StateData);
dispatch({timeout, Ref, {'$gen_timer', Msg}}, Module,
StateName, StateData) ->
Mod:StateName({timeout, Ref, Msg}, StateData);
dispatch({timeout, _Ref, {'$gen_event', Event}}, Mod,
Module:StateName({timeout, Ref, Msg}, StateData);
dispatch({timeout, _Ref, {'$gen_event', Event}}, Module,
StateName, StateData) ->
Mod:StateName(Event, StateData);
dispatch(Info, Mod, StateName, StateData) ->
Mod:handle_info(Info, StateName, StateData).
Module:StateName(Event, StateData);
dispatch(Info, Module, StateName, StateData) ->
Module:handle_info(Info, StateName, StateData).

from({'$gen_sync_event', From, _Event}) -> From;
from({'$gen_sync_all_state_event', From, _Event}) ->
Expand All @@ -644,14 +646,15 @@ reply(Name, {To, Tag}, Reply, Debug, StateName) ->
-spec terminate(term(), _, _, atom(), _, _,
_) -> no_return().

terminate(Reason, Name, Msg, Mod, StateName, StateData,
Debug) ->
case erlang:function_exported(Mod, terminate, 3) of
terminate(Reason, Name, Msg, Module, StateName,
StateData, Debug) ->
case erlang:function_exported(Module, terminate, 3) of
true ->
case catch Mod:terminate(Reason, StateName, StateData)
case catch Module:terminate(Reason, StateName,
StateData)
of
{'EXIT', R} ->
FmtStateData = format_status(terminate, Mod, get(),
FmtStateData = format_status(terminate, Module, get(),
StateData),
error_info(R, Name, Msg, StateName, FmtStateData,
Debug),
Expand All @@ -665,7 +668,7 @@ terminate(Reason, Name, Msg, Mod, StateName, StateData,
shutdown -> exit(shutdown);
{shutdown, _} = Shutdown -> exit(Shutdown);
_ ->
FmtStateData1 = format_status(terminate, Mod, get(),
FmtStateData1 = format_status(terminate, Module, get(),
StateData),
error_info(Reason, Name, Msg, StateName, FmtStateData1,
Debug),
Expand Down Expand Up @@ -776,14 +779,15 @@ format_status(Opt, StatusData) ->

-endif.

format_status(Opt, Mod, PDict, State) ->
format_status(Opt, Module, PDict, State) ->
DefStatus = case Opt of
terminate -> State;
_ -> [{data, [{"StateData", State}]}]
end,
case erlang:function_exported(Mod, format_status, 2) of
case erlang:function_exported(Module, format_status, 2)
of
true ->
case catch Mod:format_status(Opt, [PDict, State]) of
case catch Module:format_status(Opt, [PDict, State]) of
{'EXIT', _} -> DefStatus;
Else -> Else
end;
Expand Down
53 changes: 26 additions & 27 deletions src/gen_nb_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -90,37 +90,36 @@
{stop, Reason :: term(),
NewState :: term()}.

%% @spec start_link(CallbackModule, IpAddr, Port, InitParams) -> Result
%% CallbackModule = atom()
%% @spec start_link(Module, IpAddr, Port, InitParams) -> Result
%% Module = atom()
%% IpAddr = string()
%% Port = integer()
%% InitParams = [any()]
%% Result = {ok, pid()} | {error, any()}
%% @doc Start server listening on IpAddr:Port
start_link(CallbackModule, IpAddr, Port, InitParams) ->
start_link(Module, IpAddr, Port, InitParams) ->
gen_server:start_link(?MODULE,
[CallbackModule, IpAddr, Port, InitParams], []).
[Module, IpAddr, Port, InitParams], []).

%% @hidden
init([CallbackModule, IpAddr, Port, InitParams]) ->
case CallbackModule:init(InitParams) of
init([Module, IpAddr, Port, InitParams]) ->
case Module:init(InitParams) of
{ok, ServerState} ->
case listen_on(CallbackModule, IpAddr, Port) of
case listen_on(Module, IpAddr, Port) of
{ok, Sock} ->
{ok,
#state{cb = CallbackModule, sock = Sock,
#state{cb = Module, sock = Sock,
server_state = ServerState}};
Error ->
CallbackModule:terminate(Error, ServerState), Error
Error -> Module:terminate(Error, ServerState), Error
end;
Err -> Err
end.

%% @hidden
handle_call(Request, From,
#state{cb = Callback, server_state = ServerState} =
#state{cb = Module, server_state = ServerState} =
State) ->
case Callback:handle_call(Request, From, ServerState) of
case Module:handle_call(Request, From, ServerState) of
{reply, Reply, NewServerState} ->
{reply, Reply,
State#state{server_state = NewServerState}};
Expand All @@ -144,9 +143,9 @@ handle_call(Request, From,

%% @hidden
handle_cast(Msg,
#state{cb = Callback, server_state = ServerState} =
#state{cb = Module, server_state = ServerState} =
State) ->
case Callback:handle_cast(Msg, ServerState) of
case Module:handle_cast(Msg, ServerState) of
{noreply, NewServerState} ->
{noreply, State#state{server_state = NewServerState}};
{noreply, NewServerState, Arg}
Expand All @@ -161,10 +160,10 @@ handle_cast(Msg,
%% @hidden
handle_info({inet_async, ListSock, _Ref,
{ok, CliSocket}},
#state{cb = Callback, server_state = ServerState} =
#state{cb = Module, server_state = ServerState} =
State) ->
inet_db:register_socket(CliSocket, inet_tcp),
case Callback:new_connection(CliSocket, ServerState) of
case Module:new_connection(CliSocket, ServerState) of
{ok, NewServerState} ->
{ok, _} = prim_inet:async_accept(ListSock, -1),
{noreply, State#state{server_state = NewServerState}};
Expand All @@ -173,9 +172,9 @@ handle_info({inet_async, ListSock, _Ref,
State#state{server_state = NewServerState}}
end;
handle_info(Info,
#state{cb = Callback, server_state = ServerState} =
#state{cb = Module, server_state = ServerState} =
State) ->
case Callback:handle_info(Info, ServerState) of
case Module:handle_info(Info, ServerState) of
{noreply, NewServerState} ->
{noreply, State#state{server_state = NewServerState}};
{noreply, NewServerState, Arg}
Expand All @@ -189,10 +188,10 @@ handle_info(Info,

%% @hidden
terminate(Reason,
#state{cb = Callback, sock = Sock,
#state{cb = Module, sock = Sock,
server_state = ServerState}) ->
gen_tcp:close(Sock),
Callback:terminate(Reason, ServerState),
Module:terminate(Reason, ServerState),
ok.

%% @hidden
Expand All @@ -201,28 +200,28 @@ code_change(_OldVsn, State, _Extra) -> {ok, State}.
%% Internal functions

%% @hidden
%% @spec listen_on(CallbackModule, IpAddr, Port) -> Result
%% CallbackModule = atom()
%% @spec listen_on(Module, IpAddr, Port) -> Result
%% Module = atom()
%% IpAddr = string() | tuple()
%% Port = integer()
%% Result = {ok, port()} | {error, any()}
listen_on(CallbackModule, IpAddr, Port)
listen_on(Module, IpAddr, Port)
when is_tuple(IpAddr) andalso
(8 =:= size(IpAddr) orelse 4 =:= size(IpAddr)) ->
SockOpts = [{ip, IpAddr} | CallbackModule:sock_opts()],
SockOpts = [{ip, IpAddr} | Module:sock_opts()],
case gen_tcp:listen(Port, SockOpts) of
{ok, LSock} ->
{ok, _Ref} = prim_inet:async_accept(LSock, -1),
{ok, LSock};
Err -> Err
end;
listen_on(CallbackModule, IpAddrStr, Port) ->
listen_on(Module, IpAddrStr, Port) ->
case inet_parse:address(IpAddrStr) of
{ok, IpAddr} -> listen_on(CallbackModule, IpAddr, Port);
{ok, IpAddr} -> listen_on(Module, IpAddr, Port);
Err ->
logger:critical("Cannot start listener for ~p\n "
" on invalid address "
"~p:~p",
[CallbackModule, IpAddrStr, Port]),
[Module, IpAddrStr, Port]),
Err
end.
Loading

0 comments on commit 4ffcfb7

Please sign in to comment.