anchor.diff:                ok
         end).
   
  -apply_current_map(#state{bucket=Bucket} = State) ->
  +apply_current_map(#state{bucket=Bucket, ddocs=DDocs} = State) ->
       {ok, BucketConfig} = ns_bucket:get_bucket(Bucket),
       VBucketStates = get_vbucket_states(Bucket, BucketConfig),
       Map = build_map(BucketConfig, VBucketStates),
  -    apply_map(Bucket, BucketConfig, undefined, Map),
  +    apply_map(Bucket, DDocs, undefined, Map),
       State#state{bucket_config=BucketConfig,
                   vbucket_states=VBucketStates,
                   pending_vbucket_states=VBucketStates,
  
positive.code: handle_call(_Request, _From, State) ->
      {reply, ok, State}.
  
  handle_cast({update_ddoc, DDocId},
              #state{bucket=Bucket,
                     bucket_config=BucketConfig, map=Map} = State) ->
      maybe_define_group(Bucket, BucketConfig, DDocId, Map),
      {noreply, State};
  
  handle_cast(_Msg, State) ->
      {noreply, State}.
  
negative.code: sync(#state{bucket=Bucket,
              bucket_config=BucketConfig,
              pending_vbucket_states=PendingStates,
              ddocs=DDocs,
              map=Map} = State) ->
      NewMap = build_map(BucketConfig, PendingStates),
      case NewMap =/= Map of
          true ->
              apply_map(Bucket, DDocs, Map, NewMap),
              State#state{vbucket_states=PendingStates, map=NewMap};
          false ->
              State#state{vbucket_states=PendingStates}
      end.
  
  get_design_docs(Bucket) ->
      DDocDbName = master_db(Bucket),
  
      {ok, DDocDb} = couch_db:open(DDocDbName,
                                   [{user_ctx, #user_ctx{roles=[<<"_admin">>]}}]),
      {ok, DDocs} =
          try
              couch_db:get_design_docs(DDocDb)
          after
              couch_db:close(DDocDb)
          end,
  
      DDocIds = lists:map(fun (#doc{id=DDocId}) ->
                                  DDocId
                          end, DDocs),
      sets:from_list(DDocIds).
  