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

Changes limit incorrectly applied in case of CBG-946

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.8.0
    • 3.0
    • SyncGateway
    • Security Level: Public
    • None
    • CBG Sprint 64
    • 1

    Description

      Small edgecase/regression here.

      Scenario

      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.

      Issue

      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.

      Repro

      • 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
      

      Attachments

        Issue Links

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

          Activity

            James Flather James Flather created issue -
            James Flather James Flather made changes -
            Field Original Value New Value
            Required Mobile Fields Mandatory:
             - CBL / SG Version:
               - SG Config:
             - Steps to Reproduce:
             - Actual Result:
             - Expected Result:
             - Logs :
                  SGW LOGS: sgcollect info
                  CBL LOGS:
                  Logcat LOGS: for Android tickets
             - Github link for the code:
             - Jenkins job failure link:
             - Pytest Command
             - What is the last build this test passed:
            James Flather James Flather made changes -
            Link This issue blocks CBSE-9384 [ CBSE-9384 ]
            adamf Adam Fraser made changes -
            Assignee The One [ the one ] Adam Fraser [ adamf ]
            adamf Adam Fraser made changes -
            Fix Version/s Lithium [ 16180 ]
            adamf Adam Fraser made changes -
            Sprint CBG Sprint 64 [ 1367 ]
            adamf Adam Fraser made changes -
            Rank Ranked lower
            adamf Adam Fraser made changes -
            Link This issue is cloned by CBG-1252 [ CBG-1252 ]
            adamf Adam Fraser made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            adamf Adam Fraser made changes -
            Status In Progress [ 3 ] In Review [ 10107 ]

            Build sync_gateway-3.0.0-99 contains sync_gateway commit 25a17b2 with commit message:
            CBG-1246 Apply limit correctly during channel backfill (#4902)

            build-team Couchbase Build Team added a comment - Build sync_gateway-3.0.0-99 contains sync_gateway commit 25a17b2 with commit message: CBG-1246 Apply limit correctly during channel backfill (#4902)
            Automated transition triggered when Adam Fraser merged pull request #4902 in GitHub -
            Resolution Fixed [ 1 ]
            Status In Review [ 10107 ] Resolved [ 5 ]
            adamf Adam Fraser made changes -
            Status Resolved [ 5 ] Closed [ 6 ]

            People

              adamf Adam Fraser
              James Flather James Flather
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty