[GODRIVER-2235] insertMany api successfully inserted part of the documents, when the context deadline exceeds Created: 17/Nov/21 Updated: 27/Oct/23 Resolved: 14/Dec/21 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Critical - P2 |
| Reporter: | Liu Wenzhe | Assignee: | Benji Rewis (Inactive) |
| Resolution: | Gone away | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
mongo-driver version: go.mongodb.org/mongo-driver v1.5.0 mongo server: sharded clusters with 2 shard, version: 4.2, WiredTiger engine
I use InsertMany API to insert 100000 documents (all documents will be hashed to the same shard), when context deadline exceed, it returned error, and part of the documents was inserted. I expect that the InsertMany API is an atomic operation, but it is not.
|
| Comments |
| Comment by PM Bot [ 14/Dec/21 ] |
|
There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information. |
| Comment by Benji Rewis (Inactive) [ 29/Nov/21 ] |
|
Apologies for the delay in response liuwenzhe_neoye@163.com, and thank you for your bug report! If there’s a deadline on the context provided to the operation (i.e. it’s not a nil context nor context.Background()), and the InsertMany operation cannot complete before the deadline expires, it would be expected behavior that only a subset of documents would be inserted and an error would be returned. All this to say that InsertMany is indeed not an atomic operation across the wire. To make the operation more “atomic”, I’d suggest you either use a transaction, which has logic to retry the operation if it fails, or you extend the deadline of your context to account for long-running InsertMany operations. Let me know if neither of those sound like options for you, and we can come up with a different workaround. But, the Go driver does honor context cancellations/expirations even in the middle of operations. |