Skip to content

Commit

Permalink
Create the couch_mrview application.
Browse files Browse the repository at this point in the history
The couch_mrview application is the implementation of the current
couchdb map/reduce views. This implementation is 100% compatible with
trunk and serves as a reference implementation for other indexers.



git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1171149 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
davisp committed Sep 15, 2011
1 parent 35e5787 commit e83352f
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ bin/couch-config_dev
etc/couchdb/default.ini
etc/launchd/org.apache.couchdb.plist
etc/logrotate.d/couchdb
src/couch_mrview/ebin/
src/couchdb/.libs/*
src/couchdb/couch.app
src/couchdb/couchjs
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ AC_CONFIG_FILES([etc/Makefile])
AC_CONFIG_FILES([share/Makefile])
AC_CONFIG_FILES([src/Makefile])
AC_CONFIG_FILES([src/couch_index/Makefile])
AC_CONFIG_FILES([src/couch_mrview/Makefile])
AC_CONFIG_FILES([src/couchdb/couch.app.tpl])
AC_CONFIG_FILES([src/couchdb/Makefile])
AC_CONFIG_FILES([src/couchdb/priv/Makefile])
Expand Down
20 changes: 10 additions & 10 deletions etc/couchdb/default.ini.tpl.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

[couchdb]
database_dir = %localstatelibdir%
view_index_dir = %localstatelibdir%
index_dir = %localstatelibdir%
util_driver_dir = %couchprivlibdir%
max_document_size = 4294967296 ; 4 GB
Expand Down Expand Up @@ -72,7 +71,6 @@ reduce_limit = true
os_process_limit = 25

[daemons]
view_manager={couch_view, start_link, []}
index_server={couch_index_server, start_link, []}
external_manager={couch_external_manager, start_link, []}
query_servers={couch_query_servers, start_link, []}
Expand Down Expand Up @@ -103,11 +101,12 @@ _session = {couch_httpd_auth, handle_session_req}
_oauth = {couch_httpd_oauth, handle_oauth_req}

[httpd_db_handlers]
_view_cleanup = {couch_httpd_db, handle_view_cleanup_req}
_all_docs = {couch_mrview_http, handle_all_docs_req}
_changes = {couch_httpd_db, handle_changes_req}
_compact = {couch_httpd_db, handle_compact_req}
_design = {couch_httpd_db, handle_design_req}
_temp_view = {couch_httpd_view, handle_temp_view_req}
_changes = {couch_httpd_db, handle_changes_req}
_temp_view = {couch_mrview_http, handle_temp_view_req}
_view_cleanup = {couch_mrview_http, handle_cleanup_req}

; The external module takes an optional argument allowing you to narrow it to a
; single script. Otherwise the script name is inferred from the first path section
Expand All @@ -116,12 +115,13 @@ _changes = {couch_httpd_db, handle_changes_req}
; _external = {couch_httpd_external, handle_external_req}

[httpd_design_handlers]
_view = {couch_httpd_view, handle_view_req}
_show = {couch_httpd_show, handle_doc_show_req}
_list = {couch_httpd_show, handle_view_list_req}
_info = {couch_httpd_db, handle_design_info_req}
_compact = {couch_mrview_http, handle_compact_req}
_info = {couch_mrview_http, handle_info_req}
_list = {couch_mrview_show, handle_view_list_req}
_rewrite = {couch_httpd_rewrite, handle_rewrite_req}
_update = {couch_httpd_show, handle_doc_update_req}
_show = {couch_mrview_show, handle_doc_show_req}
_update = {couch_mrview_show, handle_doc_update_req}
_view = {couch_mrview_http, handle_view_req}

; enable external as an httpd handler, then link it with commands here.
; note, this api is still under consideration.
Expand Down
3 changes: 3 additions & 0 deletions license.skip
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
^src/couch_index/Makefile
^src/couch_index/Makefile.in
^src/couch_index/ebin/.*beam
^src/couch_mrview/Makefile
^src/couch_mrview/Makefile.in
^src/couch_mrview/ebin/.*beam
^src/couchdb/.*beam
^src/couchdb/.deps/*
^src/couchdb/Makefile
Expand Down
2 changes: 1 addition & 1 deletion share/www/script/test/view_compaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ couchTests.view_compaction = function(debug) {
T(data_size_before_compact < disk_size_before_compact, "data size < file size");

// compact view group
var xhr = CouchDB.request("POST", "/" + db.name + "/_compact" + "/foo");
var xhr = CouchDB.request("POST", "/" + db.name + "/_design/foo/_compact");
T(JSON.parse(xhr.responseText).ok === true);

resp = db.designInfo("_design/foo");
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

SUBDIRS = \
couch_index \
couch_mrview \
couchdb \
ejson \
erlang-oauth \
Expand Down
12 changes: 6 additions & 6 deletions src/couchdb/couch_compaction_daemon.erl
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ maybe_compact_view(DbName, GroupId, Config) ->
{ok, GroupInfo} ->
case can_view_compact(Config, DbName, GroupId, GroupInfo) of
true ->
{ok, CompactPid} = couch_view_compactor:start_compact(DbName, GroupId),
ok = couch_mrview:compact(DbName, DDocId),
{ok, MonRef} = couch_mrview:monitor_compaction(DbName, DDocId),
TimeLeft = compact_time_left(Config),
MonRef = erlang:monitor(process, CompactPid),
receive
{'DOWN', MonRef, process, CompactPid, normal} ->
{'DOWN', MonRef, process, _, normal} ->
ok;
{'DOWN', MonRef, process, CompactPid, Reason} ->
{'DOWN', MonRef, process, _, Reason} ->
?LOG_ERROR("Compaction daemon - an error ocurred while compacting"
" the view group `~s` from database `~s`: ~p",
[GroupId, DbName, Reason]),
Expand All @@ -244,7 +244,7 @@ maybe_compact_view(DbName, GroupId, Config) ->
"view group `~s` of the database `~s` because it's exceeding"
" the allowed period.", [GroupId, DbName]),
erlang:demonitor(MonRef, [flush]),
ok = couch_view_compactor:cancel_compact(DbName, GroupId),
ok = couch_mrview:cancel_compaction(DbName, DDocId),
timeout
end;
false ->
Expand Down Expand Up @@ -329,7 +329,7 @@ can_view_compact(Config, DbName, GroupId, GroupInfo) ->
false ->
false;
true ->
Free = free_space(couch_config:get("couchdb", "view_index_dir")),
Free = free_space(couch_index_util:root_dir()),
case Free >= SpaceRequired of
true ->
true;
Expand Down
4 changes: 2 additions & 2 deletions test/etap/072-cleanup.t
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@ view_cleanup() ->

count_index_files() ->
% call server to fetch the index files
RootDir = couch_config:get("couchdb", "view_index_dir"),
RootDir = couch_config:get("couchdb", "index_dir"),
length(filelib:wildcard(RootDir ++ "/." ++
binary_to_list(?TEST_DB) ++ "_design"++"/*")).
binary_to_list(?TEST_DB) ++ "_design"++"/mrview/*")).
2 changes: 1 addition & 1 deletion test/etap/080-config-get-set.t
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test() ->

etap:is(
couch_config:get("httpd_design_handlers", "_view"),
"{couch_httpd_view, handle_view_req}",
"{couch_mrview_http, handle_view_req}",
"The {httpd_design_handlers, view} is the expected default."
),

Expand Down
12 changes: 7 additions & 5 deletions test/etap/200-view-group-no-db-leaks.t
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ test() ->
create_docs(),
create_design_doc(),

ViewGroup = couch_view:get_group_server(
test_db_name(), <<"_design/", (ddoc_name())/binary>>),
etap:is(is_pid(ViewGroup), true, "got view group pid"),
etap:is(is_process_alive(ViewGroup), true, "view group pid is alive"),
{ok, IndexerPid} = couch_index_server:get_index(
couch_mrview_index, test_db_name(), <<"_design/", (ddoc_name())/binary>>
),
etap:is(is_pid(IndexerPid), true, "got view group pid"),
etap:is(is_process_alive(IndexerPid), true, "view group pid is alive"),

query_view(),
check_db_ref_count(),
Expand Down Expand Up @@ -169,7 +170,8 @@ wait_db_compact_done(N) ->
end.

compact_view_group() ->
{ok, _} = couch_view_compactor:start_compact(test_db_name(), ddoc_name()),
DDoc = list_to_binary("_design/" ++ binary_to_list(ddoc_name())),
ok = couch_mrview:compact(test_db_name(), DDoc),
wait_view_compact_done(10).

wait_view_compact_done(0) ->
Expand Down

0 comments on commit e83352f

Please sign in to comment.