Permalink
Browse files

Create the couch_mrview application.

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 e83352f33cd8bc8be437fc10c734477b315de610
View
@@ -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
View
@@ -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])
@@ -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
@@ -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, []}
@@ -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
@@ -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.
View
@@ -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
@@ -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");
View
@@ -12,6 +12,7 @@
SUBDIRS = \
couch_index \
+ couch_mrview \
couchdb \
ejson \
erlang-oauth \
@@ -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]),
@@ -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 ->
@@ -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;
View
@@ -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/*")).
@@ -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."
),
@@ -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(),
@@ -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) ->

0 comments on commit e83352f

Please sign in to comment.