乐闻世界logo
搜索文章和话题

What is the purpose of Thrift parameter numbering?

1个答案

1

In Thrift, the primary purpose of parameter numbering is to ensure cross-version compatibility. Each field or parameter is assigned a unique number, allowing both parties to correctly identify and process these fields even if certain fields are added, removed, or modified in subsequent protocol versions.

For example, consider the following Thrift service definition:

thrift
struct Employee { 1: string name; 2: int32 age; 3: string position; }

In this struct, the name field is assigned number 1, the age field is assigned number 2, and the position field is assigned number 3. If, in a future version, we decide to remove the position field and add a new email field, the new definition might look like this:

thrift
struct Employee { 1: string name; 2: int32 age; 4: string email; }

Here, the email field is assigned a new number 4. Even though the position field is removed, numbers 1 and 2 remain unchanged, meaning that older versions of clients and servers can still correctly parse the name and age fields, ensuring backward compatibility.

In this way, Thrift allows service interfaces to be iteratively updated without disrupting communication between existing clients and servers. This is particularly important for large, distributed systems where components may not be able to update simultaneously.

2024年8月8日 13:43 回复

你的答案