Sync Replication Not Working after data has been deleted from local

I had data on the cloud server I first downloaded that data to my local database through channels then I removed one of the channel from the replicator, the channel data associated with the replicator remains there(is also an issue), so I removed all those channels data manually, after that I reassigned the removed channel to the replicator channels and restarted replication but this time the data are not being downloaded, could anyone can help me to know how to make the data sync again

Hi @messi-010 , can i ask what versions of sync gateway and couchbase lite you’re using? Also can you check the revisions of an example doc you’re seeing this issue with on both ends, and do you have a channel filter set up for this replication?

I am couchbase capella, with the following sync gateway version
{“couchdb”:“Welcome”,“vendor”:{“name”:“Couchbase Sync Gateway”,“version”:“3.0”},“version”:“Couchbase Sync Gateway/3.0.3(1;8187d9a) EE”}

I don’t use any filter but assigning few of channels out of all channels in the replicator config running in the client side

Do you know if the docs on your client are newer revisions than the ones on your server? Revisions | Couchbase Docs

My local document revision id ( a particular doc) is
“revisionID”: “1-bbb10aa7771150bea3fc4b255e4e0df0cdc16181”,

while in the server document revision id (for the same doc) is
“1-bbb10aa7771150bea3fc4b255e4e0df0cdc16181”

which is same,

Now if I delete all these documents manully and restart replication of the same data docs are not downloaded

What I meant was that when you delete the documents they will have newer revision IDs, and so won’t be pulled since you have a newer version locally. Is that the case?

@mohammedcb ,if documents are deleted from local then it is obvious that I will not be able to know their revision Id as these details are present in their doc’s meta data,

if conceptually, after deleting they are assigned a new revisionID , then it might be happening,

As per the revision Id on the server side of the same doc is remaining same after the whole operation

Now, Let’s say I delete the whole app and start replication again by reinstalling it , docs are getting downloaded,

Is there a way to actually resolve this issue without deleting and reinstalling the app?

I’m trying to understand your original description but it’s hard to know what is going on.

I first downloaded that data to my local database through channels

What do you mean by the download? Do you mean using pull replication?

then I removed one of the channel from the replicator, the channel data associated with the replicator remains there(is also an issue)

What do you mean by “the channel data associated with the replicator remains there(is also an issue)”?

so I removed all those channels data manually, after that I reassigned the removed channel to the replicator channels

What do you exactly do here? Is it with code?

this time the data are not being downloaded, could anyone can help me to know how to make the data sync again

We need the info such as:

  1. Sync Function.
  2. What are the changes to the doc that that has the issue in each step?
  3. What are the channels get set to the replicator in each step?
  4. What is CBL version?

Thank you for the reply,

Yes, by download I mean pull replication.

example, say document “A”, belongs to channel “a”,
In 1st pull, in the channel filter of replicator, channel “a” was present so document “A” was pulled to my local devices,
Now, in the 2nd replication is removed the channel “a” from the filter, also removed the access of channel “a” from the current user, so according to auto purge it should be deleted but it remains in my local device .

I purge all the documents that were not the part of current replicator filter, so document “A” was purged because channel “a” was not present in the filter.

The purge happens through queries(In an iOS app, through purgeDocument() method provided in swift)

Then in 3rd replication is reassigned channel “a” to the replication filter and also gave current user the access of channel “a”, assuming that all the earlier purged document (“A”) to be pulled again to my local but this was not happening.

FYI:

1.Sync function :slight_smile:

function (doc, oldDoc, meta) {
  channel(doc.subregionId);
  access("admin", doc.subregionId);
}

A sample of the document:

{
  "ctSegmentTitle": "9CE12F5-637",
  "title": "9CE12F5-133",
  "polygonTitle": "9CE12F5",
  "subregionId": "e2b2ffa7-c536-45eb-8dfc-39aafffe6f3a",
  "geoLong": -117.32535106847496,
  "nearestPoint": null,
  "overheadLinemile": "0.01",
  "geometry": {
    "type": "LineString",
    "coordinates": [
      [
        -117.325346000731,
        47.66009201333238
      ],
      [
        -117.3253561362189,
        47.65937191752165
      ]
    ]
  },
  "id": "00005d64-6006-41c7-8e76-0b8891540f81",
  "centroid": {
    "type": "Point",
    "coordinates": [
      -117.32535106847496,
      47.659731965427014
    ]
  }
}
  1. No changes on the doc were done.

1st pull - channel was present in filter(replicator.channels()) and and user has access to that channel
2nd pull - channel was removed from the filter and revoked the access of that channel from the user
3rd pull- channel was added to the filter and user was granted access to the channel.

SG:3.0.4,
CBL:3.0.2,
CB server:7.1.3

Now, in the 2nd replication is removed the channel “a” from the filter, also removed the access of channel “a” from the current user, so according to auto purge it should be deleted but it remains in my local device.

  • Can you make sure that the user doesn’t have access to the document from the other channel besides the channel ‘a’? Normally, you can use SG REST API to check if user still has access to the doc or not from a browser (e.g. http://locahost:4984//).

  • You may share SG log and CBL log when you perform this step if you confirm that the user doesn’t access to the document via the other channels.

Then in 3rd replication is reassigned channel “a” to the replication filter and also gave current user the access of channel “a”, assuming that all the earlier purged document (“A”) to be pulled again to my local but this was not happening.

If the user still has access to the doc from the other channels, re-assigning the doc to the channel ‘a’ will have no effect to the on-going replication unless the doc has new update even though the doc was purged manually from the local database.

This will depend on your app logic but you may not need to use channel filter. When using channel filter, it means that you want to pull the doc only from the specified channels. However, from your provided steps, you also removed the channel filter once the doc was removed from the channel so the purpose of using the channel filter here is unclear.