我看过动物园管理员的源代码,它在集群里有很奇怪的操作。我们都知道,当写入动物园管理员集群节点时,流程步骤如下:
问题在于步骤2,当跟随者收到建议请求时,requst被同步到zk日志(请参阅列表代码),提交请求只写入内存。但是在同步到磁盘时间之前和之后,重新启动所有节点,未实现的请求是最新的请求吗?
// the follower receive the proposal request method , forword to syncProcessor
public void FollowerZooKeeperServer#logRequest(TxnHeader hdr, Record txn) {
Request request = new Request(null, hdr.getClientId(), hdr.getCxid(),
hdr.getType(), null, null);
request.hdr = hdr;
request.txn = txn;
request.zxid = hdr.getZxid();
if ((request.zxid & 0xffffffffL) != 0) {
pendingTxns.add(request);
}
syncProcessor.processRequest(request);
}
// the SyncRequestProcessor operation , after tx log commit to disk , it response the ack request. Was it ok ?
private void flush(LinkedList<Request> toFlush)
throws IOException, RequestProcessorException
{
if (toFlush.isEmpty())
return;
zks.getZKDatabase().commit();
while (!toFlush.isEmpty()) {
Request i = toFlush.remove();
if (nextProcessor != null) {
nextProcessor.processRequest(i);
}
}
if (nextProcessor != null && nextProcessor instanceof Flushable) {
((Flushable)nextProcessor).flush();
}
}发布于 2018-10-12 17:44:58
答案是肯定的。
在tx日志提交到磁盘之后,假设txid为N,则认为写入是接受的。如果重新启动所有节点,则txid每个节点的使用将是N。在选举成功后,N将被视为已提交。
--我想困扰你的是,客户机实际上没有收到写的响应,但是写的是提交的。这是可以接受的,因为动物园管理员集群的状态保持一致,只有客户端遇到超时,其中超时意味着请求是否已提交都是未知的。
https://stackoverflow.com/questions/52678196
复制相似问题