Skip to content

Commit

Permalink
Fix for occasional failed tests caused by responding with 202 success…
Browse files Browse the repository at this point in the history
… to compaction requests before the compaction actually begins.

git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/0.11.x@961906 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jchris committed Jul 8, 2010
1 parent 4f87e08 commit 8d89fa5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/couchdb/couch_db.erl
Expand Up @@ -103,7 +103,7 @@ monitor(#db{main_pid=MainPid}) ->
erlang:monitor(process, MainPid).

start_compact(#db{update_pid=Pid}) ->
gen_server:cast(Pid, start_compact).
gen_server:call(Pid, start_compact).

delete_doc(Db, Id, Revisions) ->
DeletedDocs = [#doc{id=Id, revs=[Rev], deleted=true} || Rev <- Revisions],
Expand Down
15 changes: 8 additions & 7 deletions src/couchdb/couch_db_updater.erl
Expand Up @@ -133,21 +133,22 @@ handle_call({purge_docs, IdRevs}, _From, Db) ->

ok = gen_server:call(Db2#db.main_pid, {db_updated, Db2}),
couch_db_update_notifier:notify({updated, Db#db.name}),
{reply, {ok, (Db2#db.header)#db_header.purge_seq, IdRevsPurged}, Db2}.


handle_cast(start_compact, Db) ->
{reply, {ok, (Db2#db.header)#db_header.purge_seq, IdRevsPurged}, Db2};
handle_call(start_compact, _From, Db) ->
case Db#db.compactor_pid of
nil ->
?LOG_INFO("Starting compaction for db \"~s\"", [Db#db.name]),
Pid = spawn_link(fun() -> start_copy_compact(Db) end),
Db2 = Db#db{compactor_pid=Pid},
ok = gen_server:call(Db#db.main_pid, {db_updated, Db2}),
{noreply, Db2};
{reply, ok, Db2};
_ ->
% compact currently running, this is a no-op
{noreply, Db}
end;
{reply, ok, Db}
end.



handle_cast({compact_done, CompactFilepath}, #db{filepath=Filepath}=Db) ->
{ok, NewFd} = couch_file:open(CompactFilepath),
{ok, NewHeader} = couch_file:read_header(NewFd),
Expand Down

0 comments on commit 8d89fa5

Please sign in to comment.