-
Notifications
You must be signed in to change notification settings - Fork 485
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
LSN and ids Serialize
impls force unnecessary copy-paste
#3511
Comments
AFAIK, this was the issue last time I've tried to implement this: I failed to distinguish "bytes of a json string" from "bytes of a bincode serialization", causing obscure bugs in tests. |
There is |
Marking this as good_first_issue. First thing which needs to be done here is to add image tests for both bincode OR serde-json serialized types which have LSN, TenantId, OR TimelineId within them. Tests should be something like: #[test]
fn ensure_type_roundtrips() {
let val = /* creation omitted */;
let expected = b"...."; // for serde-json
let expected = [...] or hex; // for bincode, whichever you find more aesthetic
assert_eq!(&serialize(&val), &expected);
assert_eq!(deserialize(&expected).unwrap(), val);
} After that in the Serialize implementation my plan was to use https://docs.rs/serde/latest/serde/trait.Serializer.html#method.is_human_readable to query which kind of serializer it is, and in the I haven't yet implemented this so there might be some issues, but after adding the tests and making the modifications to the serialize and deserialize impls, it would be safe to start removing the copypaste, and tests should tell us if the idea was good. Suggest starting out with one type of each serialization. Lsn within bincode is most likely just a |
Alternatively a new test type with all (Lsn, TenantId, TimelineId) could be created as two variants, one for bincode and other for serde_json. Then tests could be created for that type and the different formats roundtripping. However, it would still be better to find the two examples and show that the really used serialization format does not change. We only have "image based" testing for |
I would like to take this issue! @koivunej |
…melineId` ...) (#5335) Improve the serde impl for several types (`Lsn`, `TenantId`, `TimelineId`) by making them sensitive to `Serializer::is_human_readadable` (true for json, false for bincode). Fixes #3511 by: - Implement the custom serde for `Lsn` - Implement the custom serde for `Id` - Add the helper module `serde_as_u64` in `libs/utils/src/lsn.rs` - Remove the unnecessary attr `#[serde_as(as = "DisplayFromStr")]` in all possible structs Additionally some safekeeper types gained serde tests. --------- Co-authored-by: Joonas Koivunen <joonas@neon.tech>
Repeated:
This could be just:
If we'd query the serializer for https://docs.rs/serde/latest/serde/trait.Serializer.html#method.is_human_readable in the
serde::Serialize
impl for LSN, id and then decide to use stringified (for json) or u64 (for bincode).This has been a bigger issue with ids by default serializing to array of bytes.
Deserialize impls should handle strings and u64 or string and array of bytes (haven't checked if they already do).
(I haven't yet implemented this so there might be some issues.)
The text was updated successfully, but these errors were encountered: