facebookarchive / flashback

Capture and replay real mongodb workloads
Other
217 stars 72 forks source link

The order of $hint and $orderby is not preserved #31

Closed wojcikstefan closed 8 years ago

wojcikstefan commented 9 years ago

Since a JS object preserves order of the keys while Python and Go don't, we need to make sure that the keys in $hint and $orderby are in the right order.

Right now for example, an operation in the profile collection can look like this:

{
  "op": "query",
  "ns": "closeio.activity",
  "query": {
    "$query": {
      "organization": DBRef("organization", "orga_awqeiorqwejrlkqwerklqjwe"),
      "lead": DBRef("lead", "lead_asdlkjflaksjdflkajsdlfqiwueroiqu")
    },
    "$hint": {
      "lead": 1,
      "date_created": -1
    },
    "$orderby": {
      "date_created": -1
    }
  },
  ...
  "ntoreturn": 51,
  "ntoskip": 0,
}

... and is recorded as:

{"ns": "closeio.activity", "ts": {"$date": 1443222746092}, "ntoreturn": 51, "query": {"$hint": {"date_created": -1, "lead": 1}, "$orderby": {"date_created": -1}, "$query": {"organization": {"$ref": "organization", "$id": "orga_awqeiorqwejrlkqwerklqjwe"}, "lead": {"$ref": "lead", "$id": "lead_asdlkjflaksjdflkajsdlfqiwueroiqu"}}}, "ntoskip": 0, "op": "query"}

... and when you try to replay it, MongoDB returns:

2015-09-25T16:21:55.279-0700 I QUERY    [conn5792] assertion 17007 Unable to execute query: error processing query: ns=closeio.activity limit=51 skip=0
Tree: $and
    lead == { $ref: "lead", $id: "lead_asdlkjflaksjdflkajsdlfqiwueroiqu" }
    organization == { $ref: "organization", $id: "orga_awqeiorqwejrlkqwerklqjwe" }
Sort: { date_created: -1 }
Proj: {}
 planner returned error: bad hint ns:closeio.activity query:{ $hint: { date_created: -1, lead: 1 }, $orderby: { date_created: -1 }, $query: { organization: { $ref: "organization", $id: "orga_awqeiorqwejrlkqwerklqjwe" }, lead: { $ref: "lead", $id: "lead_asdlkjflaksjdflkajsdlfqiwueroiqu" } } }
tjworks commented 8 years ago

Similarly, a query with sub-document also has this problem:

In the system.profile, an entry like this:

{
"op" : "update",
"ns" : "ceairdb.invSegInfo",
"query" : {
    "flightInfo" : {
        "carrier" : "MU",
        "flightNo" : "9179",
        "oriEng" : "PVG",
        "desEng" : "CGQ",
        "flightDt" : ISODate("2016-02-05T16:00:00Z")
    }
},
"updateobj" :  { }
}

When replayed, the query looked like this:

{
"flightInfo" : {
    "oriEng" : "YNT",
    "flightNo" : "549",
    "desEng" : "ICN",
    "carrier" : "MU",
    "flightDt" : ISODate("2016-01-06T16:00:00Z")
}
}

As a result, the replay fails for every query that uses a sub document.

tredman commented 8 years ago

This should be fixed thoroughly by https://github.com/ParsePlatform/flashback/pull/35 - please open a new issue if you are still experiencing problems with ordering. Note that you will need to re-record any previous sessions to take advantage of the fix, since the record output file format has changed.