Skip to content

Commit 6f57654

Browse files
committed
fix(meta): ignore legacy StateMachineId during V004 upgrade
# Summary Drop obsolete V003 StateMachineId raft-state entries while upgrading to the V004 raft log format so old meta data can start without hitting the V004 importer panic. # Details StateMachineId has no V004 raft-log representation and should not be forwarded as a V003 RaftStateKV. The upgrade path now models dropped entries explicitly with None and skips them in both V003 import loops. Verified with a v1.2.292 debug fixture containing a legacy StateMachineId row: unpatched v1.2.768 panicked at the V004 importer, while the patched debug build upgraded to V004 and started successfully.
1 parent 2db11df commit 6f57654

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/meta/raft-store/src/key_spaces.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,16 +253,16 @@ pub enum RaftStoreEntry {
253253

254254
impl RaftStoreEntry {
255255
/// Upgrade V003 to V004
256-
pub fn upgrade(self) -> Self {
256+
pub fn upgrade(self) -> Option<Self> {
257257
match self.clone() {
258-
Self::Logs { key: _, value } => Self::LogEntry(value),
258+
Self::Logs { key: _, value } => Some(Self::LogEntry(value)),
259259
Self::RaftStateKV { key: _, value } => match value {
260-
RaftStateValue::NodeId(node_id) => Self::NodeId(Some(node_id)),
261-
RaftStateValue::HardState(vote) => Self::Vote(Some(vote)),
262-
RaftStateValue::Committed(committed) => Self::Committed(committed),
263-
RaftStateValue::StateMachineId(_) => self,
260+
RaftStateValue::NodeId(node_id) => Some(Self::NodeId(Some(node_id))),
261+
RaftStateValue::HardState(vote) => Some(Self::Vote(Some(vote))),
262+
RaftStateValue::Committed(committed) => Some(Self::Committed(committed)),
263+
RaftStateValue::StateMachineId(_) => None,
264264
},
265-
Self::LogMeta { key: _, value } => Self::Purged(Some(value.log_id())),
265+
Self::LogMeta { key: _, value } => Some(Self::Purged(Some(value.log_id()))),
266266

267267
RaftStoreEntry::DataHeader { .. }
268268
| RaftStoreEntry::Nodes { .. }
@@ -275,7 +275,7 @@ impl RaftStoreEntry {
275275
| RaftStoreEntry::NodeId(_)
276276
| RaftStoreEntry::Vote(_)
277277
| RaftStoreEntry::Committed(_)
278-
| RaftStoreEntry::Purged(_) => self,
278+
| RaftStoreEntry::Purged(_) => Some(self),
279279
}
280280
}
281281

src/meta/raft-store/src/ondisk/upgrade_to_v004.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ impl OnDisk {
8989
})?;
9090

9191
let ent = RaftStoreEntry::deserialize(&k, &v)?;
92-
let upgraded = ent.upgrade();
92+
let Some(upgraded) = ent.upgrade() else {
93+
continue;
94+
};
9395
if let RaftStoreEntry::LogEntry(entry) = &upgraded {
9496
if entry.log_id.index < first_log_index {
9597
debug!(
@@ -116,7 +118,9 @@ impl OnDisk {
116118
for kv in kvs {
117119
let ent = RaftStoreEntry::deserialize(&kv[0], &kv[1])?;
118120
debug!("import V003 entry: {:?}", ent);
119-
let upgraded = ent.upgrade();
121+
let Some(upgraded) = ent.upgrade() else {
122+
continue;
123+
};
120124
importer.import_raft_store_entry(upgraded)?;
121125
}
122126
}

0 commit comments

Comments
 (0)