couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnewson <...@git.apache.org>
Subject [GitHub] couchdb-couch pull request: Modify init_delete_dir to be async
Date Fri, 02 Jan 2015 17:34:13 GMT
Github user rnewson commented on a diff in the pull request:

    https://github.com/apache/couchdb-couch/pull/27#discussion_r22416091
  
    --- Diff: src/couch_file.erl ---
    @@ -257,13 +257,43 @@ nuke_dir(RootDelDir, Dir) ->
     
     init_delete_dir(RootDir) ->
         Dir = filename:join(RootDir,".delete"),
    -    % note: ensure_dir requires an actual filename companent, which is the
    -    % reason for "foo".
    -    filelib:ensure_dir(filename:join(Dir,"foo")),
    +    ensure_dir(Dir),
    +    TmpDir = make_temp_name(Dir),
    +    % rename original directory so we can return and delete files asynchronously
    +    ok = file:rename(Dir, TmpDir),
    +    % recreate original directory
    +    ensure_dir(Dir),
    +    spawn(fun() -> delete_temp_dirs(RootDir, Dir) end),
    +    ok.
    +
    +
    +make_temp_name(Prefix) ->
    +    {A,B,C} = now(),
    +    lists:flatten(io_lib:format("~s.tmp-~p.~p.~p",[Prefix, A, B, C])).
    +
    +
    +delete_temp_dirs(RootDir, Prefix) ->
    +    Dirs = filelib:wildcard(Prefix ++ ".tmp-" ++ "*", RootDir),
    +    [ok = delete_dir(Dir) || Dir <- Dirs],
    +    ok.
    +
    +
    +ensure_dir(Dir) ->
    +    filelib:ensure_dir(Dir ++ "/").
    --- End diff --
    
    anything in .delete can be deleted. Prior to the .delete dir, couchdb just called 'rm'.
.delete exists so we can delete asynchronously rather than block. It's definitely not used
for recovery.
    
    Given this, I think the PR is far simpler? Just spawn the process that deletes the contents
of the .delete file.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message