Description
Scenario
- Doc test2 is created in channels [ foo , bar ].
- User replicates channel foo and pulls rev 1 of the document.
- Doc test2 is updated to remove it from channel foo, leaving just bar. (Edit: previously typo'd now corrected)
- Doc test2 is updated again, remaining in channel bar only.(Edit: previously typo'd now corrected)
- Some time passes
- User replicates channel foo again.
Expected behaviour
- User's local DB stays at rev 1 for test2 †
Observed behaviour
*User's local DB purges test2
Repro
- Add doc
$ curl localhost:4985/db/test2 -X PUT -H 'Content-type: application/json' -d '{"channels":["foo", "bar"]}'
{"id":"test2","ok":true,"rev":"1-5467c30804fb9448df4873941c0c8ed8"}
- Replicate channel foo from device and confirm doc is present:
$ ~/Downloads/cblite ls "`find . -type d -name '*.cblite2'`"; ~/Downloads/cblite cat "`find . -type d -name '*.cblite2'`" test2
|
test2
|
{
|
"_id": "test2",
|
"channels": [
|
"foo",
|
"bar"
|
]
|
}
|
- Update doc to remove channel foo:
$ curl localhost:4985/db/test2 -X PUT -H 'Content-type: application/json' -d '{"channels":["bar"], "_rev":"1-5467c30804fb9448df4873941c0c8ed8", "extra": "so extra"}'
|
|
{"id":"test2","ok":true,"rev":"2-c4d10e1effc2e6bef6ac072e69c9ac59"}
|
- Update doc again, so the removal rev is not the latest:
Edit: this was the wrong snippet before - updated
$ curl localhost:4985/db/test2 -X PUT -H 'Content-type: application/json' -d '{"channels":["bar"], "_rev":"2-c4d10e1effc2e6bef6ac072e69c9ac59", "extra": "so extra"}'
|
|
{"id":"test2","ok":true,"rev":"3-989061051071c99469ac36657e86bdf3"}
|
- Simulate time passing by restarting SG (to clear rev cache) and deleting the old rev backup from the CB bucket.
- Replicate channel foo again, and check the state of the document in local db:
$ ~/Downloads/cblite ls "`find . -type d -name '*.cblite2'`"; ~/Downloads/cblite cat "`find . -type d -name '*.cblite2'`" test2
|
(No documents)
|
Error: Document "test2" not found.
|
†I'm unsure if we define this behaviour explicitly. In the case of the removal also being the latest, there's an argument for pulling that anyway. In this case however, the revision now in channel bar has no relation to channel foo and should not be pulled.