couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vladimir Ralev <vladimir.ra...@gmail.com>
Subject _cleanup_view is deleting all views
Date Fri, 31 Jan 2014 16:09:24 GMT
Hi guys,

bigcouch 0.4.2 has the following code that handles view cleanup:

cleanup_index_files(Db) ->

    % load all ddocs

    {ok, DesignDocs} = couch_db:get_design_docs(Db),


    % 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]),


    FileList = list_index_files(Db),


    DeleteFiles =

    if length(Sigs) =:= 0 ->

        FileList;

    true ->

        % regex that matches all ddocs

        RegExp = "("++ string:join(Sigs, "|") ++")",


    % filter out the ones in use

        [FilePath || FilePath <- FileList,

            re:run(FilePath, RegExp, [{capture, none}]) =:= nomatch]

    end,


    % delete unused files

    ?LOG_DEBUG("deleting unused view index files: ~p",[DeleteFiles]),

    RootDir = couch_config:get("couchdb", "view_index_dir"),

    [couch_file:delete(RootDir,File,false)||File <- DeleteFiles],

    ok.


>From here
https://github.com/cloudant/bigcouch/blob/master/apps/couch/src/couch_view.erl#L84

It's supposed to delete only unused views, but in my case it deletes
everything and then starts building from scratch. Can you help me
understand the condition used here to filter the files that are currently
in use? How is the regex supposed to work.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message