Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add token management to Background manager. #361

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e1e1b1a
update hash functions
evanmcc Jul 9, 2013
184b06f
unbreak releases earlier than R16
evanmcc Jul 11, 2013
30ceb0a
up chbin timeout for slower computers
evanmcc Jul 15, 2013
ee3a7f4
Reverse hash logic and use rebar.config.script
Vagabond Jul 18, 2013
3997b00
bump webmachine tag
evanmcc Jul 18, 2013
86377ce
Merge pull request #348 from basho/pevm-r16-compat
evanmcc Jul 18, 2013
33e0779
Fix catch pattern to match all errors
russelldb Jul 29, 2013
af20e80
Fix TCP mon to correctly spot nodes coming up.
Jul 30, 2013
eea9d61
Merge pull request #352 from basho/jdm-tcp-mon-add-dist-fix
Jul 30, 2013
583545d
Merge pull request #351 from basho/gh350-vnodeq-stats
russelldb Jul 31, 2013
de4527e
Roll version 1.4.1
rzezeski Aug 1, 2013
ad6337c
Merge branch '1.4'
jaredmorrow Aug 13, 2013
6b448d1
Initial API of token manager + bg proxy calls
buddhisthead Aug 22, 2013
fb2fd63
Initial API of token manager + bg proxy calls
buddhisthead Aug 22, 2013
7d855f8
Update rebar.config for new branching model
jtuple Aug 23, 2013
0551be9
Update protobuffs, webmachine, folsom tags
jtuple Aug 24, 2013
b70be44
Update webmachine dependency tag
jtuple Aug 24, 2013
3fd7251
Finish API and add unit tests.
buddhisthead Aug 29, 2013
2763efa
Add head(Token) unit test
buddhisthead Aug 29, 2013
4ad05bf
Copyright for include file
buddhisthead Aug 29, 2013
2dcc0b1
WIP
jrwest Jul 16, 2013
c859cef
* added enable/disable
jrwest Jul 16, 2013
817fe61
* lock & type querying
jrwest Jul 17, 2013
4672e13
supervise bg manager
jrwest Jul 17, 2013
98e732b
migrate handoff manager to bg manager
jrwest Jul 17, 2013
0d3d188
remove addressed TODOs
jrwest Jul 17, 2013
b8fde9a
Initial API of token manager + bg proxy calls
buddhisthead Aug 22, 2013
0c0b869
Initial API of token manager + bg proxy calls
buddhisthead Aug 22, 2013
d6556b2
Finish API and add unit tests.
buddhisthead Aug 29, 2013
ed2926d
Add head(Token) unit test
buddhisthead Aug 29, 2013
bb9fccf
Copyright for include file
buddhisthead Aug 29, 2013
380a14d
Fix token manager API calls from background manager
buddhisthead Aug 30, 2013
7bf0d9d
Merge conflicts
buddhisthead Aug 30, 2013
19abe9a
Add table manager and use ETS for storing token info
buddhisthead Sep 4, 2013
3cf55bc
Move blocked and given lists to ETS.
buddhisthead Sep 5, 2013
03c4e58
Add crash/restart test and reschedule token rates on restart
buddhisthead Sep 5, 2013
7a2cec3
Migrate Lock Manager's info data to an ETS table
buddhisthead Sep 5, 2013
68c3abe
Add table, lock and token managers to core's supervision tree.
buddhisthead Sep 6, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -7,7 +7,7 @@ PULSE_TESTS = worker_pool_pulse

all: deps compile

compile:
compile:
./rebar compile

deps:
Expand All @@ -19,7 +19,7 @@ clean:
distclean: clean
./rebar delete-deps

test: all
test: all
./rebar skip_deps=true eunit

