v0.1 → v0.2 迁移指南 / v0.1 → v0.2 Migration Guide
v0.2.0 已发布。本页只描述 v0.1.x → v0.2.0,不代表后续 main 分支的格式或兼容性承诺。
v0.2.0 is released. This page covers only v0.1.x → v0.2.0; it does not describe later main-branch formats or
compatibility guarantees.
v0.2.0 保留 v0.1.x Raft RPC wire format,并支持读取旧裸快照。幂等和 Kafka 输入是可选功能;涉及下列破坏性 API 的下游代码 仍需修改后重编译。
v0.2.0 retains the v0.1.x Raft RPC wire format and reads legacy unframed snapshots. Idempotency and Kafka input are opt-in, but downstream code using the breaking APIs below still requires changes and recompilation.
升级摘要 / Upgrade Summary
Rr 尚未发布到 crates.io;下游项目使用固定 v0.2.0 tag 的 git 依赖,不要用 branch = "main" 代替固定 tag。
Rr is not published to crates.io. Downstream projects use git dependencies pinned to the v0.2.0 tag; do not substitute
branch = "main".
[dependencies]
rr-server = { git = "https://github.com/gardenias/rr.git", tag = "v0.2.0" }
rr-client = { git = "https://github.com/gardenias/rr.git", tag = "v0.2.0" }
rr-core = { git = "https://github.com/gardenias/rr.git", tag = "v0.2.0" }
rr-raft = { git = "https://github.com/gardenias/rr.git", tag = "v0.2.0" }
# 可选 Kafka 输入 / optional Kafka input:
# rr-ingestor-kafka = { git = "https://github.com/gardenias/rr.git", tag = "v0.2.0", features = ["rdkafka"] }
修复破坏性调用、重编译,并按 滚动升级流程 部署。明文到 TLS 的切换不是无停机操作,必须先读该页警告。
Fix breaking calls, recompile, and deploy using the upgrade procedure. A plaintext-to-TLS cutover is not zero-downtime; read that page's warning first.
破坏性变更 / Breaking Changes
ServiceStateMachineAdapter::new 签名 / ServiceStateMachineAdapter::new Signature
v0.2.0 要求传入 group_id: u64,供每组指标标签使用。工厂闭包应把收到的 gid 传给 adapter:
v0.2.0 requires group_id: u64 for per-group metric labels. Pass the factory's gid into the adapter:
// v0.1.x / before:
// Box::new(ServiceStateMachineAdapter::new(my_service.clone())) as Box<dyn StateMachine>
// v0.2.0 / after:
let factory = Box::new(|gid| {
Box::new(ServiceStateMachineAdapter::new(gid, my_service.clone())) as Box<dyn StateMachine>
});
DurabilityPolicy 改名 / DurabilityPolicy Rename
| v0.1.x | v0.2.0 | 含义 / Meaning |
|---|---|---|
Strict | Strict | 每次提交 fsync;唯一满足完整持久化契约的策略 / Fsync every commit; the only fully durable policy |
Balanced | ReplicatedOnly | 依赖复制,不保证多数派同时掉电后的已 ACK 写 / Relies on replication; acknowledged writes can be lost on majority power loss |
Fast | TestOnly | 不 fsync;仅限测试 / No fsync; tests only |
v0.2.0 中旧枚举名仍是 deprecated aliases,会触发编译弃用提示和首次运行时警告;它们在 v1.0.0 移除。生产保持 Strict。
In v0.2.0, old enum names remain deprecated aliases with compile-time lints and a first-use runtime warning; they are
removed in v1.0.0. Keep Strict in production.
allow_insecure 显式开关 / Explicit allow_insecure Opt-In
v0.2.0 在启用 Raft 时检查 TLS、mTLS 和 Admin token;不安全配置默认拒绝启动。该开关只用于本地开发、examples 和 CI,并暴露
rr_security_insecure_mode = 1。
v0.2.0 validates TLS, mTLS, and the Admin token when Raft is enabled, refusing insecure configurations by default. The
override is for local development, examples, and CI only, and exposes rr_security_insecure_mode = 1.
[node]
allow_insecure = true
rr-server serve --allow-insecure --config /etc/rr/config.toml
# 或 / or: RR_ALLOW_INSECURE=true
生产使用默认值 false 并配置 TLS + mTLS + admin_token,详见 TLS 部署指南。
Production keeps the default false and configures TLS + mTLS + admin_token; see the TLS deployment guide.
其他破坏性变更 / Other Breaking Changes
完整原因见 CHANGELOG 和 v0.2.0 release notes。下游最常遇到:
See the CHANGELOG and v0.2.0 release notes for rationale. Common downstream impacts:
-
RaftNode::new_with_factory/new_single_node/new_with_rocks_factory改为返回Result<Self, RrError>,不再panic。
These constructors now returnResult<Self, RrError>instead of panicking. -
未接线的
rr_network::RrGrpcClient/RrGrpcServer脚手架被移除。The unwired
rr_network::RrGrpcClient/RrGrpcServerstubs were removed. -
GroupMeta.leader、ShardRouter::get_leader/get_leader_addr和RouterError::NoLeader被移除;leader 发现由客户 端 redirect cache 负责。Leader fields and lookup APIs were removed; the client redirect cache owns leader discovery.
-
公共错误枚举改为
#[non_exhaustive],下游match需要通配分支。Public error enums are
#[non_exhaustive]; downstream matches need a wildcard arm. -
RocksConfig::default()改用DurabilityPolicy::Strict。严格 fsync 会改变写性能,按 存储引擎指南 评估。RocksConfig::default()now usesStrict; evaluate the write-performance impact with the storage engines guide. -
kafka_offset_to_request_id/OffsetToRequestId返回Result,无法解码的 offset fail-closed。These offset-mapping APIs return
Resultand fail closed on undecodable offsets.
快照 wire 格式 / Snapshot Wire Format
FramedSnapshot 快照信封 / FramedSnapshot Envelope
ServiceStateMachineAdapter 把 Service::snapshot() 的原始字节包在 FramedSnapshot 中:8 字节 magic \0rrSNAP1 加
bincode body,携带可选 IdempotencyState、IngestorState 等框架状态。
ServiceStateMachineAdapter wraps raw Service::snapshot() bytes in FramedSnapshot: an 8-byte \0rrSNAP1 magic plus
a bincode body containing optional framework state such as IdempotencyState and IngestorState.
恢复时,缺少 magic 的 v0.1.x 快照按旧裸用户字节处理;这发生在 restore(),不是“读取后立即改写”。下一次成功构建快照才写
入新信封。当前 envelope version = 1,更高版本会被拒绝。
During restore, v0.1.x snapshots without the magic are treated as legacy raw user bytes. This happens in restore(); a
read does not immediately rewrite the snapshot. The next successful snapshot build writes the new envelope. The current
envelope version is 1, and newer versions are rejected.
FramedEntry 日志信封 / FramedEntry Envelope
只有携带 ingestor 字段或客户端 IdempotencyKey 的 Raft entry 使用 FramedEntry { version, offset, idem_key, payload }
;不含这些字段的 entry 保留裸字节路径。更高 version 同样被拒绝。
Raft entries carrying ingestor fields or a client IdempotencyKey use
FramedEntry { version, offset, idem_key, payload }; entries without them retain the bare-bytes path. Newer version
values are rejected here as well.
滚动升级步骤 / Rolling Upgrade Procedure
此流程只覆盖 v0.1.x → v0.2.0 的混合版本 Raft RPC。若同时从明文切到 TLS,按 升级指南 另安排维护窗口。
This procedure covers mixed-version Raft RPC for v0.1.x → v0.2.0 only. If also moving from plaintext to TLS, schedule the separate maintenance window described in Upgrading.
-
确认健康。 leader 稳定、无复制 lag,记录当前指标与备份位置。
Confirm health. Ensure a stable leader and no replication lag; record metrics and backup locations.
-
逐节点升级。 drain 并停止节点,替换二进制,完成必要代码/配置修改后启动。
Upgrade one node at a time. Drain and stop the node, replace the binary, apply required code/config changes, then start it.
-
验证再继续。
/ready返回 200,leader 稳定,成员与日志追平;旧快照由restore()兼容路径读取。Verify before continuing. Wait for
/ready200, a stable leader, correct membership, and log catch-up; legacy snapshots use the compatiblerestore()path. -
检查可选功能。 未启用幂等或 ingestor 的节点不应出现非零
rr_idempotency_*/rr_ingestor_*活动。Check opt-in features. Nodes without idempotency or an ingestor should show no nonzero
rr_idempotency_*/rr_ingestor_*activity.
不需要手工重建快照;下一次快照自动产生新信封。
No manual snapshot rebuild is required; the next snapshot automatically uses the new envelope.
可选新功能 / Optional New Features
客户端幂等 / Client-Side Idempotency
按请求启用,不使用的代码路径不变。
Enable per request; code paths that do not use it remain unchanged.
let key = IdempotencyKey::new("transfer", request_id_from_app);
let resp = client.send_request_idempotent(group_id, payload, key).await?;
详见 幂等指南。
See the Idempotency Guide.
Kafka 输入 / Kafka Input
添加 rr-ingestor-kafka 并调用 attach_ingestor_with_auto_idempotency:
Add rr-ingestor-kafka and call attach_ingestor_with_auto_idempotency:
[dependencies]
rr-ingestor-kafka = { git = "https://github.com/gardenias/rr.git", tag = "v0.2.0", features = ["rdkafka"] }
use rr_raft::ingestor_runner::{AutoIdempotency, OffsetMapError};
let ingestor = KafkaIngestor::new(group_id, cfg.clone()).await?;
mgr.attach_ingestor_with_auto_idempotency(
group_id,
Box::new(ingestor),
AutoIdempotency {
request_type: cfg.topic_for(group_id),
offset_to_request_id: Box::new(|b| {
kafka_offset_to_request_id(b).map_err(OffsetMapError::new)
}),
},
).await?;
详见 Kafka 输入指南。
See the Kafka Input Guide.
降级 / Downgrade
不要假定 v0.2.0 → v0.1.x 总是可滚动降级。v0.1.x 不理解 FramedSnapshot;即使幂等和 ingestor 未启用,新快照仍有外层信封
。禁用功能后再触发快照也不会把它变成旧格式。
Do not assume v0.2.0 → v0.1.x is always rolling-safe. v0.1.x does not understand FramedSnapshot; even without
idempotency or an ingestor, a new snapshot still has the envelope. Disabling features and triggering another snapshot
does not convert it to the legacy format.
只有在目标版本兼容性记录明确覆盖、且未写入不兼容快照/日志时,才逐节点回退。否则使用应用自己的导出/导入路径,或在完整灾难 恢复方案中恢复升级前离线备份;不要把旧备份直接覆盖到运行中或非空目录。已测试版本以 CHANGELOG 为准。
Roll back node by node only when the target compatibility record explicitly covers it and no incompatible snapshot/log has been written. Otherwise use the application's export/import path or restore a pre-upgrade offline backup as part of a full disaster-recovery plan. Never overwrite a running or non-empty data directory with an old archive. Consult the CHANGELOG for tested versions.