mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-12-05 08:50:58 +00:00
fix: drop protobuf 2.x from the dependency graph (RUSTSEC-2024-0437) (#10821)
* fix: drop protobuf 2.x from the dependency graph (RUSTSEC-2024-0437) Every 2.x release of the `protobuf` crate is affected by RUSTSEC-2024-0437 (uncontrolled recursion when parsing unknown fields), patched only in >= 3.7.2. Three independent paths kept protobuf 2.28.0 in Cargo.lock: - `raft-engine 0.4.2` hard-depends on `protobuf = "2"`: its entry type (`MessageExt::Entry`), `put_message`, `get_message` and `scan_messages` are bounded on `protobuf::Message` and decode with `parse_from_bytes`. It also pins `prometheus 0.13`, which pulls protobuf 2 through its default `protobuf` feature. Patch it with the GreptimeTeam fork (GreptimeTeam/raft-engine, branch v0.4.2-prost-0.14: tag 0.4.2 plus one commit) that switches the bound to `prost::Message` and bumps prometheus to 0.14. The library change is ~20 lines; the rest of the fork diff replaces the protobuf-2 based `raft`/`kvproto` test types. - `log-store` generated `logstore.proto` with `protoc-rust 2.28` and linked `protobuf = "2"` for that code. Generate the bindings with `prost-build` instead (same PROTOC/PATH/vendored protoc selection) and drop the runtime dependency. The wire format is unchanged: prost emits byte-identical proto3 for these messages, pinned by `wire_compat_tests` against bytes captured from the rust-protobuf 2.28 encoder, so raft logs and namespace records written by older binaries stay readable and a rollback keeps working. - `common-runtime` pulled `tokio-metrics-collector 0.2.3` (prometheus 0.13.4) under `cfg(tokio_unstable)`; bump it to 0.3 (prometheus 0.14, tokio-metrics 0.4). Cargo.lock now carries a single `protobuf` (3.7.2, via pprof and prometheus 0.14) and a single `prometheus` (0.14.0); `protoc-rust`, `protobuf-codegen`, `protoc` and `prometheus 0.13.4` are gone. Validation: raft-engine fork 107 unit tests; `cargo nextest run -p log-store` 310 passed; compatibility suite in both directions (`basic_table` v1.3.2 -> current and `downgrade_compatibility` current -> v1.2.1, distributed topology); `cargo build --workspace`; clippy on the touched crates; `common-runtime` with `--cfg tokio_unstable`. Signed-off-by: Ning Sun <sunning@greptime.com> * fix(log-store): drop the redundant cargo-shear ignore for prost cargo-shear now detects the dependency through the wire-compat tests, so the `[package.metadata.cargo-shear]` ignored entry became redundant (shear/redundant_ignore). Signed-off-by: Ning Sun <sunning@greptime.com> * test(log-store): pin the WAL entry decoder's tolerance to non-canonical input Fields in any order, explicit proto3 defaults and unknown fields decode, so raft log entries written by a different conforming encoder stay readable. Signed-off-by: Ning Sun <sunning@greptime.com> * style(log-store): drop the trailing blank line in Cargo.toml Signed-off-by: Ning Sun <sunning@greptime.com> --------- Signed-off-by: Ning Sun <sunning@greptime.com>
This commit is contained in:
1 parent
63b6823da6
commit
ecabaf2760
7 files changed
+179
-140
No files matched your search
Generated
+37
-105
@@ -1729,7 +1729,7 @@ dependencies = [
|
||||
"moka",
|
||||
"partition",
|
||||
"paste",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"promql-parser",
|
||||
"rand 0.9.4",
|
||||
"serde",
|
||||
@@ -2109,7 +2109,7 @@ dependencies = [
|
||||
"lazy_static",
|
||||
"moka",
|
||||
"parking_lot 0.12.4",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"prost 0.14.1",
|
||||
"query",
|
||||
"rand 0.9.4",
|
||||
@@ -2221,7 +2221,7 @@ dependencies = [
|
||||
"parquet",
|
||||
"plugins",
|
||||
"pprof",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"prost 0.14.1",
|
||||
"query",
|
||||
"rand 0.9.4",
|
||||
@@ -2348,7 +2348,7 @@ dependencies = [
|
||||
"common-base",
|
||||
"futures",
|
||||
"moka",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
@@ -2485,7 +2485,7 @@ dependencies = [
|
||||
"greptime-proto",
|
||||
"lazy_static",
|
||||
"meta-client",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"snafu 0.8.6",
|
||||
@@ -2711,7 +2711,7 @@ dependencies = [
|
||||
"lazy_static",
|
||||
"moka",
|
||||
"object-store",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"prost 0.14.1",
|
||||
"prost-types 0.14.1",
|
||||
"rand 0.9.4",
|
||||
@@ -2875,7 +2875,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"paste",
|
||||
"pin-project",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"ratelimit",
|
||||
"serde",
|
||||
"snafu 0.8.6",
|
||||
@@ -2937,7 +2937,7 @@ dependencies = [
|
||||
"common-telemetry",
|
||||
"nix 0.30.1",
|
||||
"num_cpus",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"sysinfo",
|
||||
"tokio",
|
||||
]
|
||||
@@ -2962,7 +2962,7 @@ dependencies = [
|
||||
"opentelemetry-semantic-conventions 0.30.0",
|
||||
"opentelemetry_sdk",
|
||||
"parking_lot 0.12.4",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"snafu 0.8.6",
|
||||
@@ -4587,7 +4587,7 @@ dependencies = [
|
||||
"num_cpus",
|
||||
"object-store",
|
||||
"partition",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"prost 0.14.1",
|
||||
"query",
|
||||
"rand 0.9.4",
|
||||
@@ -5557,7 +5557,7 @@ dependencies = [
|
||||
"meta-client",
|
||||
"operator",
|
||||
"pretty_assertions",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"prost 0.14.1",
|
||||
"query",
|
||||
"rand 0.9.4",
|
||||
@@ -5727,7 +5727,7 @@ dependencies = [
|
||||
"otel-arrow-rust",
|
||||
"partition",
|
||||
"pipeline",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"promql",
|
||||
"promql-parser",
|
||||
"prost 0.14.1",
|
||||
@@ -8264,10 +8264,10 @@ dependencies = [
|
||||
"lazy_static",
|
||||
"object-store",
|
||||
"pin-project",
|
||||
"prometheus 0.14.0",
|
||||
"protobuf 2.28.0",
|
||||
"prometheus",
|
||||
"prost 0.14.1",
|
||||
"prost-build 0.14.1",
|
||||
"protoc-bin-vendored",
|
||||
"protoc-rust",
|
||||
"raft-engine",
|
||||
"rand 0.9.4",
|
||||
"rskafka",
|
||||
@@ -8666,7 +8666,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"ordered-float 4.6.0",
|
||||
"partition",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"rand 0.9.4",
|
||||
"regex",
|
||||
"rskafka",
|
||||
@@ -8749,7 +8749,7 @@ dependencies = [
|
||||
"mur3",
|
||||
"object-store",
|
||||
"partition",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"rstest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -8897,7 +8897,7 @@ dependencies = [
|
||||
"parquet",
|
||||
"partition",
|
||||
"pin-project",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"prost 0.14.1",
|
||||
"puffin",
|
||||
"rand 0.9.4",
|
||||
@@ -9709,7 +9709,7 @@ dependencies = [
|
||||
"object_store_opendal",
|
||||
"opendal",
|
||||
"opendal-http-transport-reqwest",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"reqwest 0.13.4",
|
||||
"serde",
|
||||
"snafu 0.8.6",
|
||||
@@ -9943,7 +9943,7 @@ checksum = "404e766cc2e4e4c9225ce08605ae151f768a05a41a448a235e016b1aea9ff98f"
|
||||
dependencies = [
|
||||
"opendal-core",
|
||||
"opendal-layer-observe-metrics-common",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -10294,7 +10294,7 @@ dependencies = [
|
||||
"partition",
|
||||
"path-slash",
|
||||
"percent-encoding",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"prost-types 0.14.1",
|
||||
"query",
|
||||
"regex",
|
||||
@@ -11063,7 +11063,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"operator",
|
||||
"ordered-float 4.6.0",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"query",
|
||||
"regex",
|
||||
"serde",
|
||||
@@ -11333,7 +11333,7 @@ dependencies = [
|
||||
"prost 0.12.6",
|
||||
"prost-build 0.12.6",
|
||||
"prost-derive 0.12.6",
|
||||
"protobuf 3.7.2",
|
||||
"protobuf",
|
||||
"sha2 0.10.9",
|
||||
"smallvec",
|
||||
"spin 0.10.1",
|
||||
@@ -11513,21 +11513,6 @@ dependencies = [
|
||||
"hex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prometheus"
|
||||
version = "0.13.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d33c28a30771f7f96db69893f78b857f7450d7e0237e9c8fc6427a81bae7ed1"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"fnv",
|
||||
"lazy_static",
|
||||
"memchr",
|
||||
"parking_lot 0.12.4",
|
||||
"protobuf 2.28.0",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prometheus"
|
||||
version = "0.14.0"
|
||||
@@ -11541,7 +11526,7 @@ dependencies = [
|
||||
"memchr",
|
||||
"parking_lot 0.12.4",
|
||||
"procfs",
|
||||
"protobuf 3.7.2",
|
||||
"protobuf",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
@@ -11581,7 +11566,7 @@ dependencies = [
|
||||
"lazy_static",
|
||||
"mito-codec",
|
||||
"postcard",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"prost 0.14.1",
|
||||
"rand 0.9.4",
|
||||
"regex",
|
||||
@@ -11807,15 +11792,6 @@ dependencies = [
|
||||
"prost 0.14.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "protobuf"
|
||||
version = "2.28.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "protobuf"
|
||||
version = "3.7.2"
|
||||
@@ -11827,15 +11803,6 @@ dependencies = [
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "protobuf-codegen"
|
||||
version = "2.28.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "033460afb75cf755fcfc16dfaed20b86468082a2ea24e05ac35ab4a099a017d6"
|
||||
dependencies = [
|
||||
"protobuf 2.28.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "protobuf-support"
|
||||
version = "3.7.2"
|
||||
@@ -11845,16 +11812,6 @@ dependencies = [
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "protoc"
|
||||
version = "2.28.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a0218039c514f9e14a5060742ecd50427f8ac4f85a6dc58f2ddb806e318c55ee"
|
||||
dependencies = [
|
||||
"log",
|
||||
"which",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "protoc-bin-vendored"
|
||||
version = "3.2.0"
|
||||
@@ -11919,18 +11876,6 @@ version = "3.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95067976aca6421a523e491fce939a3e65249bac4b977adee0ee9771568e8aa3"
|
||||
|
||||
[[package]]
|
||||
name = "protoc-rust"
|
||||
version = "2.28.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22f8a182bb17c485f20bdc4274a8c39000a61024cfe461c799b50fec77267838"
|
||||
dependencies = [
|
||||
"protobuf 2.28.0",
|
||||
"protobuf-codegen",
|
||||
"protoc",
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "psl"
|
||||
version = "2.1.123"
|
||||
@@ -12008,7 +11953,7 @@ dependencies = [
|
||||
"lz4_flex 0.11.6",
|
||||
"moka",
|
||||
"pin-project",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2 0.10.9",
|
||||
@@ -12097,7 +12042,7 @@ dependencies = [
|
||||
"partition",
|
||||
"paste",
|
||||
"pretty_assertions",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"promql",
|
||||
"promql-parser",
|
||||
"prost 0.14.1",
|
||||
@@ -12240,8 +12185,7 @@ checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09"
|
||||
[[package]]
|
||||
name = "raft-engine"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1213c3a24e3fee8afcc74b2be08c4081adde96f092e0fc1c607abb3e16ae722e"
|
||||
source = "git+https://github.com/GreptimeTeam/raft-engine.git?rev=a049cf52bd6597417b60f4f6d9447e3f3839a5b7#a049cf52bd6597417b60f4f6d9447e3f3839a5b7"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"crc32fast",
|
||||
@@ -12259,9 +12203,9 @@ dependencies = [
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"parking_lot 0.12.4",
|
||||
"prometheus 0.13.4",
|
||||
"prometheus",
|
||||
"prometheus-static-metric",
|
||||
"protobuf 2.28.0",
|
||||
"prost 0.14.1",
|
||||
"rayon",
|
||||
"scopeguard",
|
||||
"serde",
|
||||
@@ -13869,7 +13813,7 @@ dependencies = [
|
||||
"pipeline",
|
||||
"postgres-types",
|
||||
"pprof",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"promql-parser",
|
||||
"prost 0.14.1",
|
||||
"query",
|
||||
@@ -14887,7 +14831,7 @@ dependencies = [
|
||||
"itertools 0.14.0",
|
||||
"lazy_static",
|
||||
"num_enum 0.7.4",
|
||||
"prometheus 0.14.0",
|
||||
"prometheus",
|
||||
"prost 0.14.1",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -15846,9 +15790,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tokio-metrics"
|
||||
version = "0.3.1"
|
||||
version = "0.4.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eace09241d62c98b7eeb1107d4c5c64ca3bd7da92e8c218c153ab3a78f9be112"
|
||||
checksum = "0e0410015c6db7b67b9c9ab2a3af4d74a942d637ff248d0d055073750deac6f9"
|
||||
dependencies = [
|
||||
"futures-util",
|
||||
"pin-project-lite",
|
||||
@@ -15858,13 +15802,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tokio-metrics-collector"
|
||||
version = "0.2.3"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8092b7a97ed5dac2f44892db190eca8f476ede0fa585bc87664de4151cd0b64"
|
||||
checksum = "f360c6fa7fd188e65904979ea07f1f44c57f0759ab18ecca88551c26acdf4cd6"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"parking_lot 0.12.4",
|
||||
"prometheus 0.13.4",
|
||||
"prometheus",
|
||||
"tokio",
|
||||
"tokio-metrics",
|
||||
]
|
||||
@@ -17134,18 +17078,6 @@ dependencies = [
|
||||
"rustls-pki-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "which"
|
||||
version = "4.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7"
|
||||
dependencies = [
|
||||
"either",
|
||||
"home",
|
||||
"once_cell",
|
||||
"rustix 0.38.44",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "whoami"
|
||||
version = "1.6.0"
|
||||
|
||||
+6
-1
@@ -233,9 +233,9 @@ pretty_assertions = "1.4.0"
|
||||
prometheus = { version = "0.14", features = ["process"] }
|
||||
promql-parser = { version = "0.10.0", features = ["ser"] }
|
||||
prost = { version = "0.14", features = ["no-recursion-limit"] }
|
||||
prost-build = "0.14"
|
||||
prost-types = "0.14"
|
||||
protoc-bin-vendored = "3.2"
|
||||
protoc-rust = "2.28"
|
||||
raft-engine = { version = "0.4.1", default-features = false }
|
||||
rand = "0.9"
|
||||
ratelimit = "0.10"
|
||||
@@ -389,6 +389,11 @@ git = "https://github.com/GreptimeTeam/greptime-meter.git"
|
||||
rev = "f743c3a5fe8c1f57363eac5866c356b7d91f9b39"
|
||||
|
||||
[patch.crates-io]
|
||||
# Temporary: raft-engine 0.4.2 hard-depends on protobuf 2 (RUSTSEC-2024-0437, no patched 2.x)
|
||||
# and pins prometheus 0.13. The GreptimeTeam fork (branch v0.4.2-prost-0.14, tag 0.4.2 plus one
|
||||
# commit) switches its entry/message bound to prost and bumps prometheus to 0.14. Remove once
|
||||
# tikv/raft-engine ships a release without protobuf 2.
|
||||
raft-engine = { git = "https://github.com/GreptimeTeam/raft-engine.git", rev = "a049cf52bd6597417b60f4f6d9447e3f3839a5b7" }
|
||||
substrait = { git = "https://github.com/GreptimeTeam/substrait-rs.git", rev = "91ec978b0649417ad3da8390e7a515baec723b1b" }
|
||||
datafusion = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "638a77fb504e86f85ef6053c552bbee1ed814fb9" }
|
||||
datafusion-common = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "638a77fb504e86f85ef6053c552bbee1ed814fb9" }
|
||||
|
||||
@@ -39,5 +39,5 @@ tokio-util.workspace = true
|
||||
tokio-test = "0.4"
|
||||
|
||||
[target.'cfg(tokio_unstable)'.dependencies]
|
||||
tokio-metrics = { version = "0.3" }
|
||||
tokio-metrics-collector = { version = "0.2" }
|
||||
tokio-metrics = { version = "0.4" }
|
||||
tokio-metrics-collector = { version = "0.3" }
|
||||
@@ -5,8 +5,8 @@ edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[build-dependencies]
|
||||
prost-build.workspace = true
|
||||
protoc-bin-vendored.workspace = true
|
||||
protoc-rust.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -38,7 +38,7 @@ lazy_static.workspace = true
|
||||
object-store.workspace = true
|
||||
pin-project.workspace = true
|
||||
prometheus.workspace = true
|
||||
protobuf = { version = "2", features = ["bytes"] }
|
||||
prost.workspace = true
|
||||
raft-engine.workspace = true
|
||||
rskafka.workspace = true
|
||||
serde.workspace = true
|
||||
@@ -56,9 +56,3 @@ common-wal = { workspace = true, features = ["testing"] }
|
||||
object-store = { workspace = true, features = ["testing"] }
|
||||
rand.workspace = true
|
||||
rskafka = { workspace = true, features = ["unstable-fuzzing"] }
|
||||
|
||||
[package.metadata.cargo-shear]
|
||||
# `protobuf` is required by the code generated by `build.rs`: the generated
|
||||
# protobuf bindings (included via `include!`) reference `::protobuf` paths,
|
||||
# but no source file does.
|
||||
ignored = ["protobuf"]
|
||||
+8
-13
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Generates Rust protobuf bindings for `proto/logstore.proto`.
|
||||
//! Generates prost bindings for `proto/logstore.proto`.
|
||||
//!
|
||||
//! The protoc compiler is selected in the following order:
|
||||
//!
|
||||
@@ -33,7 +33,7 @@ use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
use protoc_rust::{Codegen, Customize};
|
||||
use prost_build::Config;
|
||||
|
||||
/// Returns whether `protoc` runs and meets GreptimeDB's minimum supported version.
|
||||
fn usable_protoc(protoc: &Path) -> bool {
|
||||
@@ -91,15 +91,10 @@ fn main() {
|
||||
println!("cargo:rerun-if-changed={}", proto.display());
|
||||
std::fs::create_dir_all(&out_dir).expect("failed to create protobuf output directory");
|
||||
|
||||
Codegen::new()
|
||||
.protoc_path(protoc_path())
|
||||
.out_dir(out_dir)
|
||||
.input(proto)
|
||||
.include(proto_dir)
|
||||
.customize(Customize {
|
||||
gen_mod_rs: Some(true),
|
||||
..Default::default()
|
||||
})
|
||||
.run()
|
||||
.expect("failed to generate log-store protobuf bindings")
|
||||
// Writes `<out_dir>/logstore.rs`, included by `src/raft_engine.rs`.
|
||||
Config::new()
|
||||
.protoc_executable(protoc_path())
|
||||
.out_dir(&out_dir)
|
||||
.compile_protos(&[proto], &[proto_dir])
|
||||
.expect("failed to generate log-store prost bindings")
|
||||
}
|
||||
@@ -26,11 +26,11 @@ use store_api::logstore::provider::Provider;
|
||||
use store_api::storage::RegionId;
|
||||
|
||||
use crate::error::{JoinSnafu, Result};
|
||||
use crate::raft_engine::protos::logstore::EntryImpl;
|
||||
use crate::raft_engine::protos::EntryImpl;
|
||||
|
||||
#[allow(renamed_and_removed_lints, mismatched_lifetime_syntaxes, unused_parens)]
|
||||
/// prost-generated bindings for `proto/logstore.proto` (see `build.rs`).
|
||||
pub mod protos {
|
||||
include!(concat!(env!("OUT_DIR"), concat!("/", "protos/", "mod.rs")));
|
||||
include!(concat!(env!("OUT_DIR"), "/protos/logstore.rs"));
|
||||
}
|
||||
|
||||
/// Drops `engine` on a blocking thread, as that blocks: dropping the last reference joins the
|
||||
@@ -50,7 +50,6 @@ impl EntryImpl {
|
||||
id,
|
||||
namespace_id: ns,
|
||||
data,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,3 +91,121 @@ pub(crate) fn log_files_size(dir: &std::path::Path) -> u64 {
|
||||
/// allocates, not that allocation size.
|
||||
#[cfg(test)]
|
||||
pub(crate) const PREALLOCATION_THRESHOLD: u64 = 1024 * 1024;
|
||||
|
||||
#[cfg(test)]
|
||||
mod wire_compat_tests {
|
||||
use prost::Message as _;
|
||||
|
||||
use super::protos::{EntryImpl, LogStoreState, NamespaceImpl};
|
||||
|
||||
fn hex(s: &str) -> Vec<u8> {
|
||||
(0..s.len())
|
||||
.step_by(2)
|
||||
.map(|i| u8::from_str_radix(&s[i..i + 2], 16).unwrap())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Wire format captured from the rust-protobuf 2.28 encoder that preceded prost, so
|
||||
/// raft logs and namespace records written by older binaries stay readable (and
|
||||
/// vice versa for a rollback).
|
||||
#[test]
|
||||
fn entry_impl_encoding_matches_rust_protobuf() {
|
||||
let cases = [
|
||||
(EntryImpl::default(), ""),
|
||||
(
|
||||
EntryImpl {
|
||||
id: 1,
|
||||
namespace_id: 1,
|
||||
data: b"1".to_vec(),
|
||||
},
|
||||
"080110011a0131",
|
||||
),
|
||||
(
|
||||
EntryImpl {
|
||||
id: 300,
|
||||
..Default::default()
|
||||
},
|
||||
"08ac02",
|
||||
),
|
||||
(
|
||||
EntryImpl {
|
||||
namespace_id: 5,
|
||||
..Default::default()
|
||||
},
|
||||
"1005",
|
||||
),
|
||||
(
|
||||
EntryImpl {
|
||||
data: vec![0, 1, 2, 255],
|
||||
..Default::default()
|
||||
},
|
||||
"1a04000102ff",
|
||||
),
|
||||
];
|
||||
for (entry, expected) in cases {
|
||||
let expected = hex(expected);
|
||||
assert_eq!(entry.encode_to_vec(), expected);
|
||||
assert_eq!(EntryImpl::decode(expected.as_slice()).unwrap(), entry);
|
||||
}
|
||||
|
||||
let max = EntryImpl {
|
||||
id: u64::MAX,
|
||||
namespace_id: 12_345_678_901_234_567_890,
|
||||
data: vec![b'x'; 4096],
|
||||
};
|
||||
let mut expected = hex("08ffffffffffffffffff0110d295fcd8ceb1aaaaab011a8020");
|
||||
expected.extend(std::iter::repeat_n(b'x', 4096));
|
||||
assert_eq!(max.encode_to_vec(), expected);
|
||||
assert_eq!(EntryImpl::decode(expected.as_slice()).unwrap(), max);
|
||||
}
|
||||
|
||||
/// The decoder stays permissive for valid but non-canonical input: fields in any
|
||||
/// order, explicit proto3 defaults, and unknown fields (skipped by wire type) all
|
||||
/// decode, so entries written by a different conforming encoder remain readable.
|
||||
#[test]
|
||||
fn entry_impl_decoder_accepts_non_canonical_encodings() {
|
||||
// Field 2 before field 1.
|
||||
let reordered = EntryImpl::decode(hex("1005082a").as_slice()).unwrap();
|
||||
assert_eq!(
|
||||
reordered,
|
||||
EntryImpl {
|
||||
id: 42,
|
||||
namespace_id: 5,
|
||||
data: vec![]
|
||||
}
|
||||
);
|
||||
|
||||
// Explicit zero values for every field.
|
||||
let explicit_defaults = EntryImpl::decode(hex("080010001a00").as_slice()).unwrap();
|
||||
assert_eq!(explicit_defaults, EntryImpl::default());
|
||||
|
||||
// An unknown field (tag 2047, varint) before the known ones.
|
||||
let with_unknown = EntryImpl::decode(hex("f87f01087b1001").as_slice()).unwrap();
|
||||
assert_eq!(
|
||||
with_unknown,
|
||||
EntryImpl {
|
||||
id: 123,
|
||||
namespace_id: 1,
|
||||
data: vec![]
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn namespace_and_state_encoding_match_rust_protobuf() {
|
||||
let zero = NamespaceImpl::default();
|
||||
assert_eq!(zero.encode_to_vec(), b"");
|
||||
|
||||
let id42 = NamespaceImpl { id: 42 };
|
||||
assert_eq!(id42.encode_to_vec(), hex("082a"));
|
||||
assert_eq!(NamespaceImpl::decode(hex("082a").as_slice()).unwrap(), id42);
|
||||
|
||||
let max = NamespaceImpl { id: u64::MAX };
|
||||
assert_eq!(max.encode_to_vec(), hex("08ffffffffffffffffff01"));
|
||||
|
||||
let state = LogStoreState {
|
||||
last_index: 1 << 20,
|
||||
};
|
||||
assert_eq!(state.encode_to_vec(), hex("08808040"));
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ use crate::error::{
|
||||
use crate::metrics;
|
||||
use crate::raft_engine::backend::SYSTEM_NAMESPACE;
|
||||
use crate::raft_engine::close_engine;
|
||||
use crate::raft_engine::protos::logstore::{EntryImpl, NamespaceImpl};
|
||||
use crate::raft_engine::protos::{EntryImpl, NamespaceImpl};
|
||||
|
||||
const NAMESPACE_PREFIX: &str = "$sys/";
|
||||
|
||||
@@ -304,7 +304,6 @@ impl RaftEngineLogStore {
|
||||
id: entry_id,
|
||||
namespace_id: region_id.as_u64(),
|
||||
data: e.into_bytes(),
|
||||
..Default::default()
|
||||
}],
|
||||
)
|
||||
.context(AddEntryLogBatchSnafu)?;
|
||||
@@ -492,10 +491,7 @@ impl LogStore for RaftEngineLogStore {
|
||||
.put_message::<NamespaceImpl>(
|
||||
SYSTEM_NAMESPACE,
|
||||
key,
|
||||
&NamespaceImpl {
|
||||
id: namespace_id,
|
||||
..Default::default()
|
||||
},
|
||||
&NamespaceImpl { id: namespace_id },
|
||||
)
|
||||
.context(RaftEngineSnafu)?;
|
||||
let _ = self
|
||||
@@ -649,7 +645,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::error::Error;
|
||||
use crate::raft_engine::log_store::RaftEngineLogStore;
|
||||
use crate::raft_engine::protos::logstore::EntryImpl;
|
||||
use crate::raft_engine::protos::EntryImpl;
|
||||
use crate::raft_engine::{PREALLOCATION_THRESHOLD, log_files_size};
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
Reference in new issue
Block a user