skip to Main Content

With RESTHeart 5.1.5, I’m trying to add a document to the collection myapp via an HTTP POST.

POST http://xyz:9998/logs/myapp?checkETag=false
{
  "diff": {
    "address": {
      "addressLine2": [
        "152 Broadway, Suite 600",
        "150 Broadway, Suite 600"
      ]
    }
  },
  "tracking": {
    "resourceId": "2f9af48b-2a7c-47ce-bccc-0b29c1188648",
    "login": "MYDOMAINuser1",
    "timestamp": "2024-04-08T15:01:28.671Z"
  }
}

I notice that the performance is not good at all, and that Mongo DB systematically scans all the documents in the collection via a findAndModify (even though I’m doing a POST).

{
  "t": {
    "$date": "2024-04-08T17:01:28.731+02:00"
  },
  "s": "I",
  "c": "COMMAND",
  "id": 51803,
  "ctx": "conn29",
  "msg": "Slow query",
  "attr": {
    "type": "command",
    "ns": "logs.myapp",
    "command": {
      "findAndModify": "myapp",
      "query": {
        "_etag": {
          "$oid": "661406338bd44174052a37a9"
        }
      },
      "new": true,
      "upsert": true,
      "update": {
        "diff": {
          "address": {
            "addressLine2": [
              "152 Broadway, Suite 600",
              "150 Broadway, Suite 600"
            ]
          }
        },
        "tracking": {
          "resourceId": "2f9af48b-2a7c-47ce-bccc-0b29c1188648",
          "login": "MYDOMAIN\user1",
          "timestamp": "2024-04-08T15:01:28.671Z"
        },
        "_etag": {
          "$oid": "661406c88bd44174052a37aa"
        }
      },
      "$db": "logs"
    },
    "planSummary": "COLLSCAN",
    "keysExamined": 0,
    "docsExamined": 2766646,
    "nMatched": 0,
    "nModified": 0,
    "upsert": true,
    "keysInserted": 2,
    "numYields": 2766,
    "queryHash": "EE3A823E",
    "planCacheKey": "EE3A823E",
    "reslen": 611,
    "locks": {
      "ParallelBatchWriterMode": {
        "acquireCount": {
          "r": 2767
        }
      },
      "FeatureCompatibilityVersion": {
        "acquireCount": {
          "w": 2767
        }
      },
      "ReplicationStateTransition": {
        "acquireCount": {
          "w": 2767
        }
      },
      "Global": {
        "acquireCount": {
          "w": 2767
        }
      },
      "Database": {
        "acquireCount": {
          "w": 2767
        }
      },
      "Collection": {
        "acquireCount": {
          "w": 2767
        }
      },
      "Mutex": {
        "acquireCount": {
          "r": 1
        }
      }
    },
    "flowControl": {
      "acquireCount": 2767,
      "timeAcquiringMicros": 1030
    },
    "storage": {
      "data": {
        "bytesRead": 101067941,
        "timeReadingMicros": 96970
      }
    },
    "protocol": "op_msg",
    "durationMillis": 1593
  }
}

I tried adding the parameter checkETag=false in the URL but to no effect.

2

Answers


  1. RESTHeart v5 used to write docs always with upsert semantic using findOneAndReplace

    Since RESTHeart v6 (latest release is v7.7.7) write operations depends on the write mode, i.e. the ?wm query paramenter. Default write operation for POST is insertOne.

    If the write is done checking the _etag, then an index on that must be created on that field (if the collection is created by RESTHeart, it is automatically created, otherwise must be created by you).

    See https://restheart.org/docs/mongodb-rest/write-docs#mongodb-write-operations

    Login or Signup to reply.
  2. If I get https://github.com/SoftInstigate/restheart/blob/6e3ed24712f2db3d41bc404455094e4c88c2679a/commons/src/main/java/org/restheart/exchange/MongoRequest.java#L198 right,

    this.forceEtagCheck = exchange.getQueryParameters().get(ETAG_CHECK_QPARAM_KEY) != null;
    

    only tests whether the checkEtag parameter is present in the query string, and when it is, it forces the check regardless of the value. Basically your ?checkETag=false forces the check.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search