Microsoft Bond schema evolution best practices

廉价感情. 提交于 2019-12-02 02:04:36

问题


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:

  1. 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?
  2. adding a new "required" field requires you give the field a default value
  3. removing a field in a newer version is okay, provided older versions had a default value assigned
  4. 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)?
  5. 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:

  1. Yes, names of fields can change, all that matters for the CompactBinary format is the field ordinal.
  2. 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.
  3. 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).
  4. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!