-
Notifications
You must be signed in to change notification settings - Fork 482
Reduce dependencies of catalog-protos #34105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
antiguru
wants to merge
1
commit into
MaterializeInc:main
Choose a base branch
from
antiguru:mz_catalog_types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| [package] | ||
| name = "mz-catalog-types" | ||
| version = "0.0.0" | ||
| edition.workspace = true | ||
| rust-version.workspace = true | ||
| publish = false | ||
|
|
||
| [lints] | ||
| workspace = true | ||
|
|
||
| # The crate deliberately has few dependencies. Please don't add new dependencies without | ||
| # discussing with the Materialize team. Specifically, avoid adding dependencies that | ||
| # bring in large dependency trees. | ||
| [dependencies] | ||
| serde = { version = "1.0.219", features = ["derive"] } | ||
| tracing = "0.1.37" | ||
| workspace-hack = { version = "0.0.0", path = "../workspace-hack", optional = true } | ||
|
|
||
| [dev-dependencies] | ||
|
|
||
| [build-dependencies] | ||
|
|
||
| [package.metadata.cargo-udeps.ignore] | ||
| normal = ["workspace-hack"] | ||
|
|
||
| [features] | ||
| default = ["workspace-hack"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| // Copyright Materialize, Inc. and contributors. All rights reserved. | ||
| // | ||
| // Use of this software is governed by the Business Source License | ||
| // included in the LICENSE file. | ||
| // | ||
| // As of the Change Date specified in that file, in accordance with | ||
| // the Business Source License, use of this software will be governed | ||
| // by the Apache License, Version 2.0. | ||
|
|
||
| //! Types related to clusters. | ||
|
|
||
| use std::fmt; | ||
| use std::str::FromStr; | ||
|
|
||
| use serde::{Deserialize, Serialize}; | ||
| use tracing::error; | ||
|
|
||
| /// Identifier of a storage instance. | ||
| #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] | ||
| pub enum StorageInstanceId { | ||
| /// A system storage instance. | ||
| System(u64), | ||
| /// A user storage instance. | ||
| User(u64), | ||
| } | ||
|
|
||
| impl StorageInstanceId { | ||
| /// Creates a new `StorageInstanceId` in the system namespace. The top 16 bits of `id` must be | ||
| /// 0, because this ID is packed into 48 bits of | ||
| /// `mz_repr::GlobalId::IntrospectionSourceIndex`. | ||
| pub fn system(id: u64) -> Option<Self> { | ||
| Self::new(id, Self::System) | ||
| } | ||
|
|
||
| /// Creates a new `StorageInstanceId` in the user namespace. The top 16 bits of `id` must be | ||
| /// 0, because this ID is packed into 48 bits of | ||
| /// `mz_repr::GlobalId::IntrospectionSourceIndex`. | ||
| pub fn user(id: u64) -> Option<Self> { | ||
| Self::new(id, Self::User) | ||
| } | ||
|
|
||
| fn new(id: u64, variant: fn(u64) -> Self) -> Option<Self> { | ||
| const MASK: u64 = 0xFFFF << 48; | ||
| const WARN_MASK: u64 = 1 << 47; | ||
| if MASK & id == 0 { | ||
| if WARN_MASK & id != 0 { | ||
| error!("{WARN_MASK} or more `StorageInstanceId`s allocated, we will run out soon"); | ||
| } | ||
| Some(variant(id)) | ||
| } else { | ||
| None | ||
| } | ||
| } | ||
|
|
||
| /// Extract the inner u64 ID. | ||
| pub fn inner_id(&self) -> u64 { | ||
| match self { | ||
| StorageInstanceId::System(id) | StorageInstanceId::User(id) => *id, | ||
| } | ||
| } | ||
|
|
||
| /// Returns true if this represents a user object. | ||
| pub fn is_user(&self) -> bool { | ||
| matches!(self, Self::User(_)) | ||
| } | ||
|
|
||
| /// Returns true if this represents a system object. | ||
| pub fn is_system(&self) -> bool { | ||
| matches!(self, Self::System(_)) | ||
| } | ||
| } | ||
|
|
||
| impl FromStr for StorageInstanceId { | ||
| type Err = IdParseError<Cluster>; | ||
|
|
||
| fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| if s.len() < 2 { | ||
| return Err(s.into()); | ||
| } | ||
| let val: u64 = s[1..].parse()?; | ||
| match s.chars().next().unwrap() { | ||
| 's' => Ok(Self::System(val)), | ||
| 'u' => Ok(Self::User(val)), | ||
| _ => Err(s.into()), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// An error parsing a `StorageInstanceId`. | ||
| #[derive(Debug)] | ||
| pub struct IdParseError<V> { | ||
| reason: String, | ||
| _marker: std::marker::PhantomData<V>, | ||
| } | ||
|
|
||
| impl<V: fmt::Debug> std::error::Error for IdParseError<V> {} | ||
|
|
||
| impl<V> fmt::Display for IdParseError<V> { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| write!(f, "couldn't parse id {}", self.reason) | ||
| } | ||
| } | ||
|
|
||
| impl<V> From<&str> for IdParseError<V> { | ||
| fn from(reason: &str) -> Self { | ||
| reason.to_string().into() | ||
| } | ||
| } | ||
|
|
||
| impl<V> From<std::num::ParseIntError> for IdParseError<V> { | ||
| fn from(error: std::num::ParseIntError) -> Self { | ||
| error.to_string().into() | ||
| } | ||
| } | ||
|
|
||
| impl<V> From<String> for IdParseError<V> { | ||
| fn from(reason: String) -> Self { | ||
| Self { | ||
| reason, | ||
| _marker: std::marker::PhantomData, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl fmt::Display for StorageInstanceId { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| match self { | ||
| Self::System(id) => write!(f, "s{}", id), | ||
| Self::User(id) => write!(f, "u{}", id), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Identifier of a replica. | ||
| #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] | ||
| pub enum ReplicaId { | ||
| /// A user replica. | ||
| User(u64), | ||
| /// A system replica. | ||
| System(u64), | ||
| } | ||
|
|
||
| impl ReplicaId { | ||
| /// Return the inner numeric ID value. | ||
| pub fn inner_id(&self) -> u64 { | ||
| match self { | ||
| ReplicaId::User(id) => *id, | ||
| ReplicaId::System(id) => *id, | ||
| } | ||
| } | ||
|
|
||
| /// Whether this value identifies a user replica. | ||
| pub fn is_user(&self) -> bool { | ||
| matches!(self, Self::User(_)) | ||
| } | ||
|
|
||
| /// Whether this value identifies a system replica. | ||
| pub fn is_system(&self) -> bool { | ||
| matches!(self, Self::System(_)) | ||
| } | ||
| } | ||
|
|
||
| impl fmt::Display for ReplicaId { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| match self { | ||
| Self::User(id) => write!(f, "u{}", id), | ||
| Self::System(id) => write!(f, "s{}", id), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl FromStr for ReplicaId { | ||
| type Err = IdParseError<Replica>; | ||
|
|
||
| fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| let first = s.chars().next(); | ||
| let rest = s.get(1..); | ||
| if let (Some(prefix), Some(num)) = (first, rest) { | ||
| let id = num.parse()?; | ||
| match prefix { | ||
| 'u' => return Ok(Self::User(id)), | ||
| 's' => return Ok(Self::System(id)), | ||
| _ => (), | ||
| } | ||
| } | ||
|
|
||
| Err(s.into()) | ||
| } | ||
| } | ||
|
|
||
| /// A marker type for replica ID parse errors. | ||
| #[derive(Debug)] | ||
| pub struct Replica; | ||
| impl fmt::Display for Replica { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| write!(f, "replica") | ||
| } | ||
| } | ||
|
|
||
| /// A marker type for cluster ID parse errors. | ||
| #[derive(Debug)] | ||
| pub struct Cluster; | ||
| impl fmt::Display for Cluster { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| write!(f, "cluster") | ||
| } | ||
| } |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Copyright Materialize, Inc. and contributors. All rights reserved. | ||
| // | ||
| // Use of this software is governed by the Business Source License | ||
| // included in the LICENSE file. | ||
| // | ||
| // As of the Change Date specified in that file, in accordance with | ||
| // the Business Source License, use of this software will be governed | ||
| // by the Apache License, Version 2.0. | ||
|
|
||
| //! Catalog configuration types. | ||
|
|
||
| #![deny(missing_docs)] | ||
|
|
||
| pub mod cluster; | ||
| pub mod compute; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not using this implementation. Should remove the
Timestamptype from the proto, but that'd require a migration.