# You should 'clean' before your first run of this target
Expand Down
7 changes: 5 additions & 2 deletions ebin/riak_core.app
Expand Up @@ -3,7 +3,7 @@
{application, riak_core,
[
{description, "Riak Core"},
{vsn, "1.4.0"},
{vsn, "1.4.1"},
{modules, [
app_helper,
bloom,
Expand Down Expand Up @@ -87,7 +87,10 @@
riak_core_ssl_util,
supervisor_pre_r14b04,
vclock,
riak_core_bg_manager
riak_core_bg_manager,
riak_core_token_manager,
riak_core_table_manager,
riak_core_bg_manager_sup
]},
{registered, []},
{included_applications, [folsom]},
Expand Down
23 changes: 23 additions & 0 deletions include/riak_core_bg_manager.hrl
@@ -0,0 +1,23 @@
%% -------------------------------------------------------------------
%%
%% Copyright (c) 2013 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.
%%
%% -------------------------------------------------------------------
-define(LM_ETS_TABLE, lock_mgr_table). %% name of private lock manager ETS table
-define(LM_ETS_OPTS, [private, bag]). %% creation time properties of lock manager ETS table

-type concurrency_limit() :: non_neg_integer() | infinity.
53 changes: 53 additions & 0 deletions include/riak_core_token_manager.hrl
@@ -0,0 +1,53 @@
%% -------------------------------------------------------------------
%%
%% Copyright (c) 2013 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.
%%
%% -------------------------------------------------------------------
-type tm_token() :: any().
-type tm_meta() :: {atom(), any()}. %% meta data to associate with a token
-type tm_period() :: pos_integer(). %% refill period in milliseconds
-type tm_count() :: pos_integer(). %% refill tokens to count at each refill period
-type tm_rate() :: {tm_period(), tm_count()}. %% token refresh rate
-type tm_stat_event() :: refill_event | give_event. %% stat event type

%% Results of a "ps" of live given or blocked tokens
-record(tm_stat_live,
{
token :: tm_token(), %% token type
consumer :: pid(), %% process asking for token
meta :: [tm_meta()], %% associated meta data
state :: given | blocked | failed %% result of last request
}).
-type tm_stat_live() :: #tm_stat_live{}.

%% Results of a "head" or "tail", per token
-record(tm_stat_hist,
{
limit :: tm_count(), %% maximum available, defined by token rate during interval
refills :: tm_count(), %% number of times this token was refilled during interval
given :: tm_count(), %% number of this token type given in interval
blocked :: tm_count() %% number of blocked processes waiting for a token
}).
-type tm_stat_hist() :: #tm_stat_hist{}.
-define(DEFAULT_TM_STAT_HIST,
#tm_stat_hist{limit=0, refills=0, given=0, blocked=0}).

-define(DEFAULT_TM_SAMPLE_WINDOW, 60). %% in seconds
-define(DEFAULT_TM_OUTPUT_SAMPLES, 20). %% default number of sample windows displayed
-define(DEFAULT_TM_KEPT_SAMPLES, 10000). %% number of history samples to keep
-define(TM_ETS_TABLE, token_mgr_table). %% name of private token manager ETS table
-define(TM_ETS_OPTS, [private, bag]). %% creation time properties of token manager ETS table
12 changes: 6 additions & 6 deletions rebar.config
Expand Up @@ -6,14 +6,14 @@

{deps, [
{lager, "2.0.0", {git, "git://github.com/basho/lager", {tag, "2.0.0"}}},
{poolboy, ".*", {git, "git://github.com/basho/poolboy", {branch, "master"}}},
{poolboy, ".*", {git, "git://github.com/basho/poolboy", {branch, "develop"}}},
{protobuffs, "0.8.*", {git, "git://github.com/basho/erlang_protobuffs",
{branch, "master"}}},
{basho_stats, ".*", {git, "git://github.com/basho/basho_stats", "HEAD"}},
{riak_sysmon, ".*", {git, "git://github.com/basho/riak_sysmon", {branch, "master"}}},
{tag, "0.8.1p1"}}},
{basho_stats, ".*", {git, "git://github.com/basho/basho_stats", {branch, "develop"}}},
{riak_sysmon, ".*", {git, "git://github.com/basho/riak_sysmon", {branch, "develop"}}},
{webmachine, ".*", {git, "git://github.com/basho/webmachine",
{tag, "64176ef9b"}}},
{folsom, ".*", {git, "git://github.com/basho/folsom.git", {tag, "0.7.4p1"}}},
{tag, "1.10.4p1"}}},
{folsom, ".*", {git, "git://github.com/basho/folsom.git", {tag, "0.7.4p2"}}},
{ranch, "0.4.0-p1", {git, "git://github.com/basho/ranch.git", {tag, "0.4.0-p1"}}}

]}.
11 changes: 11 additions & 0 deletions rebar.config.script
@@ -0,0 +1,11 @@
case erlang:system_info(otp_release) =< "R15B01" of
true ->
HashDefine = [{d,old_hash}],
case lists:keysearch(erl_opts, 1, CONFIG) of
{value, {erl_opts, Opts}} ->
lists:keyreplace(erl_opts,1,CONFIG,{erl_opts,Opts++HashDefine});
false ->
CONFIG ++ [{erl_opts, HashDefine}]
end;
false -> CONFIG
end.
10 changes: 9 additions & 1 deletion src/chash.erl
Expand Up @@ -97,12 +97,20 @@ lookup(IndexAsInt, CHash) ->
{IndexAsInt, X} = proplists:lookup(IndexAsInt, Nodes),
X.

-ifndef(old_hash).
sha(Bin) ->
crypto:hash(sha, Bin).
-else.
sha(Bin) ->
crypto:sha(Bin).
-endif.

%% @doc Given any term used to name an object, produce that object's key
%% into the ring. Two names with the same SHA-1 hash value are
%% considered the same name.
-spec key_of(ObjectName :: term()) -> index().
key_of(ObjectName) ->
crypto:sha(term_to_binary(ObjectName)).
sha(term_to_binary(ObjectName)).

%% @doc Return all Nodes that own any partitions in the ring.
-spec members(CHash :: chash()) -> [chash_node()].
Expand Down
5 changes: 5 additions & 0 deletions src/merkerl.erl
Expand Up @@ -323,8 +323,13 @@ contains_node(Tree,Node) ->
getkids(Tree) ->
[V || {_K,V} <- orddict:to_list(Tree#merk.children)].

-ifndef(old_hash).
sha(X) ->
crypto:hash(sha, term_to_binary(X)).
-else.
sha(X) ->
crypto:sha(term_to_binary(X)).
-endif.

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
Expand Down
2 changes: 1 addition & 1 deletion src/riak_core_apl.erl
Expand Up @@ -325,7 +325,7 @@ six_node_test() ->
ok.

chbin_test_() ->
{timeout, 60, fun chbin_test_scenario/0}.
{timeout, 180, fun chbin_test_scenario/0}.

chbin_test_scenario() ->
[chbin_test_scenario(Size, NumNodes)
Expand Down