Changes api does not return new changes


I am using Couchbase server 4.5.1 and Sync gateway 1.4.1.
Yesterday all of a sudden I got an issue with changes REST API of Sync Gateway.
It worked fine till sequence 295. After this all new changes (seq 295 - 312) got saved successfully on Sync Gateway but changes api did not returned sequences 295 to 312. I checked sg logs and found one doubtful log :
GET /db1/_changes
changes_view: Query took 1.83378s to return 229 rows, options = db.Body{“stale”:false, “startkey”:interface {}{"", 0x1}, “endkey”:[]interface {}{"", 0xf1}}
I have attached the log info from sequence 295 to 296:

I restarted SG, hit changes api and it returned changes sequences 295-312. Then added new records which got saved successfully but again changes api did not returned the new changes and got same doubtful line mentioned above in SG logs. Restarted SG and then it returned new changes. So I was getting new changes only after restarting SG.

I had to delete the bucket in CBS, create new bucket with same name and restart SG. It is working fine now.
It is a very critical issue and can stop the replication of data completely

Please help me understanding the cause of issue.

Are you making any writes directly to CB Server, or do they all go through Sync Gateway?

No, all writes go through Sync Gateway.

Is there a reason why you are not using N1QL to do Ad-hoc queries?

In our application, mobile devices (having couchbase lite) pull data from couchbase server through sync gateway. Pull replication involves hitting changes api of SG to see if there are any new changes.
When I saw data replication is not happening, I hit the SG changes api from browser to check what changes api returns. It was not returning the new changes.


If you suspect that SG is not putting the newest changes is the _changes feed its best to look into the sync gateway logs.
In dev turn loging to “logs”:["*"] so that you see all the process that SG is going.

Looks like we’ve got the same issue.

We use PouchDB as a client. It first issues GET /db and receives some metadata including update_seq (ex. 4000). Then, it asks for changes since that seq.

The problem is that new changes receive seq less than update_seq above (ex. 3600, 3601…) and thus are not returned in the changes feed.

Special _sync:seq doc had the same value as update seq in /db metadata and didn’t increment.

After SG restart new changes started receiving seqs from _sync:seq and it started to increment.

Any ideas on the root cause and possible workarounds?

Thank you.


You would have to investigate your Sync Gateway logs to see whats it is or is not doing.

Currently Couchbase Mobile is almost 100% compatible with CouchDB/PouchDB protocol.
As Couchbase Mobile moves forward you might see it diverge from the CouchDB/PouchDB standard due to performance reason.

As I understood, new SG version supports both old (CouchDB) protocol and the new one.
Are there plans to drop support of CouchDB protocol?

Thank you.

Can you clarify what version you are referring to as the “New version”. V2.0 of Couchbase Mobile uses a high performance, efficient replication protocol that’s layered on top of BLIP / web sockets. I don’t believe there are plans to support the HTTP /couch DB API based version of replication . @jens or @traun can chime in.

Sync Gateway 2 will continue to support the existing CouchDB-based REST API, including its replication features. In other words, you will still be able to replicate CouchDB or PouchDB with Sync Gateway.

However, Couchbase Lite 2 will only support our new replication API.