[SERVER-76775] Replace `iasserted` with `throw` in `throwWriteConflictException` Created: 02/May/23  Updated: 29/Oct/23  Resolved: 04/May/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.1.0-rc0, 7.0.0-rc1

Type: Improvement Priority: Major - P3
Reporter: Amirsaman Memaripour Assignee: Amirsaman Memaripour
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Backwards Compatibility: Fully Compatible
Backport Requested:
v7.0
Sprint: Service Arch 2023-05-15
Participants:
Linked BF Score: 129

 Description   

SERVER-66205 introduced throwWriteConflictException, which calls into iasserted to throw instances of WriteConflictException. For workloads that excersice contended writes, the additional, non-inlined function calls may cause performance regression. As part of this ticket, we should replace instance of iasserted(someStatus) with the following:

throw ExceptionFor<ErrorCodes::WriteConflictException>(someStatus);



 Comments   
Comment by Githook User [ 05/May/23 ]

Author:

{'name': 'Amirsaman Memaripour', 'email': 'amirsaman.memaripour@mongodb.com', 'username': 'samanca'}

Message: SERVER-76775 Replace `iasserted` with `throw` in `throwWriteConflictException`

(cherry picked from commit 4973d6f85a1a394aff14d4a2124ba993d666c604)
Branch: v7.0
https://github.com/mongodb/mongo/commit/719fb0b5957ed9be0c8544db16b8a6422dc64465

Comment by Githook User [ 04/May/23 ]

Author:

{'name': 'Amirsaman Memaripour', 'email': 'amirsaman.memaripour@mongodb.com', 'username': 'samanca'}

Message: SERVER-76775 Replace `iasserted` with `throw` in `throwWriteConflictException`
Branch: master
https://github.com/mongodb/mongo/commit/4973d6f85a1a394aff14d4a2124ba993d666c604

Comment by Billy Donahue [ 03/May/23 ]

ok thanks for the details.

Comment by Amirsaman Memaripour [ 03/May/23 ]

Does iassert have a significant intrinsic cost relative to throw?

Yes, for contended writes, the additional function calls add up to a 3-4% regression. I was able to verify this by replacing `iasserted` with `throw`.

Is the real issue here that we're using exceptions to handle an expected occurrence (write conflicts)?

I believe so, we throw WriteConflict exceptions and retry on them on the hot-path, they are not an exceptional event, hence my agreement with your statement that Exceptions are not the right tool to identify and handle write conflicts. On another note, the additional overhead can be mitigated with a simple change (this ticket), but rewriting the write-conflict path to rely on a new mechanism is not as trivial.

Comment by Billy Donahue [ 03/May/23 ]

Any throw is going to be expensive in C++. It's just the way it is unfortunately.
Does iassert have a significant intrinsic cost relative to throw?

Is the real issue here that we're using exceptions to handle an expected occurrence (write conflicts)?

Generated at Thu Feb 08 06:33:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.