Impact of deleting document from server on mobile database

#1

Good morning everybody

we are using couchbase lite 1.4 for android with sync_gateway 1.4 and unfortunately we cannot move from those versions. We also have a server side implemented with node.js

We have a couple of scenario which I would like to discuss:

Scenario 1. Creation from the phone and delete on the server
We generate from an android application some documents just to feed the server, the phone does not care about the document once it has been created. The app always has a continuous push/pull replication active
Then the server will elaborate the document, and it move it out from the channel of the phone.
The server once it has elaborated the information it will delete the document, so it is gone for us.
So here I have a some questions:

  • Has the phone to delete or purge the document after the creation? or is it automatically done by the change of the channel?
  • Must the application purge the local document? when we have to do it? Do we need to check the actual sync to the server before the purging or is it better to set an expiration time?
  • By our tests it looks like moving the document out of the phone channel will remove the document from the mobile application, but it’s not clear if it still consuming space or it has any impact on the performance of the database.

Scenario 2. A Document on phone channel will be deleted by the server
In this case the document is on the phone channel, and the server decide to delete the document (using the sync_gateway api) and propagate the deletion on any mobile device.
According to https://docs.couchbase.com/sync-gateway/1.4/sync-function-api.html the deleted document will not be part of the channel of the phone.
I don’t really understand how the mobile application can be notified about the deletion of the document on the server if the tombstone is out of the phone channel. Then what happens if the phone is offline and days later it will be turned on? Does it still get the deletion notification?
Sometime it happens the document is deleted from the server but it still exists on the mobile database, and also there is no way to notify the deletion without re-generate the document and deleting it again.

Sorry to be so long.
It’s very important to me to truly understand the lifecycle of the document with or without the usage of the channel.

Thanks for any feedback, comment question…

-Paolo

#2

For the first scenario:

  • Has the phone to delete or purge the document after the creation? or is it automatically done by the change of the channel?

No, a document will not be automatically purged when a document was removed from the user’s channel. There is an empty revision called removed revision sent to client to mark as removed.

  • Must the application purge the local document? when we have to do it? Do we need to check the actual sync to the server before the purging or is it better to set an expiration time?

It depends. The removed revision consumes very little space but some application still wants to remove the it. You can try to use Replication. getPendingDocumentIDs() to check whether the documents has been pushed to the server or not. If Yes, you can purge the document.

  • By our tests it looks like moving the document out of the phone channel will remove the document from the mobile application, but it’s not clear if it still consuming space or it has any impact on the performance of the database.

Same answer as the first question.

#3

For the second scenario:

If the user still have access to the channel, the user will be notified with the removed revision when a document is removed from the channel. If the application is offline and later turn on, the application should still receive the removed revision as long as the user still has an access to the channel.

#4

Just curious, about the reasons you cannot move off of 1.4. Are there missing platforms/features that prevent you from moving?

#5

Hi, sorry for the late reply, the issue with couch base lite >=2.0 is the missing method Document.putProperties(), as far I saw it was removed in favor of MutableDocument setString(.) setInt() and we cannot rewrite how we save all our documents

#6

Sorry for the late reply, I was asking this because we had this strange behavior on our app. It happened only once, but at the end the document was present on the phone, even if deleted on the server, using live query or any other get method on the mobile, I was able to find it.
Only when I have recreated the document on the server and I deleted it, the phone got the _deleted document.
BTW I noted the version where really far, on mobile was version 5_abc… on the server 95_qwe…
We have a revision limit of 20, I am start thinking is it might be the reason.

#7

Thank you very much for the reply, I will try to use the getPendingDocumentIDs() and when it’s not present anymore on the list I will purge it.

#8

Really? You can easily write a wrapper to give you the behavior you want. Make a mutable copy of the document, call setData on it with your updated Map, then save the mutable document.

#9

This is illuminating. Thanks. I will try ASAP