Skip to content

Commit

Permalink
Validate method now always has decoded types available
Browse files Browse the repository at this point in the history
  • Loading branch information
bkirwi committed Jan 17, 2025
1 parent be25fac commit e5863ba
Showing 1 changed file with 5 additions and 25 deletions.
30 changes: 5 additions & 25 deletions src/persist-client/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,13 +688,7 @@ where
.codecs
.val
.encode(|| V::encode(val, &mut self.val_buf));
validate_schema(
&self.builder.write_schemas,
&self.key_buf,
&self.val_buf,
Some(key),
Some(val),
);
validate_schema(&self.builder.write_schemas, key, val);

let update = (
(self.key_buf.as_slice(), self.val_buf.as_slice()),
Expand Down Expand Up @@ -881,32 +875,18 @@ where
// inline it at the two callers.
pub(crate) fn validate_schema<K: Codec, V: Codec>(
stats_schemas: &Schemas<K, V>,
key: &[u8],
val: &[u8],
decoded_key: Option<&K>,
decoded_val: Option<&V>,
decoded_key: &K,
decoded_val: &V,
) {
// Attempt to catch any bad schema usage in CI. This is probably too
// expensive to run in prod.
if !mz_ore::assert::SOFT_ASSERTIONS.load(Ordering::Relaxed) {
return;
}
let key_valid = match decoded_key {
Some(key) => K::validate(key, &stats_schemas.key),
None => {
let key = K::decode(key, &stats_schemas.key).expect("valid encoded key");
K::validate(&key, &stats_schemas.key)
}
};
let key_valid = K::validate(decoded_key, &stats_schemas.key);
let () = key_valid
.unwrap_or_else(|err| panic!("constructing batch with mismatched key schema: {}", err));
let val_valid = match decoded_val {
Some(val) => V::validate(val, &stats_schemas.val),
None => {
let val = V::decode(val, &stats_schemas.val).expect("valid encoded val");
V::validate(&val, &stats_schemas.val)
}
};
let val_valid = V::validate(decoded_val, &stats_schemas.val);
let () = val_valid
.unwrap_or_else(|err| panic!("constructing batch with mismatched val schema: {}", err));
}
Expand Down

0 comments on commit e5863ba

Please sign in to comment.