2015-03-31 07:46:03 +00:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
%%
|
|
|
|
%% Copyright (c) 2007-2014 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.
|
|
|
|
%%
|
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
|
2015-04-09 03:16:58 +00:00
|
|
|
-ifndef(MACHI_PROJECTION_HRL).
|
|
|
|
-define(MACHI_PROJECTION_HRL, true).
|
|
|
|
|
2015-05-17 14:48:05 +00:00
|
|
|
-type pv1_consistency_mode() :: 'ap_mode' | 'cp_mode'.
|
2015-12-07 05:41:56 +00:00
|
|
|
-type pv1_chain_name():: atom().
|
2015-04-02 07:05:06 +00:00
|
|
|
-type pv1_csum() :: binary().
|
|
|
|
-type pv1_epoch() :: {pv1_epoch_n(), pv1_csum()}.
|
|
|
|
-type pv1_epoch_n() :: non_neg_integer().
|
2015-12-07 05:41:56 +00:00
|
|
|
-type pv1_server() :: atom().
|
2015-04-02 07:05:06 +00:00
|
|
|
-type pv1_timestamp() :: {non_neg_integer(), non_neg_integer(), non_neg_integer()}.
|
2015-04-02 05:17:57 +00:00
|
|
|
|
2015-04-09 03:16:58 +00:00
|
|
|
-record(p_srvr, {
|
|
|
|
name :: pv1_server(),
|
2015-05-17 07:18:30 +00:00
|
|
|
proto_mod = 'machi_flu1_client' :: atom(), % Module name
|
2015-04-09 03:16:58 +00:00
|
|
|
address :: term(), % Protocol-specific
|
|
|
|
port :: term(), % Protocol-specific
|
|
|
|
props = [] :: list() % proplist for other related info
|
|
|
|
}).
|
|
|
|
|
2015-06-02 11:32:52 +00:00
|
|
|
-record(flap_i, {
|
|
|
|
flap_count :: {term(), term()},
|
|
|
|
all_hosed :: list(),
|
2015-08-24 10:04:26 +00:00
|
|
|
all_flap_counts :: list(),
|
|
|
|
my_unique_prop_count :: non_neg_integer()
|
2015-06-02 11:32:52 +00:00
|
|
|
}).
|
|
|
|
|
2015-04-09 03:16:58 +00:00
|
|
|
-type p_srvr() :: #p_srvr{}.
|
2015-04-09 12:32:04 +00:00
|
|
|
-type p_srvr_dict() :: orddict:orddict().
|
2015-04-09 03:16:58 +00:00
|
|
|
|
2015-04-02 09:08:42 +00:00
|
|
|
-define(DUMMY_PV1_EPOCH, {0,<<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>>}).
|
|
|
|
|
2015-09-04 09:51:01 +00:00
|
|
|
%% Kludge for spam gossip. TODO: replace me
|
2015-09-07 06:38:23 +00:00
|
|
|
-define(SPAM_PROJ_EPOCH, ((1 bsl 32) - 7)).
|
2015-09-04 09:51:01 +00:00
|
|
|
|
2015-04-02 07:05:06 +00:00
|
|
|
-record(projection_v1, {
|
2015-09-04 09:51:01 +00:00
|
|
|
epoch_number :: pv1_epoch_n() | ?SPAM_PROJ_EPOCH,
|
2015-04-02 07:05:06 +00:00
|
|
|
epoch_csum :: pv1_csum(),
|
2015-04-10 12:59:56 +00:00
|
|
|
author_server :: pv1_server(),
|
2015-12-07 05:41:56 +00:00
|
|
|
chain_name = ch_not_def_yet :: pv1_chain_name(),
|
2015-04-02 07:05:06 +00:00
|
|
|
all_members :: [pv1_server()],
|
2015-07-21 09:43:59 +00:00
|
|
|
witnesses = [] :: [pv1_server()],
|
2015-04-14 06:30:24 +00:00
|
|
|
creation_time :: pv1_timestamp(),
|
2015-05-17 14:48:05 +00:00
|
|
|
mode = ap_mode :: pv1_consistency_mode(),
|
2015-04-02 07:05:06 +00:00
|
|
|
upi :: [pv1_server()],
|
|
|
|
repairing :: [pv1_server()],
|
2015-04-14 06:30:24 +00:00
|
|
|
down :: [pv1_server()],
|
2015-04-02 07:05:06 +00:00
|
|
|
dbg :: list(), %proplist(), is checksummed
|
2015-04-10 12:59:56 +00:00
|
|
|
dbg2 :: list(), %proplist(), is not checksummed
|
|
|
|
members_dict :: p_srvr_dict()
|
2015-04-02 07:05:06 +00:00
|
|
|
}).
|
|
|
|
|
|
|
|
-define(MACHI_DEFAULT_TCP_PORT, 50000).
|
|
|
|
|
2015-03-31 07:46:03 +00:00
|
|
|
-define(SHA_MAX, (1 bsl (20*8))).
|
2015-04-09 03:16:58 +00:00
|
|
|
|
Chain manager bug fixes & enhancment (more...)
* Set max length of a chain at -define(MAX_CHAIN_LENGTH, 64).
* Perturb tick sleep time of each manager
* If a chain manager L has zero members in its chain, and then its local
public projection store (authored by some remote author R) has a projection
that contains L, then adopt R's projection and start humming consensus.
* Handle "cross-talk" across projection stores, when chain membership
is changed administratively, e.g. chain was [a,b,c] then changed to merely
[a], but that change only happens on a. Servers b & c continue to use
stale projections and scribble their projection suggestions to a, causing
it to flap.
What's really cool about the flapping handling is that it *works*. I
wasn't thinking about this scenario when designing the flapping logic, but
it's really nifty that this extra scenario causes a to flap and then a's
inner projection remains stable, yay!
* Add complaints when "cross-talk" is observed.
* Fix flapping sleep time throttle.
* Fix bug in the machi_projection_store.erl's bookkeeping of the
max epoch number when flapping.
2015-05-11 09:41:45 +00:00
|
|
|
%% Set a limit to the maximum chain length, so that it's easier to
|
|
|
|
%% create a consistent projection ranking score.
|
|
|
|
-define(MAX_CHAIN_LENGTH, 64).
|
|
|
|
|
2015-12-04 08:47:18 +00:00
|
|
|
-record(chain_def_v1, {
|
|
|
|
name :: atom(),
|
|
|
|
mode :: pv1_consistency_mode(),
|
Bootstrap chain @ app init: done, with an example.
For example:
% make clean
% make stage
And then configure 3 FLUs:
% echo '{p_srvr, a, machi_flu1_client, "localhost", 39000, []}.' > rel/machi/etc/flu-config/a
% echo '{p_srvr, b, machi_flu1_client, "localhost", 39001, []}.' > rel/machi/etc/flu-config/b
% echo '{p_srvr, c, machi_flu1_client, "localhost", 39002, []}.' > rel/machi/etc/flu-config/c
And then configure a chain to use 2 of those 3 FLUs:
% echo '{chain_def_v1,c1,ap_mode,[{p_srvr,a,machi_flu1_client,"localhost",39000,[]},{p_srvr,b,machi_flu1_client,"localhost",39001,[]}],[],[]}.' > rel/machi/etc/chain-config/c1
... then start Machi e.g.
% ./rel/machi/bin/machi console
... you should see the following console messages scroll by (including a :
=PROGRESS REPORT==== 8-Dec-2015::22:01:44 ===
supervisor: {local,machi_flu_sup}
started: [{pid,<0.145.0>},
{name,a},
{mfargs,
{machi_flu_psup,start_link,
[a,39000,"./data/flu/a",[]]}},
{restart_type,permanent},
{shutdown,5000},
{child_type,supervisor}]
[... and also for the other two FLUs, including a bunch of progress
reports for processes that started underneath that sub-supervisor.]
22:01:44.446 [info] Running FLUs: [a,b,c]
22:01:44.446 [info] Running FLUs at epoch 0: [a,b,c]
22:01:44.532 [warning] The following FLUs are defined but are not also members of a defined chain: [c]
2015-12-08 12:16:54 +00:00
|
|
|
full :: [p_srvr()],
|
|
|
|
witnesses :: [p_srvr()],
|
2015-12-09 15:12:34 +00:00
|
|
|
old_all :: [pv1_server()], % guard against some races
|
|
|
|
old_witnesses :: [pv1_server()], % guard against some races
|
|
|
|
local_run :: [pv1_server()], % must be tailored to each machine!
|
|
|
|
local_stop :: [pv1_server()], % must be tailored to each machine!
|
|
|
|
props = [] :: list() % proplist for other related info
|
2015-12-04 08:47:18 +00:00
|
|
|
}).
|
|
|
|
|
2015-04-09 03:16:58 +00:00
|
|
|
-endif. % !MACHI_PROJECTION_HRL
|