diff options
author | Eric Avdey <eiri@eiri.ca> | 2017-04-03 15:48:12 -0300 |
---|---|---|
committer | Jay Doane <jay.s.doane@gmail.com> | 2017-04-19 11:23:30 -0700 |
commit | 1c945229948a9257f98443784f2d2f2a2a556ac1 (patch) | |
tree | 7eb5ef113b828959bdbdcdc3f7570b6a3fc8deed | |
parent | 80963ca3e4469e65bbc12d917c3e6dd8b5e32e1d (diff) | |
download | couchdb-1c945229948a9257f98443784f2d2f2a2a556ac1.tar.gz |
Add function to clean up after failed compaction
-rw-r--r-- | src/couch_mrview/src/couch_mrview_compactor.erl | 9 | ||||
-rw-r--r-- | src/couch_mrview/src/couch_mrview_index.erl | 6 | ||||
-rw-r--r-- | src/couch_mrview/test/couch_mrview_compact_tests.erl | 32 |
3 files changed, 44 insertions, 3 deletions
diff --git a/src/couch_mrview/src/couch_mrview_compactor.erl b/src/couch_mrview/src/couch_mrview_compactor.erl index 9ef79b664..fabe2894c 100644 --- a/src/couch_mrview/src/couch_mrview_compactor.erl +++ b/src/couch_mrview/src/couch_mrview_compactor.erl @@ -15,7 +15,7 @@ -include_lib("couch/include/couch_db.hrl"). -include_lib("couch_mrview/include/couch_mrview.hrl"). --export([compact/3, swap_compacted/2]). +-export([compact/3, swap_compacted/2, remove_compacted/1]). -record(acc, { btree = nil, @@ -294,6 +294,13 @@ swap_compacted(OldState, NewState) -> {ok, NewState#mrst{fd_monitor=Ref}}. +remove_compacted(#mrst{sig = Sig, db_name = DbName} = State) -> + RootDir = couch_index_util:root_dir(), + CompactFName = couch_mrview_util:compaction_file(DbName, Sig), + ok = couch_file:delete(RootDir, CompactFName), + {ok, State}. + + -ifdef(TEST). -include_lib("eunit/include/eunit.hrl"). diff --git a/src/couch_mrview/src/couch_mrview_index.erl b/src/couch_mrview/src/couch_mrview_index.erl index 0473d5dd2..eaec5cc52 100644 --- a/src/couch_mrview/src/couch_mrview_index.erl +++ b/src/couch_mrview/src/couch_mrview_index.erl @@ -16,7 +16,7 @@ -export([get/2]). -export([init/2, open/2, close/1, reset/1, delete/1]). -export([start_update/3, purge/4, process_doc/3, finish_update/1, commit/1]). --export([compact/3, swap_compacted/2]). +-export([compact/3, swap_compacted/2, remove_compacted/1]). -export([index_file_exists/1]). -include_lib("couch/include/couch_db.hrl"). @@ -184,6 +184,10 @@ swap_compacted(OldState, NewState) -> couch_mrview_compactor:swap_compacted(OldState, NewState). +remove_compacted(State) -> + couch_mrview_compactor:remove_compacted(State). + + index_file_exists(State) -> #mrst{ db_name=DbName, diff --git a/src/couch_mrview/test/couch_mrview_compact_tests.erl b/src/couch_mrview/test/couch_mrview_compact_tests.erl index 079639f5d..a05a68df2 100644 --- a/src/couch_mrview/test/couch_mrview_compact_tests.erl +++ b/src/couch_mrview/test/couch_mrview_compact_tests.erl @@ -38,7 +38,8 @@ compaction_test_() -> foreach, fun setup/0, fun teardown/1, [ - fun should_swap/1 + fun should_swap/1, + fun should_remove/1 ] } } @@ -71,6 +72,35 @@ should_swap(Db) -> end). +should_remove(Db) -> + ?_test(begin + DDoc = <<"_design/bar">>, + couch_mrview:query_view(Db, DDoc, <<"baz">>), + {ok, Pid} = couch_index_server:get_index(couch_mrview_index, Db, DDoc), + ok = couch_index:compact(Pid, []), + {ok, CPid} = couch_index:get_compactor_pid(Pid), + Info = recon:info(CPid), + Ancs = couch_util:get_value('$ancestors', + couch_util:get_value(dictionary, + couch_util:get_value(meta, Info))), + Links = couch_util:get_value(links, + couch_util:get_value(signals, Info)), + [CompactionPid] = Links -- Ancs, + MonRef = erlang:monitor(process, CompactionPid), + exit(CompactionPid, crash), + receive + {'DOWN', MonRef, process, _, crash} -> + ?assert(is_process_alive(Pid)), + ?assert(is_process_alive(CPid)) + after ?TIMEOUT -> + erlang:error( + {assertion_failed, + [{module, ?MODULE}, {line, ?LINE}, + {reason, "compaction didn't failed :/"}]}) + end + end). + + start_query(Db) -> Self = self(), Pid = spawn(fun() -> |