Fail if the database was stamped by a newer schema than this build reads.
(txn: &ReadTransaction)
| 261 | |
| 262 | /// Fail if the database was stamped by a newer schema than this build reads. |
| 263 | pub fn check_schema_version(txn: &ReadTransaction) -> PristineResult<()> { |
| 264 | let found = match txn.open_table(ATOMIC_META) { |
| 265 | Ok(meta) => match meta.get(SCHEMA_VERSION_KEY)? { |
| 266 | Some(stored) => <[u8; 8]>::try_from(stored.value()) |
| 267 | .map(u64::from_le_bytes) |
| 268 | .map_err(|_| PristineError::Inconsistent { |
| 269 | message: "schema version in atomic_meta is not 8 bytes".to_string(), |
| 270 | })?, |
| 271 | None => BASE_SCHEMA_VERSION, |
| 272 | }, |
| 273 | Err(TableError::TableDoesNotExist(_)) => BASE_SCHEMA_VERSION, |
| 274 | Err(error) => return Err(error.into()), |
| 275 | }; |
| 276 | if found > SCHEMA_VERSION { |
| 277 | return Err(PristineError::UnsupportedSchema { |
| 278 | found, |
| 279 | supported: SCHEMA_VERSION, |
| 280 | }); |
| 281 | } |
| 282 | let key = format!( |
| 283 | "{}{}", |
| 284 | crate::pristine::REQUIRED_CAPABILITY_PREFIX, |
| 285 | crate::pristine::SPAN_PROJECTED_SEMANTICS_CAPABILITY.id() |
| 286 | ); |
| 287 | let projected = match txn.open_table(PRISTINE_META) { |
| 288 | Ok(table) => table.get(key.as_str())?.map(|value| value.value()), |
| 289 | Err(TableError::TableDoesNotExist(_)) => None, |
| 290 | Err(error) => return Err(error.into()), |
| 291 | }; |
| 292 | if found >= PROJECTED_SEMANTICS_SCHEMA_VERSION { |
| 293 | if projected.is_none_or(|version| { |
| 294 | version < crate::pristine::SPAN_PROJECTED_SEMANTICS_CAPABILITY.minimum_version() |
| 295 | }) { |
| 296 | return Err(PristineError::Inconsistent { |
| 297 | message: "projected schema is missing its required semantic capability".into(), |
| 298 | }); |
| 299 | } |
| 300 | } else if projected.is_some() { |
| 301 | return Err(PristineError::Inconsistent { |
| 302 | message: "projected semantic capability is missing its required schema fence".into(), |
| 303 | }); |
| 304 | } |
| 305 | Ok(()) |
| 306 | } |
| 307 | |
| 308 | /// Refuse requirements unknown to this build without opening a writable |
| 309 | /// database handle. Physical maintenance must perform this check too. |