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
Feat: Make the encoding format forward and backward compatible #329
Conversation
and refine Awareness type in ts
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@zxch3n This is a proposal for the forward and backward compatibility of encoding formats. Can we add automated testing for this feature? |
I'm not sure how to test it properly. Maybe we can use a new test-only cargo feature to simulate a new version of Loro and test it in another crate |
I added It can cover:
|
cfa5578
to
0f0ba33
Compare
Background
We may add other
ContainerType
in the future.If developers need to ensure that all users have upgraded to the new version before they can enable the capabilities provided by future versions of Loro, this will be harmful to the developer experience.
The only thing holding back upgrades is the forward and backward compatibility of encoding formats.
Details
Loro has
updates
andsnapshot
two encoding formats. These two ways all need to encodearena
,ops
, andchanges
:Arena
The arena is a better way to take advantage of
columnar
because there is a large amount of identical or incremental metadata. All arenas are in the last chunk in encoding format and encoded to&[u8]
. Its compatibility depends on loro-dev/columnar#28.Ops
Encoding and decoding ops are the most difficult part. We should parse
ContainerType
,ContainerID
, and theValue
/Prop
of Op.ContainerType
ContainerType::Unkown
type withu8
. We can infer the realContainerType
when the new version decodes an unknown type.ContainerID & ContainerIdx
Container
of typeunknown
will be registered inLoro arena
, so they do have a correspondingContainerIdx
.I use the first bit to infer the
ContainerIdx
whether is unknown, and 4 bits forContainerType
and 27 bits forindex
.Value
ValueKind::Unknown(u8)
. For now, the unknown kind starts with1
at the first bit, and 7 bits of the realValueKind
.FutureValue
and an unknownFutureValue::Unkown{kind: u8, prop: i32, data: &[u8]}
. Only we encode the future value, the length of bytes need to be encoded first. The newer value type will always be FutureValue.InnerContent::Future(FutureInnerContent)
, andFutureInnerContent::Unknown{prop: i32, value: OwnedValue}
. The content of unknown op will be degenerate to Unknown holding the decoded value. When encoding, we can process any content according to unified logic.arena
.prop
should not depend onarena
.