Skip to content

Fix wait_for_caching_feed && add to create_document and delete_document - #510

Open
torcolvin wants to merge 2 commits into
mainfrom
create-document-caching-feed
Open

Fix wait_for_caching_feed && add to create_document and delete_document#510
torcolvin wants to merge 2 commits into
mainfrom
create-document-caching-feed

Conversation

@torcolvin

Copy link
Copy Markdown
Collaborator

Fix wait_for_caching_feed && add to create_document and delete_document

  • The first attempt at wait_for_caching_feed didn't work as I thought. request_plus does not apply to either continuous or doc_id filtered feeds. To work around this, I created post-filtering of changes feeds for docids after getting the entire set of documents over changes feed. This is not efficient but there are not that many circumstances where this is used. In the future, I can add a wait function to wait for doc_ids + revids.
  • Add argument to create_document/delete_document for wait_for_caching_feed
  • Add option for RemoteDocument to be a tombstone to make delete_document API more clear
  • Start reading changes feed at 0, but retry on the last since value. If this was called from a single client as the API is right now, the request_plus should take care of it, but if we use this wait technique elsewhere, this needs to retry changes feed logic.

The changes in #495 do not need this for upserted or removed documents, but there are race conditions around upserting those documents and doing a one shot replication for Couchbase Lite, so I'm making this code stronger in the helpers.

torcolvin and others added 2 commits August 27, 2026 21:10
The changes feed read was passing both `doc_ids` and `request_plus`, which are
mutually exclusive in effect. Sync Gateway consumes `RequestPlusSeq` only in
`SimpleMultiChangesFeed`; supplying `doc_ids` routes the request to
`DocIDChangesFeed`, which calls `GetDocument` per id straight out of the bucket
and never consults the channel cache. `request_plus` was therefore ignored and
the call returned as soon as the document was readable, which is before the
caching feed has it.

Measured on a 3-node cluster: the call returned in ~9ms with the document
absent from the unfiltered feed. Reading the unfiltered feed instead, it blocks
until the revision is actually cached (~1.5s in two of five samples) and the
document is in the feed on every return.

The parameter still populates `seq` and still detects a concurrent write the
same way; only the wait it advertised was missing. The error message no longer
dumps the whole feed, now that the feed is not filtered to one document.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
- The first attempt at wait_for_caching_feed didn't work as I thought.
  request_plus does not apply to either continuous or doc_id filtered
  feeds. To work around this, I created post-filtering of changes feeds
  for docids.
- Add argument to create_document/delete_document
- Add option for RemoteDocument to be a tombstone
- Start reading changes feed at 0, but retry on the last since value. If
  this was called from a single client, the request_plus should take
  care of it, but if we use this wait technique elsewhere, this needs to
  retry changes feed logic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants