Is safe to rename a field in Thrift IDL?

。_饼干妹妹 提交于 2021-01-29 09:18:16

问题


Is it safe to deprecate a field in Thrift by renaming if the field is no longer used by clients? My understanding is this should work as long as we don't change the type. For example

From

struct FooResponse {
  1: optional i32 foo
}

To

struct FooResponse {
  1: optional i32 fooDeprecated
}

回答1:


Yes it is 100% safe. Thrift only deals with field IDs internally. The names of a struct as well as method argument names are used to generate field names in the generated code only. They do not even go over the wire.

Furthermore, it is a recommended way to deprecate fields. Even in the case where a field is fully retired, one should comment it out but leave it in the IDL to prevent the numeric field ID from being accidentally reused.

The only place where names are used as names is with service method calls. Methods do not have numeric identifiers, in that case the name is used. Changing the name actually declares a new method.

TL;DR

From a technically perspective

  • All names in Thrift IDL may be changed as needed, except ...
  • Method names may not be changed (unless you know what you are doing)

With regard to compatibility on the code level, any consumer of your API will highly value it, if you stay away from changing field names too often.

See also

A good read on the topic is Diwaker Gupta's "Missing Guide". It also elaborates on the pros and cons of optional and required which also should be considered before you retire fields - you may end up with broken IDL compatibility otherwise.



来源:https://stackoverflow.com/questions/52882370/is-safe-to-rename-a-field-in-thrift-idl

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