javascriptnode.jscouchbasecouchbase-sync-gateway

Why does couchbase-sync-gateway return "Failure adding Rev to RevTree"?


I tried the procedure I read on Couchbase to resolve conflicts Resolving Conflicts, sync-gateway 1.5.

From couchbase-sync-gateway I get a result from _bulk_docs, this error but I can't find any feedback:

2019-09-13T12:10:36.932Z HTTP:  #754: GET /bucket_01/id.00001?open_revs=all  (as admin)
2019-09-13T12:10:37.079Z HTTP:  #755: POST /bucket_01/_bulk_docs
2019-09-13T12:10:37.079Z HTTP: #755:     --> 401 Login required  (0.4 ms)
2019-09-13T12:10:37.203Z HTTP:  #756: POST /bucket_01/_bulk_docs  (as admin)
2019-09-13T12:10:37.210Z    BulkDocs: Doc "id.00001" --> 500 Internal error: Failure adding Rev to RevTree (Failure adding Rev to RevTree)

The error is "Failure adding Rev to RevTree", I understand what happened but I can't fix it.

UPDATE: 15.09.2019

The response of bulk_docs with CRUD key log:

2019-09-15T21:14:28.232Z HTTP:  #006: POST /cfond_09/_bulk_docs  (as admin)
2019-09-15T21:14:28.280Z CRUD: Stored doc "id.00001" / "6-baf5790d2d436f2e7af2715d59c1c3ce"
2019-09-15T21:14:28.284Z CRUD: Stored doc "id.00001" / "9-1c76fa9e825ca5eff39db0752a06eac2"
2019-09-15T21:14:28.286Z CRUD: Failed to add revision ID: 4-3ceed538cc59369128c25e3858183677, error: doc: id.00001, RevTree addRevision, already contains rev "4-3ceed538cc59369128c25e3858183677"
2019-09-15T21:14:28.286Z    BulkDocs: Doc "id.00001" --> 500 Internal error: Failure adding Rev to RevTree (Failure adding Rev to RevTree)
2019-09-15T21:14:28.290Z CRUD: Stored doc "id.00001" / "5-ea9b3e32746fcb844d2004bc38061d40"

Only one revision didn't go well, I think I have three revisions into the Bodymap of the same document and one of this its body is like:

[...]
8: "{\"_deleted\":true}",
[...]

Status of the document:

    [...]
    "history": {
      "revs": [
        "4-422342a11e82d6368a08c62e83ecf2b0",
        "8-fb0b278568a4bf668f814e0072df2da9",
        "2-92501b3c9bbbeca8b470f6d12d9f68c2",
        "4-ab334e71ddd5b5537f77af109aed9af2",
        "5-63f080d6c319ed3f7f4b3bd5e5e2dd0c",
        "1-9d6dfa10417c47474cb8313c047fc3f0",
        "3-4245004b12e10b31a1bcbe38505eb5b6",
        "7-8e2994be714407787701584156ec150f",
        "5-d29926e6904e77678c7970c1bfa7e6ea",
        "4-3ceed538cc59369128c25e3858183677",
        "6-a7117b51d59a9fd179f369ad965be08e"
      ],
      "parents": [
        -1,
        7,
        5,
        -1,
        3,
        -1,
        2,
        10,
        0,
        -1,
        4
      ],
      "deleted": [
        0,
        8,
        9
      ],
      "bodymap": {
        "6": "{ ... all body ... }",
        "8": "{\"_deleted\":true}",
        "9": "{ ... all body ... }"
      }, [...]

the offending revision is present in the RevTree. I don't understand where the problem is.

UPDATE 16.09.2019

I think I understand what happens in Couchbase & Sync-Gateway: a document has forked in two documents, one 3-XYZ, and 4-QWE. The two documents are equal but differ from the revision id. When I call the bulk_docs 4-QWE become 5-IOP, and 3-XYZ become 4-QWE. But the 4-QWE is already presenting in RevTree, error 500. It's what I think, anybody agrees?

UPDATE 20.09.2019

The error has disappeared. I added a new field in the document what I save in the bulk docs. The bulk_docs works properly but the conflict also remains the Bodymap. Do you know any solutions?


Solution

  • There are 3 possible scenarios you could get this error:

    1. RevTree addRevision, empty revid is illegal
    2. RevTree addRevision, already contains rev "..."
    3. RevTree addRevision, parent id "..." is missing

    https://github.com/couchbase/sync_gateway/blob/818566998a7d22cc6d44fb39868c3cd520e7ed2c/db/revtree.go#L283-L295

    The particular error you're hitting should be logged, if you enable the CRUD log key: https://docs.couchbase.com/sync-gateway/1.5/config-properties.html#logging-default-logKeys

    That should give you a hint as to what is going wrong.