Purged documents are being replicated down to devices after being purged

Hey,

We’re having a problem where documents that have been purged locally (on device using couchbase lite) are being replicated back down to the device on replication, despite there not being any updates to the documents on another device or on the server. Our serverside db is connected to sync-gateway and other than that we don’t perform any write operations on it. The documents we’re archiving are really old (1yr+), so it’s essentially impossible for all of them for a single user (15k+ at times) to be manually edited. This also doesn’t happen reliably, only for some devices, some of the time.

The only thing I can think of is that sync-gateway is performing a re-sync in the background for some reason, but we haven’t issued one explicitly.

A related thought is that a re-sync of our db may solve the problem if we build the same filter into sync gateway. In other words, if the app has a purge function that says: if (doc > 1yr old) purge, and an equivalent statement to the sync function that says: if (doc > 1yr old) reject, and then re-sync the db?

We’re currently using outdated architecture because of the removal of conflict resolution (we posted about it here), so are on cb lite 1.4, sync gateway 1.5 and couchbase server 5.0.

Is there anything else that could be causing this?

This probably means the client’s replication ‘checkpoint’ gets invalidated. This is rare, but it can happen if the server is restored from backup or if the client crashes at the wrong moment (after updating the server-side checkpoint but before persisting its local checkpoint.) When that happens, the client will scan through everything on the server and pull any revisions it doesn’t have. Since purging by design removes all traces of a document, including sync metadata, the client has no idea it used to have such a document and will pull it again.

The best solution to this is to purge the doc on the server side too, or at least to remove it from the channels that the client would be pulling from.

1 Like