[SERVER-65024] Multiple documents with the same _id value make reIndex invariant Created: 29/Mar/22 Updated: 29/Oct/23 Resolved: 01/Apr/22 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 5.3.2, 5.0.8, 6.0.0-rc0, 4.4.15 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Daniel Gomez Ferro | Assignee: | Yuhong Zhang |
| 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 | ||||||||||||||||||||
| Backport Requested: |
v5.3, v5.0, v4.4, v4.2
|
||||||||||||||||||||
| Sprint: | Execution Team 2022-04-04, Execution Team 2022-04-18 | ||||||||||||||||||||
| Participants: | |||||||||||||||||||||
| Description |
|
In a cluster affected by Our remediation process guide requires running reIndex to fix inconsistencies detected by validate. In master, when reIndex encounters duplicate _ids it invariants. The server ends up in a bad state because it tries to build the _id index during recovery but fails every time due to the duplicate values. In 4.4 the behaviour is a bit different, reIndex adds the duplicate entries to the index and validate invariants when it encounters two duplicate values in a unique index. |
| Comments |
| Comment by Githook User [ 28/Apr/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'Yuhong Zhang', 'email': 'yuhong.zhang@mongodb.com', 'username': 'YuhongZhang98'}Message: (cherry picked from commit 5985d757ddc2645fb1b5df88f78abf6b9a833452) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Githook User [ 19/Apr/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'Yuhong Zhang', 'email': 'yuhong.zhang@mongodb.com', 'username': 'YuhongZhang98'}Message: (cherry picked from commit 5985d757ddc2645fb1b5df88f78abf6b9a833452) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Githook User [ 19/Apr/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'Yuhong Zhang', 'email': 'yuhong.zhang@mongodb.com', 'username': 'YuhongZhang98'}Message: (cherry picked from commit 5985d757ddc2645fb1b5df88f78abf6b9a833452) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Githook User [ 01/Apr/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'Yuhong Zhang', 'email': 'yuhong.zhang@mongodb.com', 'username': 'YuhongZhang98'}Message: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Yuhong Zhang [ 30/Mar/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
It turns out that our foreground index builds through IndexBuildsCoordinator::createIndex() are not checking any index constraints. I managed to reproduce the duplicate key case in a unit test:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Louis Williams [ 30/Mar/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks for investigating, yuhong.zhang. I believe we could have problems with other places where we use foreground builds in the code, like initial sync as well. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Yuhong Zhang [ 30/Mar/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The history and code paths of various index builds are admittedly quite hard to follow, so please correct me if I missed anything louis.williams daniel.gomezferro. I believe there are two related issues in the current code:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Yuhong Zhang [ 29/Mar/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
On the master branch, reindexing a unique index will ignore duplicate keys and succeed instead of failing.
|