Repository navigation
[Nexthop][fboss2-dev] Move explicit template instantiations to individual files - #931
benoit-nexthop wants to merge 1 commit into
Conversation
…p class (#919) Summary: **Pre-submission checklist** - [x] I've ran the linters locally and fixed lint errors related to the files I modified in this PR. You can install the linters by running `pip install -r requirements-dev.txt && pre-commit install` - [x] `pre-commit run` This PR consolidates the separate `CmdConfigInterfaceDescription` and `CmdConfigInterfaceMtu` commands into a unified `CmdConfigInterface` command that can set multiple interface attributes in a single invocation. ``` # Set description config interface eth1/1/1 description "My port description" # Set MTU config interface eth1/1/1 mtu 9000 # Set both in one command config interface eth1/1/1 description "My port" mtu 9000 # Apply to multiple interfaces config interface eth1/1/1,eth1/2/1 description "Uplink" mtu 1500 ``` Original change by hillol-nexthop Note: this change is part of a series, the previous one is #900, the next one is #931. ## Implementation Details 1. **New `InterfaceConfig` class** - Parses CLI tokens to separate port names from attribute key-value pairs - Supports description and mtu attributes (case-insensitive) - Validates attribute names and detects missing values - Wraps `InterfaceList` for port/interface resolution 2. **Updated CmdConfigInterface** - Changed from pass-through command to functional command - Implements `queryClient` to process description and mtu attributes - Sets `port->description()` for description attribute - Sets `interface->mtu()` for mtu attribute with validation 3. **Updated subcommands to use `InterfaceConfig` instead of `InterfaceList`** 4. **Deleted obsolete pairs of `.cpp` / `.h`** 5. **New comprehensive test suite** - 23 tests covering `InterfaceConfig` validation and `CmdConfigInterface::queryClient` functionality - Backward Compatibility - Subcommands like switchport, pfc-config, and queuing-policy continue to work as before Pull Request resolved: #919 Test Plan: **Note:** The e2e test is already implemented in #893 Above mentioned list of new test file, deleted and updated test files. Existing unit and end to end tests pass. Reviewed By: KevinYakar Differential Revision: D98340162 Pulled By: joseph5wu fbshipit-source-id: 82d10267ae00fb6e81710f61781f0746d591f836
|
There's some concern about affect compiling time with such change. The Core Problem: #include "CmdHandler.cpp" Notice line 11 of both CmdHandlerImpl.cpp and CmdHandlerImplConfig.cpp: #include "fboss/cli/fboss2/CmdHandler.cpp" This is not a typo — it's including a .cpp file. The template method definitions (run(), runHelper(), getValidFilters(), getValidAggs(), etc.) in CmdHandler.cpp are ~620 lines of heavy template code. They must be visible at the point of explicit instantiation. If you moved each instantiation to its respective CmdShowAcl.cpp, every one of those files would need #include "CmdHandler.cpp" too. That means: ┌───────────────────────┬───────────────────────────────────────────────────┐ That's a massive build time regression — each TU would independently compile all the template machinery (thrift reflection, filter/aggregate logic, thread pool executor, etc.). Other Tradeoffs Incremental builds: The current pattern means changing CmdHandler.cpp recompiles 2 large files. The per-command approach would recompile ~130 files, but each is smaller. In practice, changes to CmdHandler.cpp are rare — it's stable infrastructure code. Changes to individual commands (which are frequent) already only recompile that command's own .cpp. Modularity: Yes, adding a new command requires touching CmdHandlerImpl.cpp. But it's just 1-2 lines (include + instantiation), which is a trivial cost compared to the build time tradeoff. |
1b76179 to
1286def
Compare
1286def to
62cdffd
Compare
# Summary Move explicit template instantiations from the monolithic CmdHandlerImplConfig.cpp file to individual command .cpp files. This is the first step in refactoring the CLI command registration system to avoid creating a monolithic include file. Changes: - Created 11 new .cpp files for stub commands that were missing them - Added template instantiations to 20 existing command .cpp files - Updated cmake/CliFboss2.cmake and fboss/cli/fboss2/BUCK build files - Deleted fboss/cli/fboss2/CmdHandlerImplConfig.cpp Each command .cpp file now includes CmdHandler.cpp and has its own explicit template instantiation, following the pattern: #include "fboss/cli/fboss2/CmdHandler.cpp" template void CmdHandler<CmdClass, CmdClassTraits>::run(); # Test Plan Ran all the unit tests.
62cdffd to
d18515c
Compare
Claude is wrong 😅
Yes it looks weird but it's because normally the
Claude is mistaken: this decouples the build of all the commands, so they can all be built in parallel. In practice in a heavily parallel build like what we get with BUCK / cmake, the main factors driving build time are how much can you build in parallel and what's the slowest build units. This massive
Wrong, in practice what happens is that when someone works on a CLI command, if they change the header file of any of the CLI command, they trigger the recompilation of this massive
Wrong, in practice what happens is that this file is a source of conflicts, and the human time wasted solving those conflicts, no matter how trivial, is costing way more than the compilation time, but even on the compilation the argument was wrong anyway. |
|
@joseph5wu has imported this pull request. If you are a Meta employee, you can view this in D98510944. |
|
@joseph5wu merged this pull request in 675e814. |
Summary: **Pre-submission checklist** - [x] I've ran the linters locally and fixed lint errors related to the files I modified in this PR. You can install the linters by running `pip install -r requirements-dev.txt && pre-commit install` - [x] `pre-commit run` Implements a new CLI command `fboss2-dev config session clear` that removes the current config session files (`~/.fboss2/agent.conf` and `~/.fboss2/cli_metadata.json`). This command allows users to discard any pending config session changes without committing them, providing a clean way to abandon a session and start fresh. Original change by hillol-nexthop Note: this change is part of a series, the previous one is #931. ## Changes - Added `CmdConfigSessionClear.h` and `CmdConfigSessionClear.cpp` implementing the clear command - Registered the command in `CmdListConfig.cpp` under config session subcommands - Added unit tests in `CmdConfigSessionTest.cpp` covering: - Clearing an existing session removes both files - Clearing when no session exists (no-op) - Clearing with partial session state (only config file exists) - Added e2e test in `ConfigSessionClearTest.cpp` that creates a session and clears it - Added unit test in `CmdConfigSessionClearTest.cpp` Pull Request resolved: #935 Test Plan: New E2E and unit tests. ## Sample usage ``` [admin@fboss101 .fboss2]$ fboss2-dev config session clear Config session cleared successfully. [admin@fboss101 .fboss2]$ fboss2-dev config session clear No config session exists. Nothing to clear. ``` Reviewed By: AarjunC Differential Revision: D98555036 Pulled By: joseph5wu fbshipit-source-id: 6229f59a3d49479469fa0e6ebe5794ac988f5d82
Pre-submission checklist
pip install -r requirements-dev.txt && pre-commit installpre-commit runSummary
Move explicit template instantiations from the monolithic
CmdHandlerImplConfig.cppfile to individual command.cppfiles. This is the first step in refactoring the CLI command registration system to avoid creating a monolithic include file.The non-config commands will be done in a separate PR.
Changes:
.cppfiles for stub commands that were missing them.cppfilescmake/CliFboss2.cmakeandfboss/cli/fboss2/BUCKbuild filesfboss/cli/fboss2/CmdHandlerImplConfig.cppEach command
.cppfile now includesCmdHandler.cppand has its own explicit template instantiation, following the pattern:Original change by @manoharan-nexthop
Note: this change is part of a series, the previous one is #919, the next one is #935.
Test Plan
Ran all the unit tests.