[SERVER-29762] Updating multiple elements in an array produces incorrect results Created: 21/Jun/17 Updated: 30/Oct/23 Resolved: 06/Jul/17 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | 3.5.10 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Max Hirschhorn | Assignee: | Justin Seyster |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||||||||
| Operating System: | ALL | ||||||||||||||||||||||
| Steps To Reproduce: |
|
||||||||||||||||||||||
| Sprint: | Query 2017-07-10 | ||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||
| Linked BF Score: | 0 | ||||||||||||||||||||||
| Description |
|
This appears to be the result of the changes from ab165e7 as part of Additionally, I think it is worth mentioning that this issue was only detected because the update operation produced a different result (i.e. the correct one) when applied by the secondary despite having the same $set modifier.
|
| Comments |
| Comment by Githook User [ 06/Jul/17 ] |
|
Author: {u'username': u'jseyster', u'name': u'Justin Seyster', u'email': u'justin.seyster@mongodb.com'}Message: This patch moves getPositionalPathSpecification() from its location in There are two problems with trying to look up an array element by The second problem is that mutable BSON does not maintain the |
| Comment by Justin Seyster [ 23/Jun/17 ] |
|
max.hirschhorn Thanks for this amazing code snippet! I was able to convert it directly to a unit test, which made it pretty simple to track down the problem. Interestingly, the reason that we only see this happen when updating array indexes >= 10 is that the bug only triggers when updating array elements in descending numerical order. The new update code applies updates in lexicographic order, so "10" applies before "2" for this case, exposing the problem. Our update code expects to be able to look up a BSON array element using a string representation of the index. However, the path_support code for adding elements to an array (with padding) does not give the new elements any fields names. (Presumably, each of these elements gets a field name matching its numeric index when the mutablebson gets serialized, but I haven't verified that yet.) Here, the "10" update pads the empty array so that it now contains a "2" element, but when the update attempts to perform a look up on "2" it fails and then erroneously appends to the array instead. A related problem is that updates that index an array element with a leading zero will also fail, because a lookup on "02" will not find element "2" in an array. |