1use crate::blob_metadata::{BlobMetadata, BlobMetadataV53};
6use crate::lsm_tree::{
7 PersistentLayerHeader, PersistentLayerHeaderV39, PersistentLayerInfo, PersistentLayerInfoV39,
8};
9use crate::object_store::allocator::{
10 AllocatorInfo, AllocatorInfoV32, AllocatorKey, AllocatorKeyV32, AllocatorValue,
11 AllocatorValueV32,
12};
13use crate::object_store::journal::super_block::{
14 SuperBlockHeader, SuperBlockHeaderV32, SuperBlockHeaderV61, SuperBlockRecord,
15 SuperBlockRecordV56, SuperBlockRecordV59, SuperBlockRecordV62,
16};
17use crate::object_store::journal::{
18 JournalRecord, JournalRecordV56, JournalRecordV57, JournalRecordV59, JournalRecordV60,
19 JournalRecordV61, JournalRecordV62,
20};
21use crate::object_store::object_record::{
22 FsverityMetadata, FsverityMetadataV50, ObjectKey, ObjectKeyV54, ObjectValue, ObjectValueV56,
23 ObjectValueV59, ObjectValueV62,
24};
25use crate::object_store::transaction::{
26 Mutation, MutationV56, MutationV57, MutationV59, MutationV61, MutationV62,
27};
28use crate::object_store::{
29 EncryptedMutations, EncryptedMutationsV49, EncryptedTransaction, EncryptedTransactionV57,
30 EncryptedTransactionV59, EncryptedTransactionV61, EncryptedTransactionV62, StoreInfo,
31 StoreInfoV52,
32};
33use crate::serialized_types::{Version, Versioned, VersionedLatest, versioned_type};
34use std::collections::BTreeMap;
35
36pub const LATEST_VERSION: Version = Version { major: 62, minor: 0 };
46
47pub const OLD_KEY_SERIALIZATION_VERSION: Version = Version { major: 57, minor: 0 };
50
51pub const EARLIEST_SUPPORTED_VERSION: Version = Version { major: 56, minor: 0 };
60
61pub const AES_JOURNAL_ENCRYPTION_VERSION: Version = Version { major: 57, minor: 0 };
64
65#[allow(dead_code)]
69trait UniqueVersionForType {}
70
71trait HasVersion {
72 const VERSION: u32;
73}
74
75macro_rules! versioned_types {
76 ( $( $name:ident { $latest:literal.. => $latest_type:ty $(, $major:literal.. => $type:ty )* $(,)? } )+ ) => {
77 $(
78 static_assertions::assert_type_eq_all!($name, $latest_type);
79
80 versioned_type! {
81 $latest.. => $latest_type,
82 $( $major.. => $type ),*
83 }
84
85 impl UniqueVersionForType for $latest_type {}
86 $( impl UniqueVersionForType for $type {} )*
87
88 impl HasVersion for $latest_type {
89 const VERSION: u32 = $latest;
90 }
91
92 )+
93
94 pub fn get_type_fingerprints(version: Version) -> BTreeMap<String, String> {
95 let mut map = BTreeMap::new();
96 $(
97 let fingerprint = {
98 let mut fp = None;
99 const FINGERPRINTS: &[(u32, fn() -> String)] = &[
100 ($latest, <$latest_type as fprint::TypeFingerprint>::fingerprint),
101 $( ($major, <$type as fprint::TypeFingerprint>::fingerprint) ),*
102 ];
103 for (major, type_fp) in FINGERPRINTS {
104 if version.major >= *major {
105 fp = Some(type_fp());
106 break;
107 }
108 }
109 fp
110 };
111 if let Some(fp) = fingerprint {
112 map.insert(stringify!($name).to_string(), fp.to_string());
113 }
114 )+
115 map
116 }
117 };
118}
119
120versioned_types! {
121 AllocatorInfo {
122 32.. => AllocatorInfoV32,
123 }
124 AllocatorKey {
125 32.. => AllocatorKeyV32,
126 }
127 AllocatorValue {
128 32.. => AllocatorValueV32,
129 }
130 EncryptedMutations {
131 49.. => EncryptedMutationsV49,
132 }
133 EncryptedTransaction {
134 62.. => EncryptedTransactionV62,
135 61.. => EncryptedTransactionV61,
136 59.. => EncryptedTransactionV59,
137 57.. => EncryptedTransactionV57,
138 }
139 FsverityMetadata {
140 50.. => FsverityMetadataV50,
141 }
142 JournalRecord {
143 62.. => JournalRecordV62,
144 61.. => JournalRecordV61,
145 60.. => JournalRecordV60,
146 59.. => JournalRecordV59,
147 57.. => JournalRecordV57,
148 56.. => JournalRecordV56,
149 }
150 Mutation {
151 62.. => MutationV62,
152 61.. => MutationV61,
153 59.. => MutationV59,
154 57.. => MutationV57,
155 56.. => MutationV56,
156 }
157 ObjectKey {
158 54.. => ObjectKeyV54,
159 }
160 ObjectValue {
161 62.. => ObjectValueV62,
162 59.. => ObjectValueV59,
163 56.. => ObjectValueV56,
164 }
165 PersistentLayerHeader {
166 39.. => PersistentLayerHeaderV39,
167 }
168 PersistentLayerInfo {
169 39.. => PersistentLayerInfoV39,
170 }
171 StoreInfo {
172 52.. => StoreInfoV52,
173 }
174 SuperBlockHeader {
175 61.. => SuperBlockHeaderV61,
176 32.. => SuperBlockHeaderV32,
177 }
178 SuperBlockRecord {
179 62.. => SuperBlockRecordV62,
180 59.. => SuperBlockRecordV59,
181 56.. => SuperBlockRecordV56,
182 }
183 BlobMetadata {
184 53.. => BlobMetadataV53,
185 }
186}
187
188static_assertions::const_assert!(
192 <EncryptedTransaction as HasVersion>::VERSION <= <Mutation as HasVersion>::VERSION
193);
194
195#[cfg(test)]
196mod tests {
197 use super::*;
198
199 #[fuchsia::test]
200 fn test_get_type_fingerprints() {
201 let latest = get_type_fingerprints(LATEST_VERSION);
202 assert!(!latest.is_empty());
203 assert!(latest.contains_key("JournalRecord"));
204 assert!(latest.contains_key("Mutation"));
205 assert!(latest.contains_key("ObjectKey"));
206
207 let earliest = get_type_fingerprints(EARLIEST_SUPPORTED_VERSION);
208 assert!(!earliest.is_empty());
209 assert!(earliest.contains_key("JournalRecord"));
210 assert!(!earliest.contains_key("EncryptedTransaction"));
211
212 let too_old = get_type_fingerprints(Version { major: 1, minor: 0 });
213 assert!(too_old.is_empty());
214 }
215}