Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/custodian/README
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Custodian is responsible for the data stored in CouchDB databases.

Custodian scans the "dbs" database, which details the location of
Custodian scans the shards database, which details the location of
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix!

every shard of every database and ensures that operators are aware of
any shard that is under-replicated (has less than N copies).

Expand Down
3 changes: 2 additions & 1 deletion src/custodian/src/custodian_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ start_shard_checker(#state{shard_checker=Pid}=State) when is_pid(Pid) ->


start_event_listener() ->
DbName = mem3_sync:shards_db(),
couch_event:link_listener(
?MODULE, handle_db_event, nil, [{dbname, <<"dbs">>}]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed this during import 😞

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries! Thanks for taking a look at the PR

?MODULE, handle_db_event, nil, [{dbname, DbName}]
).

handle_db_event(_DbName, updated, _St) ->
Expand Down
7 changes: 3 additions & 4 deletions src/custodian/src/custodian_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
% Old design doc which should be cleaned up
-define(CUSTODIAN_ID, <<"_design/custodian">>).

-record(state, {live, safe, n, callback, db, acc}).
-record(state, {live, safe, callback, db, acc}).

%% public functions.

Expand Down Expand Up @@ -55,10 +55,9 @@ ensure_dbs_exists() ->
fold_dbs(Acc, Fun) ->
Safe = maybe_redirect([node() | nodes()]),
Live = Safe -- maintenance_nodes(Safe),
N = cluster_n(),
{ok, Db} = ensure_dbs_exists(),
try
State0 = #state{live=Live, safe=Safe, n=N, callback=Fun, db=Db, acc=Acc},
State0 = #state{live=Live, safe=Safe, callback=Fun, db=Db, acc=Acc},
{ok, State1} = couch_db:fold_docs(Db, fun fold_dbs1/2, State0, []),
State1#state.acc
after
Expand All @@ -82,9 +81,9 @@ fold_dbs1(#full_doc_info{id = Id} = FDI, State) ->
fold_dbs(Id, Shards, State) ->
IsSafe = fun(#shard{node = N}) -> lists:member(N, State#state.safe) end,
IsLive = fun(#shard{node = N}) -> lists:member(N, State#state.live) end,
TargetN = State#state.n,
LiveShards = lists:filter(IsLive, Shards),
SafeShards = lists:filter(IsSafe, Shards),
TargetN = mem3_util:calculate_max_n(Shards),
Acc0 = State#state.acc,
Acc1 = case mem3_util:calculate_max_n(LiveShards) of
LiveN when LiveN < TargetN ->
Expand Down