jiangphcn commented on a change in pull request #2666: [WIP] soft-deletion for
database
URL: https://github.com/apache/couchdb/pull/2666#discussion_r394975071
##########
File path: src/fabric/src/fabric2_fdb.erl
##########
@@ -314,12 +317,65 @@ delete(#{} = Db) ->
} = ensure_current(Db),
DbKey = erlfdb_tuple:pack({?ALL_DBS, DbName}, LayerPrefix),
- erlfdb:clear(Tx, DbKey),
- erlfdb:clear_range_startswith(Tx, DbPrefix),
+ DoRecovery = fabric_util:do_recovery(),
+ case DoRecovery of
+ true ->
+ {Mega, Secs, _} = os:timestamp(),
+ NowSecs = Mega * 1000000 + Secs,
+ DeletedDbKey = erlfdb_tuple:pack({?DELETED_DBS, DbName, NowSecs},
+ LayerPrefix),
+ erlfdb:set(Tx, DeletedDbKey, DbPrefix),
+ erlfdb:clear(Tx, DbKey);
+ false ->
+ erlfdb:clear(Tx, DbKey),
+ erlfdb:clear_range_startswith(Tx, DbPrefix)
+ end,
bump_metadata_version(Tx),
ok.
+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| Acc]
+ end, [], DeletedDbs).
+
+
+restore(#{} = Db0, [DeletedTS|_]) ->
Review comment:
No, trailing path items will not be used. Just think not too strict here.
But I can change to be strict by removing `|_`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services