CouchDB
  1. CouchDB
  2. COUCHDB-1206

View ETags may be incorrect if ?include_docs=true is specified

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.1
    • Fix Version/s: 1.1.1, 1.2
    • Component/s: None
    • Labels:
      None

      Description

      Change COUCHDB-799 altered the way ETags are assigned to views, by having the ETag change only when the view index changes, not when any document changes. Unfortunately this means that a view with the "?include_docs=true" option can return an incorrect ETag. The reason is that if a document in the view is changed, but the change doesn't affect the view index, the result of the GET will change (it will contain the document's updated contents), but the ETag won't. This can result in stale data if the client uses a conditional GET, because it'll get a 304 even though the prior response is out of date.

      Robert Newson's analysis on the user@ list is "I think the sanest fix is to make view etags for include_docs=true use the original algorithm, so that they always change if the database changes."

        Issue Links

          Activity

          Hide
          Randall Leeds added a comment -

          Could we include the _rev and _id of the document iff it emitted a non-zero number of rows? Then the etag wouldn't change when a document emits no rows, but would change even if the emitted data stays the same (_rev changed). Without looking at the view code I don't know if this is easy or reasonable, but I thought I'd mention it before you dive in.

          Show
          Randall Leeds added a comment - Could we include the _rev and _id of the document iff it emitted a non-zero number of rows? Then the etag wouldn't change when a document emits no rows, but would change even if the emitted data stays the same (_rev changed). Without looking at the view code I don't know if this is easy or reasonable, but I thought I'd mention it before you dive in.
          Hide
          Robert Newson added a comment -

          Wouldn't that defeat COUCHDB-799?

          Show
          Robert Newson added a comment - Wouldn't that defeat COUCHDB-799 ?
          Hide
          Randall Leeds added a comment -

          Oh, dang. I suppose you're right. Do what you said first.

          Show
          Randall Leeds added a comment - Oh, dang. I suppose you're right. Do what you said first.
          Hide
          Marcello Nuccio added a comment -

          This fix does not work with `_all_docs` view.
          Tested on CouchDB-1.1.1.

          Show
          Marcello Nuccio added a comment - This fix does not work with `_all_docs` view. Tested on CouchDB-1.1.1.
          Hide
          Robert Newson added a comment -

          The all_docs view includes the update_seq, so the ETag is still correct. What problem are you experiencing?

          Show
          Robert Newson added a comment - The all_docs view includes the update_seq, so the ETag is still correct. What problem are you experiencing?
          Hide
          Marcello Nuccio added a comment - - edited

          The following queries return the same ETag, but different bodies (I have created two docs with "id1" and "id2"):

          curl -v 'http://localhost:5984/db/_all_docs?keys=%5B%22id1%22,%22id2%22%5D'
          curl -v 'http://localhost:5984/db/_all_docs?keys=%5B%22id1%22,%22id2%22%5D&include_docs=true'

          If I do the same query on a custom view, the ETag changes.

          Show
          Marcello Nuccio added a comment - - edited The following queries return the same ETag, but different bodies (I have created two docs with "id1" and "id2"): curl -v 'http://localhost:5984/db/_all_docs?keys=%5B%22id1%22,%22id2%22%5D' curl -v 'http://localhost:5984/db/_all_docs?keys=%5B%22id1%22,%22id2%22%5D&include_docs=true' If I do the same query on a custom view, the ETag changes.
          Hide
          Robert Newson added a comment -

          Erm, so what?

          Show
          Robert Newson added a comment - Erm, so what?
          Hide
          Marcello Nuccio added a comment -

          OK, it's time to go to sleep... sorry...

          Show
          Marcello Nuccio added a comment - OK, it's time to go to sleep... sorry...
          Hide
          Randall Leeds added a comment -

          I verified that the ?include_docs=true endpoint changes its ETag when a document is updated. It is of no importance whether or not the view with and without docs included have the same ETag as they are different URLs. Thanks for the concern, Marcello.

          Show
          Randall Leeds added a comment - I verified that the ?include_docs=true endpoint changes its ETag when a document is updated. It is of no importance whether or not the view with and without docs included have the same ETag as they are different URLs. Thanks for the concern, Marcello.
          Hide
          Marcello Nuccio added a comment -

          Yes. I've realized that the URL was different in the moment that Robert asked "Erm, so what?"... It was a long working day...

          Show
          Marcello Nuccio added a comment - Yes. I've realized that the URL was different in the moment that Robert asked "Erm, so what?"... It was a long working day...

            People

            • Assignee:
              Robert Newson
              Reporter:
              Jens Alfke
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development