Uploaded image for project: 'Couchbase Gateway'
  1. Couchbase Gateway
  2. CBG-1252

[2.8.1 Backport] CBG-1246 - Changes limit incorrectly applied in case of CBG-946



    • Bug
    • Resolution: Fixed
    • Major
    • 2.8.1
    • 2.8.0
    • SyncGateway
    • Security Level: Public
    • None
    • CBG Sprint 65
    • 1


      Small edgecase/regression here.


      A changes feed for a single channel (N.B. not required to be single, but easier to demonstrate) would include backfills, except under the changes in CBG-946 some of these backfills are not included as they are tombstones. The changes request specified a limit N, but no since value (issue still applies with since != 0, but again, easier to demo).

      Expected behaviour
      Up to N live documents are returned in the response. If <N documents are returned, this is because there are no more documents in the channel beyond what's been sent.

      Observed behaviour

      N-T documents are returned, where T is the number of backfill tombstones.


      We pass the limit for the whole feed down to each channel - this way we get as small a query as we can reasonably run for each channel. E.g. if the limit is 5000, we ask each channel for up to 5000 and take the lowest 5000 across that union. You could get anything up to channels*5000 results, but we filter it in the changes level processing.

      This is a problem if we're then discarding anything implicitly (like we now do under CBG-946) because the limit has already been applied. IIRC we had similar issues in the Views era with active_only, and I notice we now pass that down and loop at the query level to prevent this issue there.


      • Have a user with no access to channel bar:

      "users": {
        "GUEST": {
          "admin_channels": [
          "disabled": true
        "jflath": {
          "admin_channels": ["foo"],
          "password": "pass"

      • Add 5 docs to channel bar:

      $ curlj 'localhost:4985/db/_bulk_docs' -d '{"new_edits":false, "docs":[{"channels":"bar", "_id":"1", "_rev": "1-deadbeef"},{"channels":"bar", "_id":"2", "_rev": "1-deadbeef"},{"channels":"bar", "_id":"3", "_rev": "1-deadbeef"},{"channels":"bar", "_id":"4", "_rev": "1-deadbeef"},{"channels":"bar", "_id":"5", "_rev": "1-deadbeef"}]}'

      • Update them to create 5 tombstones:

      $ curlj 'localhost:4985/db/_bulk_docs' -d '{"new_edits":true, "docs":[{"channels":"bar", "_id":"1", "_rev": "1-deadbeef", "_deleted": true},{"channels":"bar", "_id":"2", "_rev": "1-deadbeef", "_deleted": true},{"channels":"bar", "_id":"3", "_rev": "1-deadbeef", "_deleted": true},{"channels":"bar", "_id":"4", "_rev": "1-deadbeef", "_deleted": true},{"channels":"bar", "_id":"5", "_rev": "1-deadbeef", "_deleted": true}]}'

      • Give user access to bar

      $ curlj localhost:4985/db/_user/jflath -X PUT -d '{"admin_channels": ["foo", "bar"]}'

      • Add a further document to bar:

      $ curlj  'localhost:4985/db/' -X POST -d '{"channels":"bar"}'

      • Request changes for user with limit <5 - observe that newest doc is not returned:

      $ curlj 'localhost:4984/db/_changes?limit=3' -u jflath:pass


        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.



              adamf Adam Fraser
              James Flather James Flather (Inactive)
              0 Vote for this issue
              1 Start watching this issue



                Gerrit Reviews

                  There are no open Gerrit changes