Repository: couchdb-chttpd Updated Branches: refs/heads/master 3509b9153 -> 68f8fa50d
Implement clustered _compact endpoint COUCHDB-3099 Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/68f8fa50 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/68f8fa50 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/68f8fa50 Branch: refs/heads/master Commit: 68f8fa50d021ba6573b9cf394aef26c1ec705aff Parents: 3509b91 Author: Robert Newson <[email protected]> Authored: Thu Aug 11 10:52:24 2016 +0100 Committer: Robert Newson <[email protected]> Committed: Thu Aug 11 12:16:58 2016 +0100 ---------------------------------------------------------------------- src/chttpd_db.erl | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/68f8fa50/src/chttpd_db.erl ---------------------------------------------------------------------- diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl index 59ccebd..7f0dce7 100644 --- a/src/chttpd_db.erl +++ b/src/chttpd_db.erl @@ -225,9 +225,24 @@ maybe_flush_changes_feed(Acc0, Data, Len) -> }, {ok, Acc}. -handle_compact_req(Req, _) -> - Msg = <<"Compaction must be triggered on a per-shard basis in CouchDB">>, - couch_httpd:send_error(Req, 403, forbidden, Msg). +handle_compact_req(#httpd{method='POST'}=Req, Db) -> + chttpd:validate_ctype(Req, "application/json"), + case Req#httpd.path_parts of + [_DbName, <<"_compact">>] -> + ok = fabric:compact(Db), + send_json(Req, 202, {[{ok, true}]}); + [DbName, <<"_compact">>, DesignName | _] -> + case ddoc_cache:open(DbName, <<"_design/", DesignName/binary>>) of + {ok, _DDoc} -> + ok = fabric:compact(Db, DesignName), + send_json(Req, 202, {[{ok, true}]}); + Error -> + throw(Error) + end + end; + +handle_compact_req(Req, _Db) -> + send_method_not_allowed(Req, "POST"). handle_view_cleanup_req(Req, Db) -> ok = fabric:cleanup_index_files(Db),
