问题
Does Microsoft Bond have some best practices on how schemas evolve over time? I want to make certain we follow best practices such that we have 2 way compatibility (i.e. allowing our Bond types to evolve older versions to the current version, as well as backward compatibility allowing conversion from a newer version back to an older version). I don't see this addressed specifically in the documentation (e.g. https://microsoft.github.io/bond/manual/bond_cs.html nor https://microsoft.github.io/bond/manual/compiler.html#idl-syntax ), though other serialization frameworks such as Avro have this explicitly detailed in their documentation.
For what it's worth, we are writing in .NET (C#/F#) and intend to use the CompactBinaryWriter and CompactBinaryReader formats initially.
For example, I imagine some guidance along these lines:
- names of fields can change over time since the field ordinals are used for field resolution, not the names directly (except in SimpleJSON). I believe this true, is it?
- adding a new "required" field requires you give the field a default value
- removing a field in a newer version is okay, provided older versions had a default value assigned
- what about changing the type of a field? For example, can a field change from an string field in version 1 to a int64 in version 2? Can it change from a string to a custom union (custom type with optional fields)?
- any other recommendations?
Thank you!
would also be interested if there is any active forum community for this type of Microsoft Bond question, i wasn't able to find one...
回答1:
The Bond schema evolution rules and best practices can now be found here: https://microsoft.github.io/bond/manual/bond_cpp.html#schema-evolution https://microsoft.github.io/bond/manual/bond_cs.html#schema-evolution
回答2:
I am not aware of any explicit schema evolution guidelines either, that's certainly a gap in the Bond documentation. From my own work with Bond, I can answer some of your questions:
- Yes, names of fields can change, all that matters for the
CompactBinary
format is the field ordinal. - The
DefaultAttribute
is only valid on interface members. You can add required fields without further annotations, but upon deserialization of old records (that do not contain that required field), I expect a runtime error. - You can remove fields. Default values are determined by instantiating the containing object via its default constructors, and reading out the respective field. However, if you remove a required field, the old reader would fail to deserialize it (the new reader would not have included it at all).
- That's a big no no. If you need to change the type of a field, leave the old field in place, (give it a suffix like
_Obsolete
if desired) and introduce a new field of the "correct" type.
For what it's worth: You write that you are using F#, some F# specific changes are in the making, see here. This will support records, unions, and core F# data types.
Update: There is now a section on schema evolution in the Bond documentation.
来源:https://stackoverflow.com/questions/41860787/microsoft-bond-schema-evolution-best-practices