diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2020-04-05 14:18:59 -0500 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2020-04-05 14:18:59 -0500 |
commit | 07ccd471c52e92b8ffff2b477b8a3ca05578ba18 (patch) | |
tree | 1e4b0ca27359f94a057ecc9149b270fe92605887 | |
parent | 6b1fe068848cbc4ce58e99f524398d922cd981c3 (diff) | |
download | couchdb-07ccd471c52e92b8ffff2b477b8a3ca05578ba18.tar.gz |
Rename and move functions for consistency
-rw-r--r-- | src/fabric/src/fabric2_db.erl | 87 | ||||
-rw-r--r-- | src/fabric/src/fabric2_fdb.erl | 42 |
2 files changed, 54 insertions, 75 deletions
diff --git a/src/fabric/src/fabric2_db.erl b/src/fabric/src/fabric2_db.erl index c94710bd5..82241fbf7 100644 --- a/src/fabric/src/fabric2_db.erl +++ b/src/fabric/src/fabric2_db.erl @@ -23,15 +23,13 @@ list_dbs/1, list_dbs/3, - list_deleted_dbs/0, - list_deleted_dbs/1, - list_deleted_dbs/3, - list_dbs_info/0, list_dbs_info/1, list_dbs_info/3, - deleted_dbs_info/2, + list_deleted_dbs_info/0, + list_deleted_dbs_info/1, + list_deleted_dbs_info/3, check_is_admin/1, check_is_member/1, @@ -270,11 +268,11 @@ list_dbs(UserFun, UserAcc0, Options) -> end). -list_deleted_dbs() -> - list_deleted_dbs([]). +list_dbs_info() -> + list_dbs_info([]). -list_deleted_dbs(Options) -> +list_dbs_info(Options) -> Callback = fun(Value, Acc) -> NewAcc = case Value of {meta, _} -> Acc; @@ -283,30 +281,26 @@ list_deleted_dbs(Options) -> end, {ok, NewAcc} end, - {ok, DbInfos} = list_deleted_dbs(Callback, [], Options), + {ok, DbInfos} = list_dbs_info(Callback, [], Options), {ok, lists:reverse(DbInfos)}. -list_deleted_dbs(UserFun, UserAcc0, Options) -> - FoldFun = fun(DbName, TimeStamp, InfoFuture, {FutureQ, Count, Acc}) -> - NewFutureQ = queue:in({DbName, TimeStamp, InfoFuture}, FutureQ), - drain_deleted_dbs_futures(NewFutureQ, Count + 1, UserFun, Acc) +list_dbs_info(UserFun, UserAcc0, Options) -> + FoldFun = fun(DbName, InfoFuture, {FutureQ, Count, Acc}) -> + NewFutureQ = queue:in({DbName, InfoFuture}, FutureQ), + drain_info_futures(NewFutureQ, Count + 1, UserFun, Acc) end, fabric2_fdb:transactional(fun(Tx) -> try UserAcc1 = maybe_stop(UserFun({meta, []}, UserAcc0)), InitAcc = {queue:new(), 0, UserAcc1}, - {FinalFutureQ, _, UserAcc2} = fabric2_fdb:list_deleted_dbs( + {FinalFutureQ, _, UserAcc2} = fabric2_fdb:list_dbs_info( Tx, FoldFun, InitAcc, Options ), - UserAcc3 = drain_all_deleted_dbs_futures( - FinalFutureQ, - UserFun, - UserAcc2 - ), + UserAcc3 = drain_all_info_futures(FinalFutureQ, UserFun, UserAcc2), {ok, maybe_stop(UserFun(complete, UserAcc3))} catch throw:{stop, FinalUserAcc} -> {ok, FinalUserAcc} @@ -314,11 +308,11 @@ list_deleted_dbs(UserFun, UserAcc0, Options) -> end). -list_dbs_info() -> - list_dbs_info([]). +list_deleted_dbs_info() -> + list_deleted_dbs_info([]). -list_dbs_info(Options) -> +list_deleted_dbs_info(Options) -> Callback = fun(Value, Acc) -> NewAcc = case Value of {meta, _} -> Acc; @@ -327,26 +321,30 @@ list_dbs_info(Options) -> end, {ok, NewAcc} end, - {ok, DbInfos} = list_dbs_info(Callback, [], Options), + {ok, DbInfos} = list_deleted_dbs_info(Callback, [], Options), {ok, lists:reverse(DbInfos)}. -list_dbs_info(UserFun, UserAcc0, Options) -> - FoldFun = fun(DbName, InfoFuture, {FutureQ, Count, Acc}) -> - NewFutureQ = queue:in({DbName, InfoFuture}, FutureQ), - drain_info_futures(NewFutureQ, Count + 1, UserFun, Acc) +list_deleted_dbs_info(UserFun, UserAcc0, Options) -> + FoldFun = fun(DbName, TimeStamp, InfoFuture, {FutureQ, Count, Acc}) -> + NewFutureQ = queue:in({DbName, TimeStamp, InfoFuture}, FutureQ), + drain_deleted_info_futures(NewFutureQ, Count + 1, UserFun, Acc) end, fabric2_fdb:transactional(fun(Tx) -> try UserAcc1 = maybe_stop(UserFun({meta, []}, UserAcc0)), InitAcc = {queue:new(), 0, UserAcc1}, - {FinalFutureQ, _, UserAcc2} = fabric2_fdb:list_dbs_info( + {FinalFutureQ, _, UserAcc2} = fabric2_fdb:list_deleted_db_infos( Tx, FoldFun, InitAcc, Options ), - UserAcc3 = drain_all_info_futures(FinalFutureQ, UserFun, UserAcc2), + UserAcc3 = drain_all_deleted_info_futures( + FinalFutureQ, + UserFun, + UserAcc2 + ), {ok, maybe_stop(UserFun(complete, UserAcc3))} catch throw:{stop, FinalUserAcc} -> {ok, FinalUserAcc} @@ -354,13 +352,6 @@ list_dbs_info(UserFun, UserAcc0, Options) -> end). -deleted_dbs_info(DbName, Options) -> - Result = fabric2_fdb:transactional(DbName, Options, fun(TxDb) -> - fabric2_fdb:deleted_dbs_info(TxDb) - end), - {ok, lists:reverse(Result)}. - - is_admin(Db, {SecProps}) when is_list(SecProps) -> case fabric2_db_plugin:check_is_admin(Db) of true -> @@ -1110,24 +1101,32 @@ make_deleted_dbs_info(DbName, TimeStamp, Props) -> ]. -drain_deleted_dbs_futures(FutureQ, Count, _UserFun, Acc) when Count < 100 -> +drain_deleted_info_futures(FutureQ, Count, _UserFun, Acc) when Count < 100 -> {FutureQ, Count, Acc}; -drain_deleted_dbs_futures(FutureQ, Count, UserFun, Acc) when Count >= 100 -> +drain_deleted_info_futures(FutureQ, Count, UserFun, Acc) when Count >= 100 -> {{value, {DbName, TimeStamp, Future}}, RestQ} = queue:out(FutureQ), - InfoProps = fabric2_fdb:get_info_wait(Future), - DbInfo = make_deleted_dbs_info(DbName, TimeStamp, InfoProps), + BaseProps = fabric2_fdb:get_info_wait(Future), + DeletedProps = BaseProps ++ [ + {deleted, true}, + {deleted_at, TimeStamp} + ], + DbInfo = make_db_info(DbName, DeletedProps), NewAcc = maybe_stop(UserFun({row, DbInfo}, Acc)), {RestQ, Count - 1, NewAcc}. -drain_all_deleted_dbs_futures(FutureQ, UserFun, Acc) -> +drain_all_deleted_info_futures(FutureQ, UserFun, Acc) -> case queue:out(FutureQ) of {{value, {DbName, TimeStamp, Future}}, RestQ} -> - InfoProps = fabric2_fdb:get_info_wait(Future), - DbInfo = make_deleted_dbs_info(DbName, TimeStamp, InfoProps), + BaseProps = fabric2_fdb:get_info_wait(Future), + DeletedProsp = BaseProps ++ [ + {deleted, true}, + {deleted_at, TimeStamp} + ], + DbInfo = make_db_info(DbName, DeletedProps), NewAcc = maybe_stop(UserFun({row, DbInfo}, Acc)), - drain_all_deleted_dbs_futures(RestQ, UserFun, NewAcc); + drain_all_deleted_info_futures(RestQ, UserFun, NewAcc); {empty, _} -> Acc end. diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl index 19091b153..cd51161c2 100644 --- a/src/fabric/src/fabric2_fdb.erl +++ b/src/fabric/src/fabric2_fdb.erl @@ -30,10 +30,7 @@ list_dbs/4, list_dbs_info/4, - - list_deleted_dbs/4, - - deleted_dbs_info/1, + list_deleted_dbs_info/4, get_info/1, get_info_future/2, @@ -443,51 +440,34 @@ list_dbs(Tx, Callback, AccIn, Options0) -> end, AccIn, Options). -list_deleted_dbs(Tx, Callback, AccIn, Options0) -> +list_dbs_info(Tx, Callback, AccIn, Options0) -> Options = case fabric2_util:get_value(restart_tx, Options0) of undefined -> [{restart_tx, true} | Options0]; _AlreadySet -> Options0 end, LayerPrefix = get_dir(Tx), - Prefix = erlfdb_tuple:pack({?DELETED_DBS}, LayerPrefix), - fold_range({tx, Tx}, Prefix, fun({DbKey, DbPrefix}, Acc) -> - {DbName, TimeStamp} = erlfdb_tuple:unpack(DbKey, Prefix), + Prefix = erlfdb_tuple:pack({?ALL_DBS}, LayerPrefix), + fold_range({tx, Tx}, Prefix, fun({DbNameKey, DbPrefix}, Acc) -> + {DbName} = erlfdb_tuple:unpack(DbNameKey, Prefix), InfoFuture = get_info_future(Tx, DbPrefix), - Callback(DbName, TimeStamp, InfoFuture, Acc) + Callback(DbName, InfoFuture, Acc) end, AccIn, Options). -list_dbs_info(Tx, Callback, AccIn, Options0) -> +list_deleted_db_infos(Tx, Callback, AccIn, Options0) -> Options = case fabric2_util:get_value(restart_tx, Options0) of undefined -> [{restart_tx, true} | Options0]; _AlreadySet -> Options0 end, LayerPrefix = get_dir(Tx), - Prefix = erlfdb_tuple:pack({?ALL_DBS}, LayerPrefix), - fold_range({tx, Tx}, Prefix, fun({DbNameKey, DbPrefix}, Acc) -> - {DbName} = erlfdb_tuple:unpack(DbNameKey, Prefix), + Prefix = erlfdb_tuple:pack({?DELETED_DBS}, LayerPrefix), + fold_range({tx, Tx}, Prefix, fun({DbKey, DbPrefix}, Acc) -> + {DbName, TimeStamp} = erlfdb_tuple:unpack(DbKey, Prefix), InfoFuture = get_info_future(Tx, DbPrefix), - Callback(DbName, InfoFuture, Acc) + Callback(DbName, TimeStamp, InfoFuture, Acc) end, AccIn, Options). -deleted_dbs_info(#{} = Db0) -> - #{ - name := DbName, - tx := Tx, - layer_prefix := LayerPrefix - } = ensure_current(Db0, false), - - DeletedDbKey = erlfdb_tuple:pack({?DELETED_DBS, DbName}, LayerPrefix), - DeletedDbs = erlfdb:wait(erlfdb:get_range_startswith(Tx, DeletedDbKey)), - lists:foldl(fun({DbKey, DbPrefix}, Acc) -> - DBInfo = get_info_wait(get_info_future(Tx, DbPrefix)), - {?DELETED_DBS, DbName, DeletedTS} = - erlfdb_tuple:unpack(DbKey, LayerPrefix), - [{DeletedTS, DBInfo}| Acc] - end, [], DeletedDbs). - - get_info(#{} = Db) -> #{ tx := Tx, |