[SERVER-68967] Convert BSONType into an enum class rather than a raw enum Created: 18/Aug/22  Updated: 14/Aug/23

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

Type: Improvement Priority: Major - P3
Reporter: Charlie Swanson Assignee: Backlog - Storage Execution Team
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Storage Execution
Participants:

 Description   

This would have major fallout across the codebase, but I think would improve things. I was just recently authoring a patch and ran across the following strange behavior.

The correct way to build a BSON object with MinKey and MaxKey for testing is like so:

BSON("" << MINKEY << "" << MAXKEY)

But this code actually compiles also:

BSON("" << MinKey << "" << MaxKey)

After several minutes or maybe an hour of insanity, I realized that when I typed the second one I had actually constructed this object:

{"": -1, "": 127}

because it was reading from the BSONType enum and converting to an integer...

I do not think I will be the last person to make this mistake in a test.



 Comments   
Comment by Yujin Kang Park [ 07/Jul/23 ]

Sending back to backlog. The change is more involved than initially thought, and we are unsure if it really is desired. IIRC, geert.bosch@mongodb.com had some concerns about potentially making the code more convoluted, and the change potentially being unsafe.

Note that this change would also require updating the IDL parser to generate code using the scoped enums. 
https://github.com/10gen/mongo/blob/2c5a74dfd5cfac8e264d9dd24a6761ea4b55f1dc/buildscripts/idl/idl/bson.py#L40

Comment by Blake Oler [ 22/Aug/22 ]

Passing this along to Storage Execution, who owns the BSON library. (Confirmed by pavithra.vetriselvan@mongodb.com)

Comment by Alex Neben [ 22/Aug/22 ]

I strongly agree with this change request however, I believe this is a service-arch ticket.

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