diff options
author | Damien F. Katz <damien@apache.org> | 2008-12-22 20:35:50 +0000 |
---|---|---|
committer | Damien F. Katz <damien@apache.org> | 2008-12-22 20:35:50 +0000 |
commit | c823bd2e8b3990b5c55dde54705d6866ad1eda4f (patch) | |
tree | 4be1ffa83f983e36038841f8b25812f2cfe6d482 /src/couchdb/couch_view.erl | |
parent | 112e286f3c0727caf6f6c96caa2ba40f31552ac7 (diff) |
Fix for leaked file handles when not explicitly closed, added file stats code for checking for leaked file handles, and some refactoring of the view api.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@728764 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_view.erl')
-rw-r--r-- | src/couchdb/couch_view.erl | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/src/couchdb/couch_view.erl b/src/couchdb/couch_view.erl index 84f327e3..665cb6f7 100644 --- a/src/couchdb/couch_view.erl +++ b/src/couchdb/couch_view.erl @@ -13,9 +13,11 @@ -module(couch_view). -behaviour(gen_server). --export([start_link/0,fold/4,fold/5,less_json/2,less_json_keys/2,expand_dups/2,detuple_kvs/2]). --export([init/1,terminate/2,handle_call/3,handle_cast/2,handle_info/2,code_change/3]). --export([get_reduce_view/1, get_map_view/1,get_row_count/1,reduce_to_count/1, fold_reduce/7]). +-export([start_link/0,fold/4,fold/5,less_json/2,less_json_keys/2,expand_dups/2, + detuple_kvs/2,init/1,terminate/2,handle_call/3,handle_cast/2,handle_info/2, + code_change/3,get_reduce_view/4,get_temp_reduce_view/4,get_temp_map_view/3, + get_map_view/4,get_row_count/1,reduce_to_count/1,fold_reduce/7, + extract_map_view/1]). -include("couch_db.hrl"). @@ -23,7 +25,8 @@ start_link() -> gen_server:start_link({local, couch_view}, couch_view, [], []). get_temp_updater(DbName, Type, MapSrc, RedSrc) -> - {ok, Pid} = gen_server:call(couch_view, {start_temp_updater, DbName, Type, MapSrc, RedSrc}), + {ok, Pid} = gen_server:call(couch_view, + {start_temp_updater, DbName, Type, MapSrc, RedSrc}), Pid. get_group_server(DbName, GroupId) -> @@ -34,21 +37,28 @@ get_group_server(DbName, GroupId) -> throw(Error) end. -get_updated_group(DbName, GroupId, Update) -> - couch_view_group:request_group(get_group_server(DbName, GroupId), seq_for_update(DbName, Update)). +get_group(Db, GroupId, Update) -> + couch_view_group:request_group( + get_group_server(couch_db:name(Db), GroupId), + if Update -> couch_db:get_update_seq(Db); true -> 0 end). -get_updated_group(temp, DbName, Type, MapSrc, RedSrc, Update) -> - couch_view_group:request_group(get_temp_updater(DbName, Type, MapSrc, RedSrc), seq_for_update(DbName, Update)). + +get_temp_group(Db, Type, MapSrc, RedSrc) -> + couch_view_group:request_group( + get_temp_updater(couch_db:name(Db), Type, MapSrc, RedSrc), + couch_db:get_update_seq(Db)). get_row_count(#view{btree=Bt}) -> {ok, {Count, _Reds}} = couch_btree:full_reduce(Bt), {ok, Count}. -get_reduce_view({temp, DbName, Type, MapSrc, RedSrc}) -> - {ok, #group{views=[View]}} = get_updated_group(temp, DbName, Type, MapSrc, RedSrc, true), - {ok, {temp_reduce, View}}; -get_reduce_view({DbName, GroupId, Name}) -> - case get_updated_group(DbName, GroupId, true) of +get_temp_reduce_view(Db, Type, MapSrc, RedSrc) -> + {ok, #group{views=[View]}} = get_temp_group(Db, Type, MapSrc, RedSrc), + {ok, {temp_reduce, View}}. + + +get_reduce_view(Db, GroupId, Name, Update) -> + case get_group(Db, GroupId, Update) of {ok, #group{views=Views,def_lang=Lang}} -> get_reduce_view0(Name, Lang, Views); Error -> @@ -63,6 +73,9 @@ get_reduce_view0(Name, Lang, [#view{reduce_funs=RedFuns}=View|Rest]) -> N -> {ok, {reduce, N, Lang, View}} end. +extract_map_view({reduce, _N, _Lang, View}) -> + View. + detuple_kvs([], Acc) -> lists:reverse(Acc); detuple_kvs([KV | Rest], Acc) -> @@ -113,21 +126,14 @@ get_key_pos(Key, [{Key1,_Value}|_], N) when Key == Key1 -> N + 1; get_key_pos(Key, [_|Rest], N) -> get_key_pos(Key, Rest, N+1). - -seq_for_update(DbName, Update) -> - case Update of - true -> - {ok, #db{update_seq=CurrentSeq}} = couch_db:open(DbName, []), - CurrentSeq; - _Else -> - 0 - end. - -get_map_view({temp, DbName, Type, Src}) -> - {ok, #group{views=[View]}} = get_updated_group(temp, DbName, Type, Src, [], true), - {ok, View}; -get_map_view({DbName, GroupId, Name, Update}) -> - case get_updated_group(DbName, GroupId, Update) of + + +get_temp_map_view(Db, Type, Src) -> + {ok, #group{views=[View]}} = get_temp_group(Db, Type, Src, []), + {ok, View}. + +get_map_view(Db, GroupId, Name, Update) -> + case get_group(Db, GroupId, Update) of {ok, #group{views=Views}} -> get_map_view0(Name, Views); Error -> |