couchdb-dev mailing list archives

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

    https://github.com/apache/couchdb-couch/pull/27#discussion_r22413779
  
    --- 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 --
    
    I though couchdb uses the files from .delete directory for recovery from crash. It looks
like I was wrong.  


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