anchor.diff:  clean_db(Name, DbId, #{db := Db}) ->
     DbKey = << 0, 0, 0, 100, (barrel_lib:to_binary(Name))/binary >>,
     ok = erocksdb:delete(Db, DbKey, [{sync, true}]),
  -  spawn(fun() -> clean_db1(Db, DbId) end),
  +  _ = spawn(fun() ->
  +          fold_prefix(Db, DbId, fun clean_db_fun/3, {Db, []})
  +        end),
     ok.
  +
  +clean_db_fun(K, _V, {Db, Acc}) ->
  +  Acc2 = [{delete, K} | Acc],
  +  Sz = length(Acc2),
  +  if
  +    Sz >= 500 ->
  +      _ = erocksdb:write(Db, Acc2, []),
  +      {ok, {Db, []}};
  +    true ->
  +      {ok, {Db, Acc2}}
  +  end.
   
   all_dbs(#{db := Db}) ->
     Fun = fun
  
positive.code:         end,
    AllDbs = fold_prefix(Db, << 0, 0, 0, 100 >>, Fun, []),
    lists:usort(AllDbs).
  
  clean_db1(Db, DbId) ->
    (catch clean_db_prefix(Db, DbId)),
    ok.
  
  clean_db_prefix(Db, Prefix) ->
    {ok, Itr} = erocksdb:iterator(Db, []),
    try clean_db_prefix1(erocksdb:iterator_move(Itr, Prefix), Itr, Db, [])
    after erocksdb:iterator_close(Itr)
    end.
  
  clean_db_prefix1({error, iterator_closed}, _Itr, _Db, _Acc) -> ok;
  clean_db_prefix1({error, invalid_iterator}, _Itr, Db, Acc) ->
    erocksdb:write(Db, lists:reverse(Acc), []);
  clean_db_prefix1({ok, K, _V}, Itr, Db, Acc) ->
    Acc2 = [{delete, K} | Acc],
    Sz = length(Acc2),
    if
      Sz >= 500 ->
        _ = erocksdb:write(Db, Acc2, []),
        clean_db_prefix1(erocksdb:iterator_move(Itr, next), Itr, Db, []);
      true ->
        clean_db_prefix1(erocksdb:iterator_move(Itr, next), Itr, Db, Acc2)
    end.
  
  fold_prefix(Db, Prefix, Fun, AccIn) ->
    fold_prefix(Db, Prefix, Fun, AccIn, []).
  
negative.code: get_doc(DbId, DocId, Rev, WithHistory, MaxHistory, HistoryFrom, #{ db := Db}) ->
    {ok, Snapshot} = erocksdb:snapshot(Db),
    ReadOptions = [{snapshot, Snapshot}],
  
    try get_doc1(DbId, DocId, Db, Rev, WithHistory, MaxHistory, HistoryFrom, ReadOptions)
    after erocksdb:release_snapshot(Snapshot)
    end.
  