anchor.diff:              throw({unauthorized, <<"password required">>})
       end.
   
  -get_db_info(#db{filepath = undefined, name = Name}) ->
  -    Info = [{db_name, Name},
  -            {instance_start_time, <<>>}],
  -    {ok, Info};
  -get_db_info(#db{name = <<"_replicator">>} = Db) ->
  -    couch_db:get_db_info(Db);
  +%% This is used by 2.x xdcr checkpointing. It's only supposed to work
  +%% against vbucket
   get_db_info(#db{name = DbName}) ->
  -    [Bucket, _Master] = string:tokens(binary_to_list(DbName), [$/]),
  +    Bucket = case string:tokens(binary_to_list(DbName), [$/]) of
  +                 [BucketV, _Vb] -> BucketV;
  +                 _ -> throw(not_found)
  +             end,
       {ok, Stats0} = ns_memcached:stats(Bucket, <<"">>),
       EpStartupTime =  proplists:get_value(<<"ep_startup_time">>, Stats0),
       Info = [{db_name, DbName},
  
positive.code:     {ok, Config} = ns_bucket:get_bucket(?b2l(Bucket)),
      Map = proplists:get_value(map, Config, []),
      first_vbucket(node(), Map, 0) =/= {error, no_vbucket_found}.
  
  %% Keep the last previous non design doc id found so if the random item
  %% picked was a design doc, return last document, or not_found
  -spec fold_docs(#doc_info{}, any(), tuple()) -> {ok, any()} | {stop, any()}.
  fold_docs(#doc_info{id = <<"_design", _/binary>>}, _, {0, undefined}) ->
      {stop, {error, not_found}};
  fold_docs(#doc_info{id = <<"_design", _/binary>>}, _, {0, Id}) ->
      {stop, Id};
  fold_docs(#doc_info{id = Id}, _, {0, _Id}) ->
      {stop, Id};
  fold_docs(#doc_info{deleted=true}, _, Acc) ->
      {ok, Acc};
  fold_docs(_, _, {N, Id}) ->
      {ok, {N - 1, Id}}.
  
  
  %% Return 404 when no documents are found
  -spec no_random_docs(#httpd{}) -> any().
  no_random_docs(Req) ->
      couch_httpd:send_error(Req, 404, <<"no_docs">>, <<"No documents in database">>).
  
  
  -spec setup_sender(#index_merge{}) -> #index_merge{}.
  setup_sender(MergeParams) ->
      MergeParams#index_merge{
        user_acc = #collect_acc{},
        callback = fun collect_ids/2,
        extra = #view_merge{
          make_row_fun = fun({{DocId, DocId}, _Value}) -> DocId end
         }
       }.
  
  
  %% Colled Id's in the callback of the view merge, ignore design documents
  -spec collect_ids(any(), #collect_acc{}) -> any().
  collect_ids(stop, Acc) ->
      {ok, Acc};
  collect_ids({start, X}, Acc) ->
      {ok, Acc#collect_acc{row_count=X}};
  collect_ids({row, Id}, #collect_acc{rows=Rows} = Acc) ->
      case is_design_doc(Id) of
          true -> {ok, Acc};
          false -> {ok, Acc#collect_acc{rows=[Id|Rows]}}
      end.
  
  
  -spec is_design_doc(binary()) -> true | false.
  is_design_doc(<<"_design/", _Rest/binary>>) ->
      true;
  is_design_doc(_) ->
      false.
  
  -spec get_version() -> string().
  get_version() ->
  
negative.code:     couch_db:start_compact(Db).
  
  cleanup_view_index_files(Db) ->
      exit(not_implemented(cleanup_view_index_files, [Db])).
  
  %% TODO: check if it's useful
  get_group_info(#db{filepath = undefined} = Db, DesignId) ->
      with_subdb(Db, <<"master">>,
                 fun (RealDb) ->
  