在 Thrift IDL 中重命名字段是否安全? [英] Is safe to rename a field in Thrift IDL?

查看:49
本文介绍了在 Thrift IDL 中重命名字段是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果客户不再使用字段,则通过重命名来弃用 Thrift 中的字段是否安全?我的理解是,只要我们不更改类型,这应该有效.例如

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

来自

struct FooResponse {
  1: optional i32 foo
}

struct FooResponse {
  1: optional i32 fooDeprecated
}

推荐答案

是的,它 100% 安全.Thrift 仅在内部处理字段 ID.结构名称和方法参数名称仅用于在生成的代码中生成字段名称.他们甚至没有越过电线.

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.

此外,这是弃用字段的推荐方法.即使在某个字段完全停用的情况下,也应该将其注释掉,但将其保留在 IDL 中,以防止数字字段 ID 被意外重用.

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.

从技术角度来看

  • Thrift IDL 中的所有名称都可以根据需要更改,除了 ...
  • 方法名称不得更改(除非您知道自己在做什么)

关于代码级别的兼容性,如果您避免过于频繁地更改字段名称,那么您的 API 的任何使用者都会高度重视它.

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.

有关该主题的好读物是 Diwaker Gupta 的缺失指南".它还详细说明了 optionalrequired 的优缺点,在您停用字段之前也应考虑这些优点和缺点 - 否则您可能会破坏 IDL 兼容性.

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.

这篇关于在 Thrift IDL 中重命名字段是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