@@ -1304,6 +1304,11 @@ pub struct NoOpStateTransition<T>(pub T);
13041304#[ derive( Debug , Clone ) ]
13051305#[ cfg_attr( any( test, debug_assertions) , derive( PartialEq ) ) ]
13061306pub struct StateCollections < T > {
1307+ /// The version of this state. This is typically identical to the version of the code
1308+ /// that wrote it, but may diverge during 0dt upgrades and similar operations when a
1309+ /// new version of code is intentionally interoperating with an older state format.
1310+ pub ( crate ) version : Version ,
1311+
13071312 // - Invariant: `<= all reader.since`
13081313 // - Invariant: Doesn't regress across state versions.
13091314 pub ( crate ) last_gc_req : SeqNo ,
@@ -2221,10 +2226,6 @@ where
22212226#[ derive( Debug ) ]
22222227#[ cfg_attr( any( test, debug_assertions) , derive( Clone , PartialEq ) ) ]
22232228pub struct State < T > {
2224- /// The version of this state. This is typically identical to the version of the code
2225- /// that wrote it, but may diverge during 0dt upgrades and similar operations when a
2226- /// new version of code is intentionally interoperating with an older state format.
2227- pub ( crate ) applier_version : semver:: Version ,
22282229 pub ( crate ) shard_id : ShardId ,
22292230
22302231 pub ( crate ) seqno : SeqNo ,
@@ -2254,10 +2255,9 @@ pub struct TypedState<K, V, T, D> {
22542255
22552256impl < K , V , T : Clone , D > TypedState < K , V , T , D > {
22562257 #[ cfg( any( test, debug_assertions) ) ]
2257- pub ( crate ) fn clone ( & self , applier_version : Version , hostname : String ) -> Self {
2258+ pub ( crate ) fn clone ( & self , hostname : String ) -> Self {
22582259 TypedState {
22592260 state : State {
2260- applier_version,
22612261 shard_id : self . shard_id . clone ( ) ,
22622262 seqno : self . seqno . clone ( ) ,
22632263 walltime_ms : self . walltime_ms ,
@@ -2271,7 +2271,6 @@ impl<K, V, T: Clone, D> TypedState<K, V, T, D> {
22712271 pub ( crate ) fn clone_for_rollup ( & self ) -> Self {
22722272 TypedState {
22732273 state : State {
2274- applier_version : self . applier_version . clone ( ) ,
22752274 shard_id : self . shard_id . clone ( ) ,
22762275 seqno : self . seqno . clone ( ) ,
22772276 walltime_ms : self . walltime_ms ,
@@ -2338,12 +2337,12 @@ where
23382337 walltime_ms : u64 ,
23392338 ) -> Self {
23402339 let state = State {
2341- applier_version,
23422340 shard_id,
23432341 seqno : SeqNo :: minimum ( ) ,
23442342 walltime_ms,
23452343 hostname,
23462344 collections : StateCollections {
2345+ version : applier_version,
23472346 last_gc_req : SeqNo :: minimum ( ) ,
23482347 rollups : BTreeMap :: new ( ) ,
23492348 active_rollup : None ,
@@ -2373,15 +2372,16 @@ where
23732372 // each version of state with the _max_ version of code that has ever
23742373 // contributed to it. Otherwise, we'd erroneously allow rolling back an
23752374 // arbitrary number of versions if they were done one-by-one.
2376- let new_applier_version = std:: cmp:: max ( & self . applier_version , & cfg. build_version ) ;
2375+ let new_applier_version = std:: cmp:: max ( & self . collections . version , & cfg. build_version ) ;
23772376 let mut new_state = State {
2378- applier_version : new_applier_version. clone ( ) ,
23792377 shard_id : self . shard_id ,
23802378 seqno : self . seqno . next ( ) ,
23812379 walltime_ms : ( cfg. now ) ( ) ,
23822380 hostname : cfg. hostname . clone ( ) ,
23832381 collections : self . collections . clone ( ) ,
23842382 } ;
2383+ new_state. collections . version = new_applier_version. clone ( ) ;
2384+
23852385 // Make sure walltime_ms is strictly increasing, in case clocks are
23862386 // offset.
23872387 if new_state. walltime_ms <= self . walltime_ms {
@@ -2752,13 +2752,13 @@ fn serialize_diffs_sum<S: Serializer>(val: &Option<[u8; 8]>, s: S) -> Result<S::
27522752impl < T : Serialize + Timestamp + Lattice > Serialize for State < T > {
27532753 fn serialize < S : Serializer > ( & self , s : S ) -> Result < S :: Ok , S :: Error > {
27542754 let State {
2755- applier_version,
27562755 shard_id,
27572756 seqno,
27582757 walltime_ms,
27592758 hostname,
27602759 collections :
27612760 StateCollections {
2761+ version : applier_version,
27622762 last_gc_req,
27632763 rollups,
27642764 active_rollup,
@@ -3140,12 +3140,12 @@ pub(crate) mod tests {
31403140 ( shard_id, seqno, walltime_ms, hostname, last_gc_req, rollups, active_rollup) ,
31413141 ( active_gc, leased_readers, critical_readers, writers, schemas, trace) ,
31423142 ) | State {
3143- applier_version : semver:: Version :: new ( 1 , 2 , 3 ) ,
31443143 shard_id,
31453144 seqno,
31463145 walltime_ms,
31473146 hostname,
31483147 collections : StateCollections {
3148+ version : Version :: new ( 1 , 2 , 3 ) ,
31493149 last_gc_req,
31503150 rollups,
31513151 active_rollup,
0 commit comments