anchor.diff:              ok
       end.
   
  -calculate_start_seq(#db{uuid=Uuid1}, {_, Uuid2, _}) when Uuid1 =/= Uuid2 ->
  -    %% The file was rebuilt, most likely in a different order, so rewind.
  -    0;
  -calculate_start_seq(#db{}=Db, {Seq, _Uuid, Node}) ->
  -    case owner(Node, Seq, Db#db.epochs) of
  -        true  -> Seq;
  -        false -> 0
  -    end;
   calculate_start_seq(_Db, Seq) when is_integer(Seq) ->
  -    Seq.
  +    Seq;
  +calculate_start_seq(Db, {Seq, Uuid, Node}) ->
  +    case couch_db:get_uuid(Db) == Uuid of
  +        true ->
  +            case owner(Node, Seq, couch_db:get_epochs(Db)) of
  +                true -> Seq;
  +                false -> 0
  +            end;
  +        false ->
  +            %% The file was rebuilt, most likely in a different
  +            %% order, so rewind.
  +            0
  +    end.
   
   owner(Node, Seq, Epochs) ->
       owner(Node, Seq, Epochs, infinity).
  
positive.code: 
  changes_row(Db, #doc_info{id=Id, high_seq=Seq}=DI, Results, Del, true, Opts) ->
      Doc = doc_member(Db, DI, Opts),
      #change{key={Seq, Db#db.uuid, node()}, id=Id, value=Results, doc=Doc, deleted=Del};
  changes_row(Db, #doc_info{id=Id, high_seq=Seq}, Results, true, _, _) ->
      #change{key={Seq, Db#db.uuid, node()}, id=Id, value=Results, deleted=true};
  changes_row(Db, #doc_info{id=Id, high_seq=Seq}, Results, _, _, _) ->
      #change{key={Seq, Db#db.uuid, node()}, id=Id, value=Results}.
  
  doc_member(Shard, DocInfo, Opts) ->
      case couch_db:open_doc(Shard, DocInfo, [deleted | Opts]) of
  
negative.code: 
  calculate_start_seq_test() ->
      %% uuid mismatch is always a rewind.
      Hdr1 = couch_db_header:new(),
      Hdr2 = couch_db_header:set(Hdr1, [{uuid, uuid1}]),
      ?assertEqual(0, calculate_start_seq(#db{header=Hdr2}, {1, uuid2, node1})),
      %% uuid matches and seq is owned by node.
      Hdr3 = couch_db_header:set(Hdr2, [{epochs, [{node1, 1}]}]),
      ?assertEqual(2, calculate_start_seq(#db{header=Hdr3}, {2, uuid1, node1})),
      %% uuids match but seq is not owned by node.
      Hdr4 = couch_db_header:set(Hdr2, [{epochs, [{node2, 2}, {node1, 1}]}]),
      ?assertEqual(0, calculate_start_seq(#db{header=Hdr4}, {3, uuid1, node1})),
      %% return integer if we didn't get a vector.
      ?assertEqual(4, calculate_start_seq(#db{}, 4)).
  
  