[SERVER-24104] Replace std::duration types with implementations that throw exceptions on overflow Created: 09/May/16  Updated: 25/Jan/17  Resolved: 17/May/16

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 3.3.8

Type: Improvement Priority: Major - P3
Reporter: Andy Schwerin Assignee: Andy Schwerin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
related to SERVER-24739 Unhandled duration_cast exception in ... Closed
Backwards Compatibility: Fully Compatible
Sprint: Sharding 14 (05/13/16), Sharding 15 (06/03/16)
Participants:
Linked BF Score: 0

 Description   

The std::duration types, which underly stdx::duration, have undefined behavior on overflow and in some other situations that we can easily and inadvertently encounter. Since we do not require optimal arithmetic performance on our duration types, it would be better to replace them with implementations that throw on overflow.



 Comments   
Comment by Githook User [ 20/May/16 ]

Author:

{u'username': u'hanumantmk', u'name': u'Jason Carey', u'email': u'jcarey@argv.me'}

Message: SERVER-24104 sfinae duration ctor overloads

We can't just static_assert in the duration constructors, because we need overload resolution to
continue and find things like implicit conversions that then dispatch to default copy constructors.

This adds standard required sfinae to those ctors. In other cases where the standard uses sfinae,
it's either not needed for us (because we don't require extension of duration types and we only have
integral duration reps) or appears not necessary now (several arithmetic overloads could
theoretically have other targets, but for the moment I think it's unlikely that we'd expect
Milliseconds{} / MySpecialNonRepType{} to actually work). We'll have to revisit sfinae in those cases
if we ever do.
Branch: master
https://github.com/mongodb/mongo/commit/fb052c13742deab981c7ba729dad36e33bdd7393

Comment by Andy Schwerin [ 20/May/16 ]

We raised the GCC compiler minimum to 5.3 in SERVER-23518, as part of development release 3.3.6.

Comment by Igor Canadi [ 20/May/16 ]

https://github.com/mongodb/mongo/commit/97f24aa42d86dcadd789ba2c9e144709fa7a7aab uses built-in functions only available in gcc since 5.0 version: https://gcc.gnu.org/gcc-5/changes.html. I get this failure with gcc 4.8.5: https://gist.github.com/igorcanadi/1dca04aa6f6506a4ce6ffb5cf5fb72d3

Are you dropping support for gcc before 5.0?

Comment by Githook User [ 18/May/16 ]

Author:

{u'username': u'visemet', u'name': u'Max Hirschhorn', u'email': u'max.hirschhorn@mongodb.com'}

Message: SERVER-24104 Fix compile on OS X.
Branch: master
https://github.com/mongodb/mongo/commit/18d40b1e6eeaabb4cca0997962a871b2a5caba9f

Comment by Githook User [ 17/May/16 ]

Author:

{u'username': u'spencerjackson', u'name': u'Spencer Jackson', u'email': u'spencer.jackson@mongodb.com'}

Message: SERVER-24104 Fix broken Windows enterprise compile
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/c4f1ede5cf0d695260b25a36cc009e5cc30911ff

Comment by Githook User [ 17/May/16 ]

Author:

{u'username': u'andy10gen', u'name': u'Andy Schwerin', u'email': u'schwerin@mongodb.com'}

Message: SERVER-24104 Fix OSX include-what-you-use induced build failure.
Branch: master
https://github.com/mongodb/mongo/commit/1523e0feaf6cbfaa82b503f2d3df0cb19c1d1c5f

Comment by Githook User [ 17/May/16 ]

Author:

{u'username': u'andy10gen', u'name': u'Andy Schwerin', u'email': u'schwerin@mongodb.com'}

Message: SERVER-24104 Replace stdx::duration with mongo::Duration.

The mongo::Duration type does overflow checking on casts and arithmetic.

This patch also moves DESTRUCTOR_GUARD out of assert_util.h into
destructor_guard.h in order to break an include cycle with duration.h.
Branch: master
https://github.com/mongodb/mongo/commit/76de5323b88080f852ca4c2f42593502d26c5620

Comment by Githook User [ 17/May/16 ]

Author:

{u'username': u'andy10gen', u'name': u'Andy Schwerin', u'email': u'schwerin@mongodb.com'}

Message: SERVER-24104 Replace direct uses of stdx::chrono::durations with MongoDB duration using decls.

This is a preliminary step for switching from stdx::chrono::duration to mongo::Duration.
Branch: master
https://github.com/mongodb/mongo/commit/73a042328a539b51b3bf35efc16ec3245381dc40

Comment by Andy Schwerin [ 17/May/16 ]

http://github.com/mongodb/mongo/commit/11e82fe19c81bd1a5d350a219c3a000e959b6dd6

Accidentally left the ticket number off the commit message.

Comment by Githook User [ 16/May/16 ]

Author:

{u'username': u'andy10gen', u'name': u'Andy Schwerin', u'email': u'schwerin@mongodb.com'}

Message: SERVER-24104 Fix some include-what-you-use errors.

These errors were exposed by removing some unnecessary includes from
assert_util.h.
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/a73de5819cf54592aa78328ea26aae7fc4beae23

Comment by Githook User [ 10/May/16 ]

Author:

{u'username': u'andy10gen', u'name': u'Andy Schwerin', u'email': u'schwerin@mongodb.com'}

Message: SERVER-24104 Cosmetic changes to support switching from stdx::chrono::duration to mongo::Duration.
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/1360eb146be18bf68797643bcab3544650d5207b

Generated at Thu Feb 08 04:05:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.