diff options
author | Filipe David Borba Manana <fdmanana@apache.org> | 2011-06-23 09:45:39 +0000 |
---|---|---|
committer | Filipe David Borba Manana <fdmanana@apache.org> | 2011-06-23 09:45:39 +0000 |
commit | 91e2121c913a54a77482ed3883f7a8d2d00801a4 (patch) | |
tree | c2e8672d4b1ab6cd04fefcfb8df0ce52b2911ef9 /src/couchdb/couch_view_updater.erl | |
parent | d8dc16093a26c53407d8bf702698848104ba01d6 (diff) |
Merged revision 1138796 from trunk
Simpler and safer db open/closing in view group servers
This makes the opening and closing of databases in the view
group server to be more friendly with the db reference counting
system, avoiding more potential db file leaking after compaction,
as we currently open a database in one process and use it on
another process (view compactor, view updater).
This significantly reduces the chances of failure when compacting
very large views as discussed in COUCHDB-994.
This relates to COUCHDB-926 and COUCHDB-994.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1138798 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_view_updater.erl')
-rw-r--r-- | src/couchdb/couch_view_updater.erl | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/couchdb/couch_view_updater.erl b/src/couchdb/couch_view_updater.erl index 8e089fa9..2cc390df 100644 --- a/src/couchdb/couch_view_updater.erl +++ b/src/couchdb/couch_view_updater.erl @@ -12,30 +12,31 @@ -module(couch_view_updater). --export([update/2]). +-export([update/3]). -include("couch_db.hrl"). --spec update(_, #group{}) -> no_return(). +-spec update(_, #group{}, Dbname::binary()) -> no_return(). -update(Owner, Group) -> +update(Owner, Group, DbName) -> #group{ - db = #db{name=DbName} = Db, name = GroupName, current_seq = Seq, purge_seq = PurgeSeq } = Group, couch_task_status:add_task(<<"View Group Indexer">>, <<DbName/binary," ",GroupName/binary>>, <<"Starting index update">>), + {ok, Db} = couch_db:open_int(DbName, []), DbPurgeSeq = couch_db:get_purge_seq(Db), Group2 = if DbPurgeSeq == PurgeSeq -> Group; DbPurgeSeq == PurgeSeq + 1 -> couch_task_status:update(<<"Removing purged entries from view index.">>), - purge_index(Group); + purge_index(Group, Db); true -> couch_task_status:update(<<"Resetting view index due to lost purge entries.">>), + couch_db:close(Db), exit(reset) end, {ok, MapQueue} = couch_work_queue:new( @@ -73,13 +74,14 @@ update(Owner, Group) -> couch_task_status:set_update_frequency(0), couch_task_status:update("Finishing."), couch_work_queue:close(MapQueue), + couch_db:close(Db), receive {new_group, NewGroup} -> exit({new_group, NewGroup#group{current_seq=couch_db:get_update_seq(Db)}}) end. -purge_index(#group{db=Db, views=Views, id_btree=IdBtree}=Group) -> +purge_index(#group{views=Views, id_btree=IdBtree}=Group, Db) -> {ok, PurgedIdsRevs} = couch_db:get_last_purged(Db), Ids = [Id || {Id, _Revs} <- PurgedIdsRevs], {ok, Lookups, IdBtree2} = couch_btree:query_modify(IdBtree, Ids, [], Ids), |