couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject [1/8] couch commit: updated refs/heads/master to 78f575e
Date Thu, 28 Apr 2016 16:26:07 GMT
Repository: couchdb-couch
Updated Branches:
  refs/heads/master 636d30ace -> 78f575ec2


Allow to specify context of file deletion

Function couch_file:delete/2,3 called on the files both during a user initiated
database deletion and database and view compaction. We want the config
parameter `enable_database_recovery` to be respected for the former,
but not the latter.

To achive that the third attribute in `couch_file:delete/3` changed from
async deletion flag to options list. It might consist tuple {context, Context}
where Context can take value `compaction` (default) or `delete`.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/a2347fbb
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/a2347fbb
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/a2347fbb

Branch: refs/heads/master
Commit: a2347fbbdbf812035edd7b0c4fe54b9851c0828e
Parents: f406dc6
Author: Eric Avdey <eiri@eiri.ca>
Authored: Tue Apr 26 10:58:55 2016 -0300
Committer: Eric Avdey <eiri@eiri.ca>
Committed: Thu Apr 28 13:09:35 2016 -0300

----------------------------------------------------------------------
 src/couch_file.erl        |  8 +++++---
 src/couch_server.erl      |  4 ++--
 test/couch_file_tests.erl | 33 +++++++++++++++++++++++----------
 3 files changed, 30 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/a2347fbb/src/couch_file.erl
----------------------------------------------------------------------
diff --git a/src/couch_file.erl b/src/couch_file.erl
index 8aa4a50..eb5c22e 100644
--- a/src/couch_file.erl
+++ b/src/couch_file.erl
@@ -219,12 +219,14 @@ close(Fd) ->
 
 
 delete(RootDir, Filepath) ->
-    delete(RootDir, Filepath, true).
+    delete(RootDir, Filepath, []).
 
-delete(RootDir, FullFilePath, Async) ->
+delete(RootDir, FullFilePath, Options) ->
     EnableRecovery = config:get_boolean("couchdb",
         "enable_database_recovery", false),
-    case EnableRecovery of
+    Async = not lists:member(sync, Options),
+    Context = couch_util:get_value(context, Options, compaction),
+    case Context =:= delete andalso EnableRecovery of
         true ->
             rename_file(FullFilePath);
         false ->

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/a2347fbb/src/couch_server.erl
----------------------------------------------------------------------
diff --git a/src/couch_server.erl b/src/couch_server.erl
index f280eca..b9a5077 100644
--- a/src/couch_server.erl
+++ b/src/couch_server.erl
@@ -459,8 +459,8 @@ handle_call({delete, DbName, Options}, _From, Server) ->
 
         couch_db_plugin:on_delete(DbName, Options),
 
-        Async = not lists:member(sync, Options),
-        case couch_file:delete(Server#server.root_dir, FullFilepath, Async) of
+        DelOpt = [{context, delete} | Options],
+        case couch_file:delete(Server#server.root_dir, FullFilepath, DelOpt) of
         ok ->
             couch_event:notify(DbName, deleted),
             {reply, ok, Server2};

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/a2347fbb/test/couch_file_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_file_tests.erl b/test/couch_file_tests.erl
index 62f5844..27e0414 100644
--- a/test/couch_file_tests.erl
+++ b/test/couch_file_tests.erl
@@ -295,12 +295,20 @@ delete_test_() ->
             end,
             [
                 fun(Cfg) ->
-                    {"enable_database_recovery = false",
-                    make_enable_recovery_test_case(Cfg, false)}
+                    {"enable_database_recovery = false, context = delete",
+                    make_enable_recovery_test_case(Cfg, false, delete)}
                 end,
                 fun(Cfg) ->
-                    {"enable_database_recovery = true",
-                    make_enable_recovery_test_case(Cfg, true)}
+                    {"enable_database_recovery = true, context = delete",
+                    make_enable_recovery_test_case(Cfg, true, delete)}
+                end,
+                fun(Cfg) ->
+                    {"enable_database_recovery = false, context = compaction",
+                    make_enable_recovery_test_case(Cfg, false, compaction)}
+                end,
+                fun(Cfg) ->
+                    {"enable_database_recovery = true, context = compaction",
+                    make_enable_recovery_test_case(Cfg, true, compaction)}
                 end,
                 fun(Cfg) ->
                     {"delete_after_rename = true",
@@ -315,20 +323,25 @@ delete_test_() ->
     }.
 
 
-make_enable_recovery_test_case({RootDir, File}, EnableRecovery) ->
+make_enable_recovery_test_case({RootDir, File}, EnableRecovery, Context) ->
     meck:expect(config, get_boolean, fun
         ("couchdb", "enable_database_recovery", _) -> EnableRecovery;
-        ("couchdb", "delete_after_rename", _) -> true
+        ("couchdb", "delete_after_rename", _) -> false
     end),
     FileExistsBefore = filelib:is_regular(File),
-    couch_file:delete(RootDir, File, false),
+    couch_file:delete(RootDir, File, [{context, Context}]),
     FileExistsAfter = filelib:is_regular(File),
     RenamedFiles = filelib:wildcard(filename:rootname(File) ++ "*.deleted.*"),
-    ExpectRenamedCount = if EnableRecovery -> 1; true -> 0 end,
+    DeletedFiles = filelib:wildcard(RootDir ++ "/.delete/*"),
+    {ExpectRenamedCount, ExpectDeletedCount} = if
+        EnableRecovery andalso Context =:= delete -> {1, 0};
+        true -> {0, 1}
+    end,
     [
         ?_assert(FileExistsBefore),
         ?_assertNot(FileExistsAfter),
-        ?_assertEqual(ExpectRenamedCount, length(RenamedFiles))
+        ?_assertEqual(ExpectRenamedCount, length(RenamedFiles)),
+        ?_assertEqual(ExpectDeletedCount, length(DeletedFiles))
     ].
 
 make_delete_after_rename_test_case({RootDir, File}, DeleteAfterRename) ->
@@ -337,7 +350,7 @@ make_delete_after_rename_test_case({RootDir, File}, DeleteAfterRename)
->
         ("couchdb", "delete_after_rename", _) -> DeleteAfterRename
     end),
     FileExistsBefore = filelib:is_regular(File),
-    couch_file:delete(RootDir, File, false),
+    couch_file:delete(RootDir, File),
     FileExistsAfter = filelib:is_regular(File),
     RenamedFiles = filelib:wildcard(filename:join([RootDir, ".delete", "*"])),
     ExpectRenamedCount = if DeleteAfterRename -> 0; true -> 1 end,


Mime
View raw message