[SERVER-59512] Introduce new find API to DBClientBase which uses IDL-generated FindCommandRequest Created: 23/Aug/21  Updated: 29/Oct/23  Resolved: 10/Nov/21

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

Type: Task Priority: Major - P3
Reporter: Irina Yatsenko (Inactive) Assignee: David Storch
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-61385 Migrate most callers of legacy 'DBCli... Closed
related to SERVER-62206 Remove DBClientBase::query_DEPRECATED... Closed
is related to SERVER-58670 Modernize DBClientBase query interfac... Closed
Backwards Compatibility: Fully Compatible
Sprint: QE 2021-11-01, QE 2021-11-15
Participants:

 Description   

We will add new methods to DBClientBase called find() and findOne(). These perform the same role as the pre-existing DBClientBase::query() methods, but the caller specifies the find operation that they want to perform using the IDL-generated FindCommandRequest. This will make the internal client code easier to maintain, since whenever the find command IDL specification is modified, the client code will immediately benefit without any explicit changes necessary.

Under the hood, the DBClientBase::find() methods will have slightly different logic for constructing the initial OP_MSG find request to send across the wire. In particular, DBClientBase::query() needs to upconvert the request as specified by the caller to a FindCommandRequest so that the find request can in turn be converted to an OP_MSG. This upconversion step is not necessary for the new find() API.

This ticket will not complete the work to migrate all the callers off query() and onto find(). That will be achieved as followup work. Once that migration is complete, the query() API and its supporting code can be deleted. In particular the upconversion code mentioned above can be removed!

Originally we had a slightly different plan in mind for achieving the same goal. The details of the old plan are outlined below for posterity.

Original implementation plan

Implement steps ##5-8, outlined in the description of SERVER-58670.

5. Investigate and remove/replace the remaining four callers of fromBSONDeprecated():

  • (src/mongo/client/dbclient_rs.cpp) in DBClientReplicaSet::say under if (lastOp == dbQuery) check – is this code still reachable?
  • (src/mongo/client/dbclient_rs.cpp) in DBClientReplicaSet::call under if (toSend.operation() == dbQuery) check – is this code still reachable?
  • (src/mongo/db/repl/apply_ops.cpp) in _checkPrecondition – should/could preconditions use different format?
  • (src/mongo/scripting/mozjs/mongo.cpp) in MongoBase::Functions::find::call – should we still be supporting 'query/$query' here?

6. When all Query construction from raw BSON is gone, the type will only handle a known fixed set of query properties, so it will become possible to replace the internal BSON field 'obj' with statically typed fields, and callers that inspect 'obj' will be able to switch to using specific statically typed accessors instead. There are currently 7 callers like this (search for getFullSettingsDeprecated()).
7. Rename the Query type into QueryOptions (or FindOptions) and incorporate into it the other options that are currently passed to the query() APIs as separate arguments.
8. Review and cleanup src/mongo/db/query/query_request_helper.cpp. There should be no vestiges of OP_QUERY left at this point.



 Comments   
Comment by David Storch [ 10/Nov/21 ]

I filed SERVER-61385 to track the follow-up work. In this ticket, we will port callers over from DBClientBase::query() to DBClientBase::find() and attempt to remove any code associated with DBClientBase::query().

Comment by Githook User [ 10/Nov/21 ]

Author:

{'name': 'David Storch', 'email': 'david.storch@mongodb.com', 'username': 'dstorch'}

Message: SERVER-59512 add new, cleaner query interface to DBClientBase

The new interface uses FindCommandRequest, and avoids any
characteristics that relate specifically to the
no-longer-supported OP_QUERY wire protocol message. This
patch moves all callers of 'findOne()' onto the new API, but
more work is required to fully eliminate the old 'query()' API
from DBClientBase.
Branch: master
https://github.com/mongodb/mongo/commit/1b51a502f9201aacf760ba37b02888bbbff831da

Comment by Githook User [ 10/Nov/21 ]

Author:

{'name': 'David Storch', 'email': 'david.storch@mongodb.com', 'username': 'dstorch'}

Message: SERVER-59512 Accommodate DBClientBase::findOne() API change
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/deb67757a28ed4bbb0d78f0af1da4eae9dfcbed5

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