mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-09-05 21:18:57 +00:00
* feat(mito2): add SST range index writer Signed-off-by: evenyag <realevenyag@gmail.com> * refactor(mito2): share parquet index writer Signed-off-by: evenyag <realevenyag@gmail.com> * fix(mito2): lazily construct index writer context Signed-off-by: evenyag <realevenyag@gmail.com> --------- Signed-off-by: evenyag <realevenyag@gmail.com>
1.7 KiB
1.7 KiB
GreptimeDB Style Guide
This style guide is intended to help contributors to GreptimeDB write code that is consistent with the rest of the codebase. It is a living document and will be updated as the codebase evolves.
It's mainly an complement to the Rust Style Guide.
Table of Contents
- Formatting
- Modules
- Comments
Formatting
- Place all
moddeclaration before anyuse. - Use
unimplemented!()instead oftodo!()for things that aren't likely to be implemented. - Add an empty line before and after declaration blocks.
- Place comment before attributes (
#[]) and derive (#[derive]).
Modules
- Use the file with same name instead of
mod.rsto define a module. E.g.:
.
├── cache
│ ├── cache_size.rs
│ └── write_cache.rs
└── cache.rs
Comments
- Add comments for public functions and structs.
- Prefer document comment (
///) over normal comment (//) for structs, fields, functions etc. - Add link (
[]) to struct, method, or any other reference. And make sure that link works.
Error handling
- Define a custom error type for the module if needed.
- Use
context()for cheap context selectors. Its argument is evaluated even when the operation succeeds. - Use
with_context()when constructing the context requires work such asformat!, allocation, or cloning, so that work only happens on the error path. For example:
value.with_context(|| InvalidValueSnafu {
reason: format!("invalid value: {value}"),
})?;
- Use
error!()orwarn!()macros in thecommon_telemetrycrate to log errors. E.g.:
error!(e; "Failed to do something");