Guidelines for AI coding agents working with generated source code. Important: Do NOT manually edit generated files.
This directory contains generated source code from Thrift and Protobuf definitions. These files are auto-generated during the build process.
Read handbook/index.md first and use handbook/domains/generated-and-extensions.md for the generated-code and Java-extension workflow map.
gensrc/
├── thrift/ # Thrift definition files (.thrift)
├── proto/ # Protobuf definition files (.proto)
└── build/ # Generated output (created during build)
├── gen-cpp/ # Generated C++ code
└── gen-java/ # Generated Java code
NEVER manually edit files in gensrc/build/
These files are regenerated on every build. Any manual changes will be lost.
The BE CMake build also generates thrift/protobuf C++ files under the active build directory
(for example be/build_Release/gensrc/gen_cpp), and those generated files must not be edited either.
Modify the source definition files, not the generated output:
| To change... | Edit this file | Not this |
|---|---|---|
| FE-BE RPC interface | gensrc/thrift/*.thrift |
build/gen-*/ |
| Storage format | gensrc/proto/*.proto |
build/gen-*/ |
Code is regenerated automatically during build:
# BE build regenerates C++ thrift/proto during CMake configure/build
./build.sh --be --clean
# Regenerate script-based shared outputs
cd gensrc && make script
# Manual fallback for C++ protobuf generation into gensrc/build
cd gensrc && make proto
# Manual fallback for C++ thrift generation into gensrc/build
cd gensrc && make thrift- Lowercase with underscores:
my_service.thrift
- Prefix with
T:TMyStruct
struct TTabletInfo {
1: optional i64 tablet_id;
2: optional i64 schema_hash;
}- NEVER use
required(breaks forward/backward compatibility) - NEVER change field ordinals (numbers)
- Always use
optional
// Good
struct TMyStruct {
1: optional i64 field_one;
2: optional string field_two;
// Adding new field - use next available number
3: optional bool field_three;
}
// BAD - Don't do this
struct TMyStruct {
1: required i64 field_one; // Never use required!
3: optional string field_two; // Changed from 2 to 3 - breaks compatibility!
}service BackendService {
TStatus submit_task(1: TTaskRequest request);
}- Lowercase with underscores:
my_message.proto
- PascalCase with
PBsuffix:MyMessagePB
message TabletInfoPB {
optional int64 tablet_id = 1;
optional int64 schema_hash = 2;
}- NEVER use
required(deprecated in proto3) - NEVER change field numbers
- Use
optional(proto2) or implicit optional (proto3)
// Good
message MyMessagePB {
optional int64 field_one = 1;
optional string field_two = 2;
// Adding new field
optional bool field_three = 3;
}
// BAD
message MyMessagePB {
required int64 field_one = 1; // Never use required!
optional string field_two = 3; // Changed from 2 to 3 - breaks!
}Don't remove fields, mark as deprecated:
message MyMessagePB {
optional int64 field_one = 1;
optional string field_two = 2 [deprecated = true];
optional string field_two_v2 = 3; // New replacement
}- Edit the
.thriftfile ingensrc/thrift/ - Run
./build.sh --be(or reconfigure the BE CMake build) to regenerate the C++ outputs - Implement the handler in BE (
be/src/service/) - Implement the caller in FE (
fe/fe-core/.../rpc/)
- Edit the
.protofile ingensrc/proto/ - Run
./build.sh --be(or reconfigure the BE CMake build) to regenerate the C++ outputs - Update reading/writing code in storage layer
After regenerating, verify:
# Check schema compatibility against your branch base
python3 build-support/check_gensrc_schema_compatibility.py --mode changed --base origin/main
# Check generated C++ compiles
./build.sh --be
# Check generated Java compiles
./build.sh --feThrift/Protobuf changes affect upgrade/downgrade compatibility:
| Change Type | Safe? | Notes |
|---|---|---|
| Add optional field | Yes | Use next available number |
| Remove field | No | Mark deprecated instead |
| Change field number | No | Breaks all existing data |
| Change field type | No | Breaks compatibility |
| Rename field | Careful | Number must stay same |
If you see serialization errors:
- Check field numbers match between versions
- Verify no required fields were added
- Check for type mismatches
- Thrift guide:
docs/en/developers/code-style-guides/thrift-guides.md - Protobuf guide:
docs/en/developers/code-style-guides/protobuf-guides.md