Skip to content

Commit cca5e13

Browse files
committed
catalog: rename WireCompatible to JsonCompatible
Wire compatibility is a networking term and somewhat confusing in the context of a catalog. This commit renames the `WireCompatible` trait and `wire_compatible!` macro to `JsonCompatible`/`json_compatible!`. The new name also surfaces the requirement that implementing types must be JSON-serializable.
1 parent dfcb523 commit cca5e13

File tree

5 files changed

+67
-67
lines changed

5 files changed

+67
-67
lines changed

src/catalog/src/durable/upgrade/v67_to_v68.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@
99

1010
use crate::durable::traits::{UpgradeFrom, UpgradeInto};
1111
use crate::durable::upgrade::MigrationAction;
12-
use crate::durable::upgrade::wire_compatible::{WireCompatible, wire_compatible};
12+
use crate::durable::upgrade::wire_compatible::{JsonCompatible, json_compatible};
1313
use crate::durable::upgrade::{objects_v67 as v67, objects_v68 as v68};
1414

15-
wire_compatible!(v67::GlobalId with v68::GlobalId);
16-
wire_compatible!(v67::CatalogItem with v68::CatalogItem);
17-
wire_compatible!(v67::SchemaId with v68::SchemaId);
18-
wire_compatible!(v67::CommentValue with v68::CommentValue);
19-
wire_compatible!(v67::RoleId with v68::RoleId);
20-
wire_compatible!(v67::MzAclItem with v68::MzAclItem);
21-
wire_compatible!(v67::DatabaseId with v68::DatabaseId);
22-
wire_compatible!(v67::ResolvedSchema with v68::ResolvedSchema);
23-
wire_compatible!(v67::ClusterId with v68::ClusterId);
24-
wire_compatible!(v67::ClusterReplicaId with v68::ClusterReplicaId);
25-
wire_compatible!(v67::SourceReferencesValue with v68::SourceReferencesValue);
26-
wire_compatible!(v67::GidMappingKey with v68::GidMappingKey);
27-
wire_compatible!(v67::ClusterIntrospectionSourceIndexKey with v68::ClusterIntrospectionSourceIndexKey);
15+
json_compatible!(v67::GlobalId with v68::GlobalId);
16+
json_compatible!(v67::CatalogItem with v68::CatalogItem);
17+
json_compatible!(v67::SchemaId with v68::SchemaId);
18+
json_compatible!(v67::CommentValue with v68::CommentValue);
19+
json_compatible!(v67::RoleId with v68::RoleId);
20+
json_compatible!(v67::MzAclItem with v68::MzAclItem);
21+
json_compatible!(v67::DatabaseId with v68::DatabaseId);
22+
json_compatible!(v67::ResolvedSchema with v68::ResolvedSchema);
23+
json_compatible!(v67::ClusterId with v68::ClusterId);
24+
json_compatible!(v67::ClusterReplicaId with v68::ClusterReplicaId);
25+
json_compatible!(v67::SourceReferencesValue with v68::SourceReferencesValue);
26+
json_compatible!(v67::GidMappingKey with v68::GidMappingKey);
27+
json_compatible!(v67::ClusterIntrospectionSourceIndexKey with v68::ClusterIntrospectionSourceIndexKey);
2828

2929
/// In v68 we switched catalog items to be keyed on a `CatalogItemId`, this required a few changes:
3030
///
@@ -278,7 +278,7 @@ impl UpgradeFrom<v67::state_update_kind::SourceReferences>
278278
fn upgrade_from(old: v67::state_update_kind::SourceReferences) -> Self {
279279
v68::state_update_kind::SourceReferences {
280280
key: old.key.map(|old| old.upgrade_into()),
281-
value: old.value.map(|old| WireCompatible::convert(&old)),
281+
value: old.value.map(|old| JsonCompatible::convert(&old)),
282282
}
283283
}
284284
}

src/catalog/src/durable/upgrade/v73_to_v74.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
use crate::durable::traits::UpgradeFrom;
1111
use crate::durable::upgrade::MigrationAction;
1212
use crate::durable::upgrade::{objects_v73 as v73, objects_v74 as v74};
13-
use crate::wire_compatible;
13+
use crate::json_compatible;
1414

15-
wire_compatible!(v73::RoleKey with v74::RoleKey);
15+
json_compatible!(v73::RoleKey with v74::RoleKey);
1616

