Sync Gateway update_seq higher than last_seq


#1

I’m using sync gateway on a web application to retrieve documents from couchbase and I’m finding that periodically the update_seq returned from the _all_docs call is higher than the actual highest sequence on the server. Details below:

I first call /_all_docs?include_docs=true and then store the update_seq returned (as well as the documents). When I make an update to a document I first save it to my couchbase server through sync gateway, then I try to refresh my local copy of the DB by calling /_changes?include_docs=true&since=update_seq. I then set the update_seq for the next call to the last_seq returned from the _changes call. Sometimes though the update_seq returned by the original _all_docs call is much higher than the last_seq returned by the _changes call. My understanding based on the documentation though is that both values are supposed to represent the latest sequence number, so how can one value be much higher than the other?


#2

I have just tested and confirmed that the _all_docs call returns the global sequence number stored in the couchbase document _sync:seq

Whereas the _changes returns the last sequence Id calculated from the documents mapped to the channels they have access to.

The global sequence stored in the _sync:seq document, can be incremented for internal use as well as new document revisions, so this value does not accurately represent the highest document sequence_id.

I have created a new github ticket to capture this: https://github.com/couchbase/sync_gateway/issues/490

Andy