pub struct SchemaRegistry { /* private fields */ }Expand description
Thread-safe, in-memory schema registry.
Tracks the schema for every measurement. Schemas are created automatically on first write and evolve additively (new tags/fields added, type conflicts rejected).
§Schema Evolution
The registry follows a schema-on-write model:
| Operation | Supported | Mechanism |
|---|---|---|
| Add tag/field | Yes | Automatic on write |
| Type conflict | Rejected | SchemaError |
| Remove column | No | N/A (append-only) |
| Rename column | No | N/A |
| Change column type | No | Write new field |
Durability is the catalog manifest’s job: the database persists every action this registry returns before it writes the data that needs it.
Implementations§
Source§impl SchemaRegistry
impl SchemaRegistry
Sourcepub fn register_batch(
&self,
points: &[&Point],
) -> Result<Vec<SchemaAction>, SchemaError>
pub fn register_batch( &self, points: &[&Point], ) -> Result<Vec<SchemaAction>, SchemaError>
Register every point of a batch, or none of them.
Validates the whole batch against the current schemas and against the columns earlier points of the same batch introduce, and only then applies the additions. A type conflict anywhere in the batch rejects it with the registry untouched — which is the property that lets the caller persist every returned action unconditionally. Registering point by point left the columns of the first points behind when a later point was refused, and nothing ever persisted them.
Returns the actions the batch caused, in application order. Empty when the batch fits the existing schemas, which is the common case and takes no lock.
§Errors
Returns SchemaError::TypeConflict if any field’s type conflicts
with the schema, or with the type another point of the batch gives
the same field.
Sourcepub fn register_point(
&self,
point: &Point,
) -> Result<Vec<SchemaAction>, SchemaError>
pub fn register_point( &self, point: &Point, ) -> Result<Vec<SchemaAction>, SchemaError>
Register a single point — register_batch
for one point.
§Errors
Returns SchemaError::TypeConflict if a field’s type doesn’t match
the existing schema.
Sourcepub fn lookup(&self, measurement: &str) -> Option<Arc<MeasurementSchema>>
pub fn lookup(&self, measurement: &str) -> Option<Arc<MeasurementSchema>>
Look up the schema for a measurement.
Returns Arc<MeasurementSchema> for an O(1) clone.
Sourcepub fn register_schema(&self, name: &str, schema: MeasurementSchema)
pub fn register_schema(&self, name: &str, schema: MeasurementSchema)
Register a pre-built schema directly (e.g. during catalog replay on startup). If the measurement already has a schema, the existing one is kept unchanged.
Sourcepub fn register_measurement(&self, ms: MeasurementSchema)
pub fn register_measurement(&self, ms: MeasurementSchema)
Register a measurement from a MeasurementSchema (WAL replay).
Idempotent: if the measurement already exists the call is a no-op.
Sourcepub fn apply_add_column(&self, measurement: &str, column: ColumnDef)
pub fn apply_add_column(&self, measurement: &str, column: ColumnDef)
Apply an AddColumn action from WAL replay.
Idempotent: if the column already exists it is not duplicated. Checks for role conflicts (e.g., tag vs field with same name).
Sourcepub fn measurement_count(&self) -> usize
pub fn measurement_count(&self) -> usize
Returns the number of registered measurements.
Sourcepub fn measurement_names(&self) -> Vec<String>
pub fn measurement_names(&self) -> Vec<String>
Returns all registered measurement names.
Trait Implementations§
Source§impl Clone for SchemaRegistry
impl Clone for SchemaRegistry
Source§fn clone(&self) -> SchemaRegistry
fn clone(&self) -> SchemaRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more