Raft论文翻译(8)——客户端

        This section describes how clients interact with Raft, including how clients find the cluster leader and how Raft supports linearizable semantics [10]. These issues apply to all consensus-based systems, and Raft’s solutions are similar to other systems.

8 客户端交互

        本节介绍客户端如何和 Raft 进行交互,包括客户端如何找到 leader 和 Raft 是如何支持线性化语义的。这些问题对于所有基于一致性的系统都存在,并且 Raft 的解决方案和其他的也差不多。

        Clients of Raft send all of their requests to the leader. When a client first starts up, it connects to a randomly- chosen server. If the client’s first choice is not the leader, that server will reject the client’s request and supply in- formation about the most recent leader it has heard from (AppendEntries requests include the network address of the leader). If the leader crashes, client requests will time out; clients then try again with randomly-chosen servers.

        Raft 的客户端发送所有的请求给 leader 。当客户端第一次启动的时候,它会随机挑选一个服务器进行通信。如果客户端第一次挑选的服务器不是 leader ,那么该服务器会拒绝客户端的请求并且提供关于它最近接收到的领导人的信息(AppendEntries 请求包含了 leader 的网络地址)。如果 leader 已经崩溃了,客户端请求就会超时;客户端之后会再次随机挑选服务器进行重试。


        Our goal for Raft is to implement linearizable seman- tics (each operation appears to execute instantaneously, exactly once, at some point between its invocation and its response). However, as described so far Raft can exe- cute a command multiple times: for example, if the leader crashes after committing the log entry but before respond- ing to the client, the client will retry the command with a new leader, causing it to be executed a second time. The solution is for clients to assign unique serial numbers to every command. Then, the state machine tracks the latest serial number processed for each client, along with the as- sociated response. If it receives a command whose serial number has already been executed, it responds immedi- ately without re-executing the request.

        我们 Raft 的目标是要实现线性化语义(每一次操作立即执行,只执行一次,在它的调用和回复之间)。但是,如上述,Raft 可能执行同一条命令多次:例如,如果 leader 在提交了该日志条目之后,响应客户端之前崩溃了,那么客户端会和新的 leader 重试这条指令,导致这条命令被再次执行。解决方案就是客户端对于每一条指令都赋予一个唯一的序列号。然后,状态机跟踪每个客户端已经处理的最新的序列号以及相关联的回复。如果接收到一条指令,该指令的序列号已经被执行过了,就立即返回结果,而不重新执行该请求。


        Read-only operations can be handled without writing anything into the log. However, with no additional mea- sures, this would run the risk of returning stale data, since the leader responding to the request might have been su- perseded by a newer leader of which it is unaware. Lin- earizable reads must not return stale data, and Raft needs two extra precautions to guarantee this without using the log. First, a leader must have the latest information on which entries are committed. The Leader Completeness Property guarantees that a leader has all committed en- tries, but at the start of its term, it may not know which those are. To find out, it needs to commit an entry from its term. Raft handles this by having each leader com- mit a blank no-op entry into the log at the start of its term. Second, a leader must check whether it has been de- posed before processing a read-only request (its informa- tion may be stale if a more recent leader has been elected). Raft handles this by having the leader exchange heart- beat messages with a majority of the cluster before re- sponding to read-only requests. Alternatively, the leader could rely on the heartbeat mechanism to provide a form of lease [9], but this would rely on timing for safety (it assumes bounded clock skew).

        只读的操作可以直接处理而不需要记录日志。但是,如果不采取任何其他措施,这么做可能会有返回过时数据(stale data)的风险,因为 leader 响应客户端请求时可能已经被新的 leader 替代了,但是它还不知道自己已经不是最新的 leader 了。线性化的读操作肯定不会返回过时数据,Raft 需要使用两个额外的预防措施来在不使用日志的情况下保证这一点。首先,leader 必须有关于哪些日志条目被提交了的最新信息。Leader 完整性特性保证了 leader 一定拥有所有已经被提交的日志条目,但是在它任期开始的时候,它可能不知道哪些是已经被提交的。为了知道这些信息,它需要在它的任期里提交一个日志条目。Raft 通过让 leader 在任期开始的时候提交一个空的没有任何操作的日志条目到日志中来处理该问题。第二,leader 在处理只读请求之前必须检查自己是否已经被替代了(如果一个更新的 leader 被选举出来了,它的信息就是过时的了)。Raft 通过让 leader 在响应只读请求之前,先和集群中的过半节点交换一次心跳信息来处理该问题。另一种可选的方案,leader 可以依赖心跳机制来实现一种租约的形式,但是这种方法依赖 timing 来保证安全性(假设时间误差是有界的)。

leader应用了之后就可以返回给客户端了

Raft算法之客户端交互篇 - 云+社区 - 腾讯云

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值