davisp commented on a change in pull request #2666: soft-deletion for database
URL: https://github.com/apache/couchdb/pull/2666#discussion_r400289710
 
 

 ##########
 File path: src/fabric/src/fabric2_fdb.erl
 ##########
 @@ -346,12 +351,97 @@ delete(#{} = Db) ->
     } = ensure_current(Db),
 
     DbKey = erlfdb_tuple:pack({?ALL_DBS, DbName}, LayerPrefix),
-    erlfdb:clear(Tx, DbKey),
-    erlfdb:clear_range_startswith(Tx, DbPrefix),
+    DoRecovery = fabric2_util:do_recovery(),
+    case DoRecovery of
+        true ->
+            Timestamp = list_to_binary(fabric2_util:iso8601_timestamp()),
+            DeletedDbKey = erlfdb_tuple:pack({?DELETED_DBS, DbName, Timestamp},
+                LayerPrefix),
+            case erlfdb:wait(erlfdb:get(Tx, DeletedDbKey)) of
+                not_found ->
+                    erlfdb:set(Tx, DeletedDbKey, DbPrefix),
+                    erlfdb:clear(Tx, DbKey);
+                _Val ->
+                    erlang:error({deleted_database_exists, DbName})
+            end;
+        false ->
+            erlfdb:clear(Tx, DbKey),
+            erlfdb:clear_range_startswith(Tx, DbPrefix)
+    end,
     bump_metadata_version(Tx),
     ok.
 
 
+deleted_dbs_info(#{} = Db0) ->
 
 Review comment:
   Make sure we move this implementation to match the exports order.

----------------------------------------------------------------
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

Reply via email to