[SERVER-53231] Generate V1 commands' base classes in separate .h/.cpp files Created: 04/Dec/20  Updated: 27/Oct/23  Resolved: 22/Dec/20

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

Type: Task Priority: Major - P3
Reporter: A. Jesse Jiryu Davis Assignee: Backlog - Replication Team
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Replication
Participants:

 Description   

Today we generate C++ base classes from IDL for all API Version 1 commands (SERVER-51862). The generated files required the TypedCommand definition so they include commands.h. This tends to produce include-cycles as we convert more V1 commands to IDL: commands.h includes many headers, if one of those headers includes an IDL-generated file that defines a V1 command, a cycle forms.

Let's give ourselves some flexibility in how we choose to break include-cycles, by generating V1 commands into separate files.



 Comments   
Comment by A. Jesse Jiryu Davis [ 22/Dec/20 ]

So far, our alternative approach has worked well, I don't think we need to do this ticket.

Comment by A. Jesse Jiryu Davis [ 04/Dec/20 ]

For example, say we generate a C++ base class for the "create" command, which is defined in create.idl and generated in create_gen.h.

collection_options.h includes create_gen.h because it needs a few other types defined in create.idl. This leads to an include cycle:

src/mongo/db/commands.h includes
src/mongo/db/query/explain.h includes
src/mongo/db/query/plan_cache.h includes
src/mongo/db/query/canonical_query.h includes
src/mongo/db/matcher/extensions_callback_noop.h includes
src/mongo/db/matcher/extensions_callback.h includes
src/mongo/db/pipeline/expression_context.h includes
src/mongo/db/pipeline/process_interface/mongo_process_interface.h includes
src/mongo/db/repl/oplog_entry.h includes
src/mongo/db/catalog/collection_options.h includes
build/ninja/mongo/db/commands/create_gen.h includes
src/mongo/db/commands.h

If we generate separate files just for the base class, say "create_bases_gen.h" and "create_bases_gen.cpp", then only those files would need to include commands.h, and the existing create_gen.h would not include commands.h. (Update idlc_emitter() in idl_tool.py to emit the additional .h/.cpp files, and generate.py to generate them.)

Alternatively, each time we add apiVersion: "1" to a command's IDL definition, if its IDL file includes additional types that are used in other header files, then we may need to split the IDL file into two: one for the command, one for the additional types. This could require delicate surgery, but would avoid the change to the code generator.

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