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