[SERVER-38623] Make safeNumberLongForHash consistent between PPC and other architectures Created: 13/Dec/18  Updated: 29/Oct/23  Resolved: 03/Apr/19

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 4.1.10

Type: Bug Priority: Major - P3
Reporter: Justin Seyster Assignee: Justin Seyster
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
is documented by DOCS-12610 Docs for SERVER-38623: Make safeNumbe... Closed
Related
related to SERVER-37183 BSONElement::safeNumberLong is not safe Closed
Backwards Compatibility: Minor Change
Operating System: ALL
Sprint: Query 2019-04-08
Participants:

 Description   

As noted in SERVER-37183, the hash function used for double values performs an undefined cast when hashing the value 2^63, and the resulting value is different on PPC than on other supported platforms. We should make this hash value consistent across architectures, but before we do that, we need a path for existing PPC installations to rehash any documents with a hashed index key that includes a 2^63 double value.



 Comments   
Comment by Githook User [ 03/Apr/19 ]

Author:

{'email': 'justin.seyster@mongodb.com', 'name': 'Justin Seyster', 'username': 'jseyster'}

Message: SERVER-38623 Make safeNumberLongForHash consistent on all platforms

Previously, the hash function for double values relied on undefined
behavior when computing the hash for 2^63, meaning that it could give
different results on different platforms. Almost all platforms we
support returned -2^63 as the result of safeNumberLongForHash when the
input was 2^63, so this patch makes that the official result. Now,
safeNumberLongForHash will explicitly convert 2^63 to -2^63 on all
platforms without invoking any undefined behavior.

Note that this does not change our guidance that using a hashed index
for a field containing a floating point value greater than 2^53 is
unsupported:
https://docs.mongodb.com/manual/core/index-hashed/#considerations
Branch: master
https://github.com/mongodb/mongo/commit/f2ab9fa71aabf110b67c28131241de6a27a3f09e

Comment by Justin Seyster [ 11/Jan/19 ]

This is no longer just a PPC issue: I observed that gcc 8.2 on x86-64 Linux also has different behavior for this cast than other compilers.

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