anchor.diff:  compact_vbucket(DbName, Config) ->
       case (catch couch_db:open_int(DbName, [])) of
       {ok, Db} ->
  +        DDocNames = db_ddoc_names(Db),
           {ok, DbCompactPid} = couch_db:start_compact(Db),
           TimeLeft = compact_time_left(Config),
           case Config#config.parallel_view_compact of
           true ->
               ViewsCompactPid = spawn(fun() ->
  -                {ok, Db2} = couch_db:open_int(DbName, []),
  -                maybe_compact_views(Db2, Config),
  -                couch_db:close(Db2)
  +                maybe_compact_views(DbName, DDocNames, Config)
               end),
               ViewsMonRef = erlang:monitor(process, ViewsCompactPid);
           false ->
  
positive.code:     end.
  
  
  maybe_compact_views(Db, Config) ->
      {ok, _, ok} = couch_db:enum_docs(
          Db,
          fun(#full_doc_info{id = <<"_design/", Id/binary>>}, _, Acc) ->
              maybe_compact_view(Db, Id, Config),
              {ok, Acc};
          (_, _, Acc) ->
              {stop, Acc}
          end, ok, [{start_key, <<"_design/">>}, {end_key_gt, <<"_design0">>}]).
  
  
  maybe_compact_view(#db{name = DbName} = Db, GroupId, Config) ->
      DDocId = <<"_design/", GroupId/binary>>,
      case (catch couch_view:get_group_info(Db, DDocId)) of
      {ok, GroupInfo} ->
          case can_view_compact(Config, Db, GroupId, GroupInfo) of
          true ->
              {ok, CompactPid} = couch_view_compactor:start_compact(DbName, GroupId),
              TimeLeft = compact_time_left(Config),
  
negative.code:             {'DOWN', MonRef, process, CompactPid, Reason} ->
                  ?LOG_ERROR("Compaction daemon - an error ocurred while compacting"
                      " the view group `~s` from database `~s`: ~p",
                      [GroupId, DbName, Reason]),
                  ok
              after TimeLeft ->
                  ?LOG_INFO("Compaction daemon - canceling the compaction for the "
                      "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),
                  timeout
              end;
          false ->
              ok
          end;
      Error ->
          ?LOG_ERROR("Error opening view group `~s` from database `~s`: ~p",
              [GroupId, DbName, Error]),
          ok
      end.
  
  