1717
/// in v74, we add attributes to RoleAttribute.
1818
pub fn upgrade(

src/catalog/src/durable/upgrade/v74_to_v75.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
use crate::durable::traits::{UpgradeFrom, UpgradeInto};
1111
use crate::durable::upgrade::MigrationAction;
12-
use crate::durable::upgrade::wire_compatible::{WireCompatible, wire_compatible};
12+
use crate::durable::upgrade::wire_compatible::{JsonCompatible, json_compatible};
1313
use crate::durable::upgrade::{objects_v74 as v74, objects_v75 as v75};
1414

15-
wire_compatible!(v74::ClusterReplicaKey with v75::ClusterReplicaKey);
16-
wire_compatible!(v74::ClusterId with v75::ClusterId);
17-
wire_compatible!(v74::RoleId with v75::RoleId);
18-
wire_compatible!(v74::ReplicaLogging with v75::ReplicaLogging);
19-
wire_compatible!(v74::replica_config::ManagedLocation with v75::replica_config::ManagedLocation);
15+
json_compatible!(v74::ClusterReplicaKey with v75::ClusterReplicaKey);
16+
json_compatible!(v74::ClusterId with v75::ClusterId);
17+
json_compatible!(v74::RoleId with v75::RoleId);
18+
json_compatible!(v74::ReplicaLogging with v75::ReplicaLogging);
19+
json_compatible!(v74::replica_config::ManagedLocation with v75::replica_config::ManagedLocation);
2020

2121
/// Removes some options from unmanaged (unorchestrated?) replica configs.
2222
pub fn upgrade(
@@ -49,7 +49,7 @@ impl UpgradeFrom<v74::state_update_kind::ClusterReplica>
4949
{
5050
fn upgrade_from(old: v74::state_update_kind::ClusterReplica) -> Self {
5151
v75::state_update_kind::ClusterReplica {
52-
key: old.key.as_ref().map(WireCompatible::convert),
52+
key: old.key.as_ref().map(JsonCompatible::convert),
5353
value: old.value.map(UpgradeFrom::upgrade_from),
5454
}
5555
}
@@ -58,18 +58,18 @@ impl UpgradeFrom<v74::state_update_kind::ClusterReplica>
5858
impl UpgradeFrom<v74::ClusterReplicaValue> for v75::ClusterReplicaValue {
5959
fn upgrade_from(old: v74::ClusterReplicaValue) -> Self {
6060
v75::ClusterReplicaValue {
61-
cluster_id: old.cluster_id.as_ref().map(WireCompatible::convert),
61+
cluster_id: old.cluster_id.as_ref().map(JsonCompatible::convert),
6262
name: old.name,
6363
config: old.config.map(UpgradeFrom::upgrade_from),
64-
owner_id: old.owner_id.as_ref().map(WireCompatible::convert),
64+
owner_id: old.owner_id.as_ref().map(JsonCompatible::convert),
6565
}
6666
}
6767
}
6868

6969
impl UpgradeFrom<v74::ReplicaConfig> for v75::ReplicaConfig {
7070
fn upgrade_from(old: v74::ReplicaConfig) -> Self {
7171
v75::ReplicaConfig {
72-
logging: old.logging.as_ref().map(WireCompatible::convert),
72+
logging: old.logging.as_ref().map(JsonCompatible::convert),
7373
location: old.location.map(UpgradeFrom::upgrade_from),
7474
}
7575
}
@@ -82,7 +82,7 @@ impl UpgradeFrom<v74::replica_config::Location> for v75::replica_config::Locatio
8282
v75::replica_config::Location::Unmanaged(loc.upgrade_into())
8383
}
8484
v74::replica_config::Location::Managed(loc) => {
85-
v75::replica_config::Location::Managed(WireCompatible::convert(&loc))
85+
v75::replica_config::Location::Managed(JsonCompatible::convert(&loc))
8686
}
8787
}
8888
}

src/catalog/src/durable/upgrade/v75_to_v76.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99

1010
use crate::durable::traits::{UpgradeFrom, UpgradeInto};
1111
use crate::durable::upgrade::MigrationAction;
12-
use crate::durable::upgrade::wire_compatible::{WireCompatible, wire_compatible};
12+
use crate::durable::upgrade::wire_compatible::{JsonCompatible, json_compatible};
1313
use crate::durable::upgrade::{objects_v75 as v75, objects_v76 as v76};
1414

15-
wire_compatible!(v75::ClusterKey with v76::ClusterKey);
16-
wire_compatible!(v75::ClusterReplicaKey with v76::ClusterReplicaKey);
17-
wire_compatible!(v75::ClusterId with v76::ClusterId);
18-
wire_compatible!(v75::RoleId with v76::RoleId);
19-
wire_compatible!(v75::MzAclItem with v76::MzAclItem);
20-
wire_compatible!(v75::ReplicaLogging with v76::ReplicaLogging);
21-
wire_compatible!(v75::replica_config::UnmanagedLocation with v76::replica_config::UnmanagedLocation);
22-
wire_compatible!(v75::OptimizerFeatureOverride with v76::OptimizerFeatureOverride);
23-
wire_compatible!(v75::ClusterSchedule with v76::ClusterSchedule);
15+
json_compatible!(v75::ClusterKey with v76::ClusterKey);
16+
json_compatible!(v75::ClusterReplicaKey with v76::ClusterReplicaKey);
17+
json_compatible!(v75::ClusterId with v76::ClusterId);
18+
json_compatible!(v75::RoleId with v76::RoleId);
19+
json_compatible!(v75::MzAclItem with v76::MzAclItem);
20+
json_compatible!(v75::ReplicaLogging with v76::ReplicaLogging);
21+
json_compatible!(v75::replica_config::UnmanagedLocation with v76::replica_config::UnmanagedLocation);
22+
json_compatible!(v75::OptimizerFeatureOverride with v76::OptimizerFeatureOverride);
23+
json_compatible!(v75::ClusterSchedule with v76::ClusterSchedule);
2424

2525
/// Removes the `disk` flag from managed cluster and replica configs.
2626
pub fn upgrade(
@@ -64,7 +64,7 @@ pub fn upgrade(
6464
impl UpgradeFrom<v75::state_update_kind::Cluster> for v76::state_update_kind::Cluster {
6565
fn upgrade_from(old: v75::state_update_kind::Cluster) -> Self {
6666
v76::state_update_kind::Cluster {
67-
key: old.key.as_ref().map(WireCompatible::convert),
67+
key: old.key.as_ref().map(JsonCompatible::convert),
6868
value: old.value.map(UpgradeFrom::upgrade_from),
6969
}
7070
}
@@ -74,8 +74,8 @@ impl UpgradeFrom<v75::ClusterValue> for v76::ClusterValue {
7474
fn upgrade_from(old: v75::ClusterValue) -> Self {
7575
v76::ClusterValue {
7676
name: old.name,
77-
owner_id: old.owner_id.as_ref().map(WireCompatible::convert),
78-
privileges: old.privileges.iter().map(WireCompatible::convert).collect(),
77+
owner_id: old.owner_id.as_ref().map(JsonCompatible::convert),
78+
privileges: old.privileges.iter().map(JsonCompatible::convert).collect(),
7979
config: old.config.map(UpgradeFrom::upgrade_from),
8080
}
8181
}
@@ -109,13 +109,13 @@ impl UpgradeFrom<v75::cluster_config::ManagedCluster> for v76::cluster_config::M
109109
size: loc.size,
110110
replication_factor: loc.replication_factor,
111111
availability_zones: loc.availability_zones,
112-
logging: loc.logging.as_ref().map(WireCompatible::convert),
112+
logging: loc.logging.as_ref().map(JsonCompatible::convert),
113113
optimizer_feature_overrides: loc
114114
.optimizer_feature_overrides
115115
.iter()
116-
.map(WireCompatible::convert)
116+
.map(JsonCompatible::convert)
117117
.collect(),
118-
schedule: loc.schedule.as_ref().map(WireCompatible::convert),
118+
schedule: loc.schedule.as_ref().map(JsonCompatible::convert),
119119
}
120120
}
121121
}
@@ -125,7 +125,7 @@ impl UpgradeFrom<v75::state_update_kind::ClusterReplica>
125125
{
126126
fn upgrade_from(old: v75::state_update_kind::ClusterReplica) -> Self {
127127
v76::state_update_kind::ClusterReplica {
128-
key: old.key.as_ref().map(WireCompatible::convert),
128+
key: old.key.as_ref().map(JsonCompatible::convert),
129129
value: old.value.map(UpgradeFrom::upgrade_from),
130130
}
131131
}
@@ -134,18 +134,18 @@ impl UpgradeFrom<v75::state_update_kind::ClusterReplica>
134134
impl UpgradeFrom<v75::ClusterReplicaValue> for v76::ClusterReplicaValue {
135135
fn upgrade_from(old: v75::ClusterReplicaValue) -> Self {
136136
v76::ClusterReplicaValue {
137-
cluster_id: old.cluster_id.as_ref().map(WireCompatible::convert),
137+
cluster_id: old.cluster_id.as_ref().map(JsonCompatible::convert),
138138
name: old.name,
139139
config: old.config.map(UpgradeFrom::upgrade_from),
140-
owner_id: old.owner_id.as_ref().map(WireCompatible::convert),
140+
owner_id: old.owner_id.as_ref().map(JsonCompatible::convert),
141141
}
142142
}
143143
}
144144

145145
impl UpgradeFrom<v75::ReplicaConfig> for v76::ReplicaConfig {
146146
fn upgrade_from(old: v75::ReplicaConfig) -> Self {
147147
v76::ReplicaConfig {
148-
logging: old.logging.as_ref().map(WireCompatible::convert),
148+
logging: old.logging.as_ref().map(JsonCompatible::convert),
149149
location: old.location.map(UpgradeFrom::upgrade_from),
150150
}
151151
}
@@ -155,7 +155,7 @@ impl UpgradeFrom<v75::replica_config::Location> for v76::replica_config::Locatio
155155
fn upgrade_from(old: v75::replica_config::Location) -> Self {
156156
match old {
157157
v75::replica_config::Location::Unmanaged(loc) => {
158-
v76::replica_config::Location::Unmanaged(WireCompatible::convert(&loc))
158+
v76::replica_config::Location::Unmanaged(JsonCompatible::convert(&loc))
159159
}
160160
v75::replica_config::Location::Managed(loc) => {
161161
v76::replica_config::Location::Managed(loc.upgrade_into())

src/catalog/src/durable/upgrade/wire_compatible.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
use serde::Serialize;
1111
use serde::de::DeserializeOwned;
1212

13-
/// Denotes that `Self` is wire compatible with type `T`.
13+
/// Denotes that `Self` is JSON compatible with type `T`.
1414
///
15-
/// You should not implement this yourself, instead use the `wire_compatible!` macro.
16-
pub unsafe trait WireCompatible<T>: Serialize + DeserializeOwned
15+
/// You should not implement this yourself, instead use the `json_compatible!` macro.
16+
pub unsafe trait JsonCompatible<T>: Serialize + DeserializeOwned
1717
where
1818
T: Serialize + DeserializeOwned,
1919
{
@@ -24,25 +24,25 @@ where
2424
}
2525
}
2626

27-
// SAFETY: A message type is trivially wire compatible with itself.
28-
unsafe impl<T: Serialize + DeserializeOwned + Clone> WireCompatible<T> for T {
27+
// SAFETY: A type is trivially JSON compatible with itself.
28+
unsafe impl<T: Serialize + DeserializeOwned + Clone> JsonCompatible<T> for T {
2929
fn convert(old: &Self) -> Self {
3030
old.clone()
3131
}
3232
}
3333

34-
/// Defines one protobuf type as wire compatible with another.
34+
/// Defines one type as JSON compatible with another.
3535
///
3636
/// ```text
37-
/// wire_compatible!(objects_v28::DatabaseKey with objects_v27::DatabaseKey);
37+
/// json_compatible!(objects_v28::DatabaseKey with objects_v27::DatabaseKey);
3838
/// ```
3939
///
40-
/// Internally this will implement the `WireCompatible<B> for <A>`, e.g.
41-
/// `WireCompatible<objects_v27::DatabaseKey> for objects_v28::DatabaseKey` and generate `proptest`
40+
/// Internally this will implement `JsonCompatible<B> for <A>`, e.g.
41+
/// `JsonCompatible<objects_v27::DatabaseKey> for objects_v28::DatabaseKey` and generate `proptest`
4242
/// cases that will create arbitrary objects of type `B` and assert they can be deserialized with
4343
/// type `A`, and vice versa.
4444
#[macro_export]
45-
macro_rules! wire_compatible {
45+
macro_rules! json_compatible {
4646
($a:ident $(:: $a_sub:ident)* with $b:ident $(:: $b_sub:ident)*) => {
4747
::static_assertions::assert_impl_all!(
4848
$a $(::$a_sub)* : ::proptest::arbitrary::Arbitrary, ::serde::Serialize, ::serde::de::DeserializeOwned,
@@ -51,10 +51,10 @@ macro_rules! wire_compatible {
5151
$b $(::$b_sub)* : ::proptest::arbitrary::Arbitrary, ::serde::Serialize, ::serde::de::DeserializeOwned,
5252
);
5353

54-
// SAFETY: Below we assert that these types are wire compatible by generating arbitrary
54+
// SAFETY: Below we assert that these types are JSON compatible by generating arbitrary
5555
// structs, encoding in one, and then decoding in the other.
56-
unsafe impl $crate::durable::upgrade::wire_compatible::WireCompatible< $b $(::$b_sub)* > for $a $(::$a_sub)* {}
57-
unsafe impl $crate::durable::upgrade::wire_compatible::WireCompatible< $a $(::$a_sub)* > for $b $(::$b_sub)* {}
56+
unsafe impl $crate::durable::upgrade::wire_compatible::JsonCompatible< $b $(::$b_sub)* > for $a $(::$a_sub)* {}
57+
unsafe impl $crate::durable::upgrade::wire_compatible::JsonCompatible< $a $(::$a_sub)* > for $b $(::$b_sub)* {}
5858

5959
::paste::paste! {
6060
::proptest::proptest! {
@@ -65,14 +65,14 @@ macro_rules! wire_compatible {
6565

6666
#[mz_ore::test]
6767
#[cfg_attr(miri, ignore)] // slow
68-
fn [<proptest_wire_compat_ $a:snake $(_$a_sub:snake)* _to_ $b:snake $(_$b_sub:snake)* >](a: $a $(::$a_sub)* ) {
68+
fn [<proptest_json_compat_ $a:snake $(_$a_sub:snake)* _to_ $b:snake $(_$b_sub:snake)* >](a: $a $(::$a_sub)* ) {
6969
let a_bytes = ::serde_json::to_vec(&a).expect("JSON serializable");
7070
let b_decoded = ::serde_json::from_slice::<$b $(::$b_sub)*>(&a_bytes);
7171
::proptest::prelude::prop_assert!(b_decoded.is_ok());
7272

7373
// Maybe superfluous, but this is a method called in production.
7474
let b_decoded = b_decoded.expect("asserted Ok");
75-
let b_converted: $b $(::$b_sub)* = $crate::durable::upgrade::wire_compatible::WireCompatible::convert(&a);
75+
let b_converted: $b $(::$b_sub)* = $crate::durable::upgrade::wire_compatible::JsonCompatible::convert(&a);
7676
assert_eq!(b_decoded, b_converted);
7777

7878
let b_bytes = ::serde_json::to_vec(&b_decoded).expect("JSON serializable");
@@ -81,14 +81,14 @@ macro_rules! wire_compatible {
8181

8282
#[mz_ore::test]
8383
#[cfg_attr(miri, ignore)] // slow
84-
fn [<proptest_wire_compat_ $b:snake $(_$b_sub:snake)* _to_ $a:snake $(_$a_sub:snake)* >](b: $b $(::$b_sub)* ) {
84+
fn [<proptest_json_compat_ $b:snake $(_$b_sub:snake)* _to_ $a:snake $(_$a_sub:snake)* >](b: $b $(::$b_sub)* ) {
8585
let b_bytes = ::serde_json::to_vec(&b).expect("JSON serializable");
8686
let a_decoded = ::serde_json::from_slice::<$a $(::$a_sub)*>(&b_bytes);
8787
::proptest::prelude::prop_assert!(a_decoded.is_ok());
8888

8989
// Maybe superfluous, but this is a method called in production.
9090
let a_decoded = a_decoded.expect("asserted Ok");
91-
let a_converted: $a $(::$a_sub)* = $crate::durable::upgrade::wire_compatible::WireCompatible::convert(&b);
91+
let a_converted: $a $(::$a_sub)* = $crate::durable::upgrade::wire_compatible::JsonCompatible::convert(&b);
9292
assert_eq!(a_decoded, a_converted);
9393

9494
let a_bytes = ::serde_json::to_vec(&a_decoded).expect("JSON serializable");
@@ -98,4 +98,4 @@ macro_rules! wire_compatible {
9898
}
9999
};
100100
}
101-
pub use wire_compatible;
101+
pub use json_compatible;

0 commit comments

Comments
 (0)