Apache zookeeper 在zookeeper提案请求阶段,跟随者节点是否刷新磁盘请求?
我看过zookeeper的源代码,它在集群中的操作非常奇怪。 我们都知道,当写入zookeeper群集节点时,过程步骤如下:Apache zookeeper 在zookeeper提案请求阶段,跟随者节点是否刷新磁盘请求?,apache-zookeeper,Apache Zookeeper,我看过zookeeper的源代码,它在集群中的操作非常奇怪。 我们都知道,当写入zookeeper群集节点时,过程步骤如下: 领导向所有追随者和自己发送提案请求 当追随者收到提案请求时,确认它 当领导者收到最多的ack响应时,然后发送提交请求 跟随者和领导者都犯了这个错误 问题在于第2步,当follower接收到提议请求时,请求被同步到zk tx log(参见列表代码),提交请求只写入内存。但是在确认之前和同步到磁盘之后,重新启动所有节点,未限制的请求是最新的请求吗 // the follo
// 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();
}
}
//追随者收到提案请求方法,forword to syncProcessor
public void FollowerZooKeeperServer#logRequest(TxnHeader hdr,Record txn){
Request Request=新请求(null,hdr.getClientId(),hdr.getCxid(),
hdr.getType(),null,null);
request.hdr=hdr;
request.txn=txn;
request.zxid=hdr.getZxid();
如果((request.zxid&0xffffffffffffl)!=0){
pendingTxns.add(请求);
}
syncProcessor.processRequest(请求);
}
//SyncRequestProcessor操作,在发送日志提交到磁盘后,它响应ack请求。还好吗?
私有无效刷新(LinkedList toFlush)
抛出IOException、RequestProcessorException
{
if(toFlush.isEmpty())
返回;
getZKDatabase().commit();
而(!toFlush.isEmpty()){
请求i=toFlush.remove();
如果(下一个处理器!=null){
下一个处理器进程请求(i);
}
}
if(nextProcessor!=null&&nextProcessor instanceof Flushable){
((可冲洗)下一个处理器).flush();
}
}
答案是肯定的
发送日志提交到磁盘后,假设txid
为N,则写入被视为已接受。如果重新启动所有节点,则每个节点使用的txid
将为N。选举成功后,N将被视为已提交
我认为让您烦恼的是,客户机实际上没有收到写操作的响应,但写操作已提交。这是可以接受的,因为zookeeper集群的状态保持一致,只是客户端遇到了超时,其中超时意味着请求是否已提交未知 这台机器翻译了吗?