Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MB-6860: Don't open group for cleanup

In the old code the spatial group was opened to get the
signature in order to cleanup the files. This meant that
a spatial group was created although there were no spatial
views defined in the design document.

The new code doesn't create new spatial groups if there
aren't eny defined in the design document.

Change-Id: I54f6a3cdfe524c8eeacb88d4bd0d9a87d59985d4
Reviewed-on: http://review.couchbase.org/21591
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: Volker Mische <volker.mische@gmail.com>
  • Loading branch information...
commit b0bd742551639c52030c070e5bf9390edbb536ba 1 parent 7782df1
@vmx vmx authored Peter Wansch committed
View
34 src/geocouch/couch_spatial.erl
@@ -118,30 +118,36 @@ get_group_info(DbName, GroupId) ->
couch_view_group:request_group_info(get_group_server(DbName, GroupId)).
-% The only reason why couch_view:cleanup_index_files can't be used is the
-% call to get_group_info
cleanup_index_files(Db) ->
% load all ddocs
- {ok, DesignDocs} = couch_db:get_design_docs(Db),
-
+ {ok, DesignDocs} = couch_db:get_design_docs(Db, no_deletes),
% make unique list of group sigs
- Sigs = lists:map(fun(#doc{id = GroupId}) ->
- {ok, Info} = get_group_info(Db, GroupId),
- ?b2l(couch_util:get_value(signature, Info))
- end, [DD||DD <- DesignDocs, DD#doc.deleted == false]),
+ Sigs = lists:map(fun couch_spatial_group:get_signature/1, DesignDocs),
FileList = list_index_files(Db),
+
% regex that matches all ddocs
RegExp = "("++ string:join(Sigs, "|") ++")",
% filter out the ones in use
- DeleteFiles = [FilePath
- || FilePath <- FileList,
- re:run(FilePath, RegExp, [{capture, none}]) =:= nomatch],
+ DeleteFiles = case Sigs of
+ [] ->
+ FileList;
+ _ ->
+ [FilePath || FilePath <- FileList,
+ re:run(FilePath, RegExp, [{capture, none}]) =:= nomatch]
+ end,
% delete unused files
- ?LOG_DEBUG("deleting unused view index files: ~p",[DeleteFiles]),
+ case DeleteFiles of
+ [] ->
+ ok;
+ _ ->
+ ?LOG_INFO("Deleting unused (old) spatial index files:~n~n~s",
+ [string:join(DeleteFiles, "\n")])
+ end,
RootDir = couch_config:get("couchdb", "view_index_dir"),
- [couch_file:delete(RootDir,File,false)||File <- DeleteFiles],
- ok.
+ lists:foreach(
+ fun(File) -> couch_file:delete(RootDir, File, false) end,
+ DeleteFiles).
delete_index_dir(RootDir, DbName) ->
couch_view:nuke_dir(RootDir ++ "/." ++ ?b2l(DbName) ++ "_design").
View
9 src/geocouch/couch_spatial_group.erl
@@ -17,7 +17,7 @@
-behaviour(gen_server).
%% API
--export([start_link/1, request_group/2, open_db_group/2]).
+-export([start_link/1, request_group/2, open_db_group/2, get_signature/1]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
@@ -354,6 +354,13 @@ open_db_group(DbName, GroupId) ->
end.
+% Return the signature of a group without the need to request
+% the group, but purely from the design document
+get_signature(DDoc) ->
+ #spatial_group{sig = Sig} = design_doc_to_spatial_group(DDoc),
+ couch_util:to_hex(Sig).
+
+
design_doc_to_spatial_group(Doc) ->
#doc{id=Id, body={Fields}} = couch_doc:with_ejson_body(Doc),
Language = couch_util:get_value(<<"language">>, Fields, <<"javascript">>),
Please sign in to comment.
Something went wrong with that request. Please try again.