Zookeeper 中的 cxid 有什么用
what is cxid used for in Zookeeper
在 zookeeper 日志和源代码中,我看到 Request/Txn/Header 中有一个名为 cxid
的字段。
2018-06-24 02:28:55,003 [myid:1] - DEBUG [CommitProcessor:1:FinalRequestProcessor@88] - Processing request:: sessionid:0x1642e63d6060000 type:ping cxid:0xfffffffffffffffe zxid:0xfffffffffffffffe txntype:unknown reqpath:n/a
我无法理解它的用途。
The zxid has two parts: the epoch and a counter. In our implementation
the zxid is a 64-bit number. We use the high order 32-bits for the
epoch and the low order 32-bits for the counter. Because it has two
parts represent the zxid both as a number and as a pair of integers,
(epoch, count). The epoch number represents a change in leadership.
Each time a new leader comes into power it will have its own epoch
number. We have a simple algorithm to assign a unique zxid to a
proposal: the leader simply increments the zxid to obtain a unique
zxid for each proposal. Leadership activation will ensure that only
one leader uses a given epoch, so our simple algorithm guarantees that
every proposal will have a unique id.
ZooKeeper 命名空间中的每个 node 都可以有与其关联的数据以及子节点。这就像拥有一个允许文件也可以是目录的文件系统。我们使用术语 znode 来明确表示我们正在谈论 ZooKeeper 数据节点.
在描述 ZooKeeper 消息传递协议时,我们将讨论数据包、提议和消息:
Packet a sequence of bytes sent through a FIFO channel
Proposal a unit of agreement. Proposals are agreed upon by exchanging packets with a quorum of ZooKeeper servers. Most proposals
contain messages, however the NEW_LEADER proposal is an example of a
proposal that does not correspond to a message.
Message a sequence of bytes to be atomically broadcast to all ZooKeeper servers. A message put into a proposal and agreed upon
before it is delivered.
如上所述,ZooKeeper 保证了消息的全序,它也保证了提案的全序。 ZooKeeper 使用 ZooKeeper 事务 ID (zxid) 公开总排序。所有提案在提出时都会被打上 zxid 的戳记,并准确反映总排序。提议被发送到所有 ZooKeeper 服务器,并在它们中的法定人数确认提议时提交。如果提案包含消息,则该消息将在提交提案时传递。确认意味着服务器已将提议记录到持久存储中。我们的法定人数要求任何一对法定人数必须至少有一个共同的服务器。
cxid
是在客户端向服务器发送数据包之前在客户端生成的单调递增整数。
以下是 zookeeper 日志的摘录,其中显示了三个不同会话的一些创建命令。如下所示,同一会话中的每个新命令的 cxid
都在增加。
7/2/18 10:52:06 PM IST session 0x1645c03e93f0004 cxid 0x0 zxid 0x100000021 createSession 30000
7/2/18 10:52:06 PM IST session 0x1645c03e93f0004 cxid 0x1 zxid 0x100000022 create '/data5,#74686973,v{s{31,s{'world,'anyone}}},F,5
7/2/18 10:52:07 PM IST session 0x1645c03e93f0004 cxid 0x2 zxid 0x100000023 create '/data5/path1,#74686973,v{s{31,s{'world,'anyone}}},F,1
7/2/18 10:52:07 PM IST session 0x1645c03e93f0004 cxid 0x3 zxid 0x100000024 create '/data5/path1/child1,#74686973,v{s{31,s{'world,'anyone}}},F,1
7/2/18 10:52:07 PM IST session 0x1645c03e93f0004 cxid 0x4 zxid 0x100000025 create '/data5/path1/child2,#74686973,v{s{31,s{'world,'anyone}}},F,2
7/2/18 10:52:07 PM IST session 0x1645c03e93f0004 cxid 0x5 zxid 0x100000026 create '/data5/path2,#74686973,v{s{31,s{'world,'anyone}}},F,2
7/2/18 10:52:07 PM IST session 0x1645c03e93f0004 cxid 0x6 zxid 0x100000027 create '/data5/path2/child1,#74686973,v{s{31,s{'world,'anyone}}},F,1
7/2/18 10:52:07 PM IST session 0x1645c03e93f0004 cxid 0x7 zxid 0x100000028 create '/data5/path2/child2,#74686973,v{s{31,s{'world,'anyone}}},F,2
7/2/18 10:52:07 PM IST session 0x1645c03e93f0005 cxid 0x0 zxid 0x100000029 createSession 30000
7/2/18 10:52:08 PM IST session 0x1645c03e93f0005 cxid 0x1 zxid 0x10000002a create '/data6,#74686973,v{s{31,s{'world,'anyone}}},F,6
7/2/18 10:52:08 PM IST session 0x1645c03e93f0005 cxid 0x2 zxid 0x10000002b create '/data6/path1,#74686973,v{s{31,s{'world,'anyone}}},F,1
7/2/18 10:52:08 PM IST session 0x1645c03e93f0005 cxid 0x3 zxid 0x10000002c create '/data6/path1/child1,#74686973,v{s{31,s{'world,'anyone}}},F,1
7/2/18 10:52:08 PM IST session 0x1645c03e93f0005 cxid 0x4 zxid 0x10000002d create '/data6/path1/child2,#74686973,v{s{31,s{'world,'anyone}}},F,2
7/2/18 10:52:08 PM IST session 0x1645c03e93f0005 cxid 0x5 zxid 0x10000002e create '/data6/path2,#74686973,v{s{31,s{'world,'anyone}}},F,2
7/2/18 10:52:08 PM IST session 0x1645c03e93f0005 cxid 0x6 zxid 0x10000002f create '/data6/path2/child1,#74686973,v{s{31,s{'world,'anyone}}},F,1
7/2/18 10:52:08 PM IST session 0x1645c03e93f0005 cxid 0x7 zxid 0x100000030 create '/data6/path2/child2,#74686973,v{s{31,s{'world,'anyone}}},F,2
7/2/18 10:52:09 PM IST session 0x1645c03e93f0006 cxid 0x0 zxid 0x100000031 createSession 30000
7/2/18 10:52:09 PM IST session 0x1645c03e93f0006 cxid 0x1 zxid 0x100000032 create '/data7,#74686973,v{s{31,s{'world,'anyone}}},F,7
7/2/18 10:52:09 PM IST session 0x1645c03e93f0006 cxid 0x2 zxid 0x100000033 create '/data7/path1,#74686973,v{s{31,s{'world,'anyone}}},F,1
7/2/18 10:52:09 PM IST session 0x1645c03e93f0006 cxid 0x3 zxid 0x100000034 create '/data7/path1/child1,#74686973,v{s{31,s{'world,'anyone}}},F,1
7/2/18 10:52:09 PM IST session 0x1645c03e93f0006 cxid 0x4 zxid 0x100000035 create '/data7/path1/child2,#74686973,v{s{31,s{'world,'anyone}}},F,2
7/2/18 10:52:09 PM IST session 0x1645c03e93f0006 cxid 0x5 zxid 0x100000036 create '/data7/path2,#74686973,v{s{31,s{'world,'anyone}}},F,2
7/2/18 10:52:09 PM IST session 0x1645c03e93f0006 cxid 0x6 zxid 0x100000037 create '/data7/path2/child1,#74686973,v{s{31,s{'world,'anyone}}},F,1
cxid
特定于连接,而不是会话。因此,如果客户端突然与服务器断开连接并重新连接到之前的 sessionid
,我猜 cxid
将再次启动。不确定这是否会导致任何问题。
cxid
是在classorg.apache.zookeeper.ClientCnxn
方法中生成的org.apache.zookeeper.ClientCnxn.getXid()
每当客户端与 zookeeper 服务器建立连接时,两者之间就会启动一组事务。这里维护了两个id cxid和zxid。
cxid 是一个递增的数字序列,表示与客户端的会话起点。
而 zxid 是 zookeeper 事务 ID 并跟踪 zookeeper 处理的任何更改。
cxid 0x0 zxid 0x20 createSession - 这是客户端开始与 zookeeper 会话的时间
cxid 0x1 zxid 0x21 错误
cxid 0x2 zxid 0x22 错误
cxid 0x3 zxid 0x23 错误
cxid 0x4 zxid 0x24 错误
cxid 0x5 zxid 0x25 错误
cxid 0x6 zxid 0x26 错误
cxid 0x7 zxid 0x27 错误
cxid 0x8 zxid 0x28 错误
cxid 0x9 zxid 0x29 错误
cxid 0xa zxid 0x2a 错误
cxid 0xb zxid 0x2b 错误
cxid 0xc zxid 0x2c 错误
cxid 0xd zxid 0x2d 错误
cxid 0x13 zxid 0x2e 创建
cxid 0x16 zxid 0x2f 创建
cxid 0x19 zxid 0x30 设置数据
cxid 0x20 zxid 0x31 设置数据
cxid 0x2d zxid 0x32 错误
cxid 0x2f zxid 0x33 错误
cxid 0x38 zxid 0x34 closeSession - 会话被客户端关闭
在 zookeeper 日志和源代码中,我看到 Request/Txn/Header 中有一个名为 cxid
的字段。
2018-06-24 02:28:55,003 [myid:1] - DEBUG [CommitProcessor:1:FinalRequestProcessor@88] - Processing request:: sessionid:0x1642e63d6060000 type:ping cxid:0xfffffffffffffffe zxid:0xfffffffffffffffe txntype:unknown reqpath:n/a
我无法理解它的用途。
The zxid has two parts: the epoch and a counter. In our implementation the zxid is a 64-bit number. We use the high order 32-bits for the epoch and the low order 32-bits for the counter. Because it has two parts represent the zxid both as a number and as a pair of integers, (epoch, count). The epoch number represents a change in leadership. Each time a new leader comes into power it will have its own epoch number. We have a simple algorithm to assign a unique zxid to a proposal: the leader simply increments the zxid to obtain a unique zxid for each proposal. Leadership activation will ensure that only one leader uses a given epoch, so our simple algorithm guarantees that every proposal will have a unique id.
ZooKeeper 命名空间中的每个 node 都可以有与其关联的数据以及子节点。这就像拥有一个允许文件也可以是目录的文件系统。我们使用术语 znode 来明确表示我们正在谈论 ZooKeeper 数据节点.
在描述 ZooKeeper 消息传递协议时,我们将讨论数据包、提议和消息:
Packet a sequence of bytes sent through a FIFO channel
Proposal a unit of agreement. Proposals are agreed upon by exchanging packets with a quorum of ZooKeeper servers. Most proposals contain messages, however the NEW_LEADER proposal is an example of a proposal that does not correspond to a message.
Message a sequence of bytes to be atomically broadcast to all ZooKeeper servers. A message put into a proposal and agreed upon before it is delivered.
如上所述,ZooKeeper 保证了消息的全序,它也保证了提案的全序。 ZooKeeper 使用 ZooKeeper 事务 ID (zxid) 公开总排序。所有提案在提出时都会被打上 zxid 的戳记,并准确反映总排序。提议被发送到所有 ZooKeeper 服务器,并在它们中的法定人数确认提议时提交。如果提案包含消息,则该消息将在提交提案时传递。确认意味着服务器已将提议记录到持久存储中。我们的法定人数要求任何一对法定人数必须至少有一个共同的服务器。
cxid
是在客户端向服务器发送数据包之前在客户端生成的单调递增整数。
以下是 zookeeper 日志的摘录,其中显示了三个不同会话的一些创建命令。如下所示,同一会话中的每个新命令的 cxid
都在增加。
7/2/18 10:52:06 PM IST session 0x1645c03e93f0004 cxid 0x0 zxid 0x100000021 createSession 30000
7/2/18 10:52:06 PM IST session 0x1645c03e93f0004 cxid 0x1 zxid 0x100000022 create '/data5,#74686973,v{s{31,s{'world,'anyone}}},F,5
7/2/18 10:52:07 PM IST session 0x1645c03e93f0004 cxid 0x2 zxid 0x100000023 create '/data5/path1,#74686973,v{s{31,s{'world,'anyone}}},F,1
7/2/18 10:52:07 PM IST session 0x1645c03e93f0004 cxid 0x3 zxid 0x100000024 create '/data5/path1/child1,#74686973,v{s{31,s{'world,'anyone}}},F,1
7/2/18 10:52:07 PM IST session 0x1645c03e93f0004 cxid 0x4 zxid 0x100000025 create '/data5/path1/child2,#74686973,v{s{31,s{'world,'anyone}}},F,2
7/2/18 10:52:07 PM IST session 0x1645c03e93f0004 cxid 0x5 zxid 0x100000026 create '/data5/path2,#74686973,v{s{31,s{'world,'anyone}}},F,2
7/2/18 10:52:07 PM IST session 0x1645c03e93f0004 cxid 0x6 zxid 0x100000027 create '/data5/path2/child1,#74686973,v{s{31,s{'world,'anyone}}},F,1
7/2/18 10:52:07 PM IST session 0x1645c03e93f0004 cxid 0x7 zxid 0x100000028 create '/data5/path2/child2,#74686973,v{s{31,s{'world,'anyone}}},F,2
7/2/18 10:52:07 PM IST session 0x1645c03e93f0005 cxid 0x0 zxid 0x100000029 createSession 30000
7/2/18 10:52:08 PM IST session 0x1645c03e93f0005 cxid 0x1 zxid 0x10000002a create '/data6,#74686973,v{s{31,s{'world,'anyone}}},F,6
7/2/18 10:52:08 PM IST session 0x1645c03e93f0005 cxid 0x2 zxid 0x10000002b create '/data6/path1,#74686973,v{s{31,s{'world,'anyone}}},F,1
7/2/18 10:52:08 PM IST session 0x1645c03e93f0005 cxid 0x3 zxid 0x10000002c create '/data6/path1/child1,#74686973,v{s{31,s{'world,'anyone}}},F,1
7/2/18 10:52:08 PM IST session 0x1645c03e93f0005 cxid 0x4 zxid 0x10000002d create '/data6/path1/child2,#74686973,v{s{31,s{'world,'anyone}}},F,2
7/2/18 10:52:08 PM IST session 0x1645c03e93f0005 cxid 0x5 zxid 0x10000002e create '/data6/path2,#74686973,v{s{31,s{'world,'anyone}}},F,2
7/2/18 10:52:08 PM IST session 0x1645c03e93f0005 cxid 0x6 zxid 0x10000002f create '/data6/path2/child1,#74686973,v{s{31,s{'world,'anyone}}},F,1
7/2/18 10:52:08 PM IST session 0x1645c03e93f0005 cxid 0x7 zxid 0x100000030 create '/data6/path2/child2,#74686973,v{s{31,s{'world,'anyone}}},F,2
7/2/18 10:52:09 PM IST session 0x1645c03e93f0006 cxid 0x0 zxid 0x100000031 createSession 30000
7/2/18 10:52:09 PM IST session 0x1645c03e93f0006 cxid 0x1 zxid 0x100000032 create '/data7,#74686973,v{s{31,s{'world,'anyone}}},F,7
7/2/18 10:52:09 PM IST session 0x1645c03e93f0006 cxid 0x2 zxid 0x100000033 create '/data7/path1,#74686973,v{s{31,s{'world,'anyone}}},F,1
7/2/18 10:52:09 PM IST session 0x1645c03e93f0006 cxid 0x3 zxid 0x100000034 create '/data7/path1/child1,#74686973,v{s{31,s{'world,'anyone}}},F,1
7/2/18 10:52:09 PM IST session 0x1645c03e93f0006 cxid 0x4 zxid 0x100000035 create '/data7/path1/child2,#74686973,v{s{31,s{'world,'anyone}}},F,2
7/2/18 10:52:09 PM IST session 0x1645c03e93f0006 cxid 0x5 zxid 0x100000036 create '/data7/path2,#74686973,v{s{31,s{'world,'anyone}}},F,2
7/2/18 10:52:09 PM IST session 0x1645c03e93f0006 cxid 0x6 zxid 0x100000037 create '/data7/path2/child1,#74686973,v{s{31,s{'world,'anyone}}},F,1
cxid
特定于连接,而不是会话。因此,如果客户端突然与服务器断开连接并重新连接到之前的 sessionid
,我猜 cxid
将再次启动。不确定这是否会导致任何问题。
cxid
是在classorg.apache.zookeeper.ClientCnxn
方法中生成的org.apache.zookeeper.ClientCnxn.getXid()
每当客户端与 zookeeper 服务器建立连接时,两者之间就会启动一组事务。这里维护了两个id cxid和zxid。
cxid 是一个递增的数字序列,表示与客户端的会话起点。
而 zxid 是 zookeeper 事务 ID 并跟踪 zookeeper 处理的任何更改。
cxid 0x0 zxid 0x20 createSession - 这是客户端开始与 zookeeper 会话的时间
cxid 0x1 zxid 0x21 错误
cxid 0x2 zxid 0x22 错误
cxid 0x3 zxid 0x23 错误
cxid 0x4 zxid 0x24 错误
cxid 0x5 zxid 0x25 错误
cxid 0x6 zxid 0x26 错误
cxid 0x7 zxid 0x27 错误
cxid 0x8 zxid 0x28 错误
cxid 0x9 zxid 0x29 错误
cxid 0xa zxid 0x2a 错误
cxid 0xb zxid 0x2b 错误
cxid 0xc zxid 0x2c 错误 cxid 0xd zxid 0x2d 错误
cxid 0x13 zxid 0x2e 创建
cxid 0x16 zxid 0x2f 创建
cxid 0x19 zxid 0x30 设置数据
cxid 0x20 zxid 0x31 设置数据
cxid 0x2d zxid 0x32 错误
cxid 0x2f zxid 0x33 错误
cxid 0x38 zxid 0x34 closeSession - 会话被客户端关闭