Skip to content

Commit a443c85

Browse files
authored
IPROTO: Add info about IPROTO_RAFT* requests (#2816)
Add information about RAFT-related constants and description of the IPROTO_RAFT request Closes #2814
1 parent 3520560 commit a443c85

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

doc/dev_guide/internals/box_protocol.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ The IPROTO constants that identify requests that we will mention in this section
7070
IPROTO_ROLLBACK=0x10
7171
IPROTO_RAFT_CONFIRM=0x28
7272
IPROTO_RAFT_ROLLBACK=0x29
73+
IPROTO_RAFT=0x1e
74+
IPROTO_RAFT_PROMOTE=0x1f
75+
IPROTO_RAFT_DEMOTE=0x20
7376
IPROTO_PING=0x40
7477
IPROTO_JOIN=0x41
7578
IPROTO_SUBSCRIBE=0x42
@@ -132,6 +135,10 @@ The IPROTO constants that appear within requests or responses that we will descr
132135
IPROTO_FIELD_IS_NULLABLE=0x03
133136
IPROTO_FIELD_IS_AUTOINCREMENT=0x04
134137
IPROTO_FIELD_SPAN=0x05
138+
IPROTO_RAFT_TERM=0x00
139+
IPROTO_RAFT_VOTE=0x01
140+
IPROTO_RAFT_STATE=0x02
141+
IPROTO_RAFT_VCLOCK=0x03
135142
136143
To denote message descriptions we will say ``msgpack(...)`` and within it we will use modified
137144
`YAML <https://en.wikipedia.org/wiki/YAML>`_ so: |br|
@@ -1406,6 +1413,37 @@ IPROTO_FLAG_COMMIT (0x01) will be set if this is the last message for a transact
14061413
IPROTO_FLAG_WAIT_SYNC (0x02) will be set if this is the last message for a transaction which cannot be completed immediately,
14071414
IPROTO_FLAG_WAIT_ACK (0x04) will be set if this is the last message for a synchronous transaction.
14081415

1416+
.. _box_protocol-raft:
1417+
1418+
IPROTO_RAFT = 0x1e
1419+
~~~~~~~~~~~~~~~~~~
1420+
1421+
A node broadcasts the IPROTO_RAFT request to all the replicas connected to it when the RAFT state of the node changes.
1422+
It can be any actions changing the state, like starting a new election, bumping the term, voting for another node, becoming the leader, and so on.
1423+
1424+
If there should be a response, for example, in case of a vote request to other nodes, the response will also be an IPROTO_RAFT message.
1425+
In this case, the node should be connected as a replica to another node from which the response is expected because the response is sent via the replication channel.
1426+
In other words, there should be a full-mesh connection between the nodes.
1427+
1428+
.. cssclass:: highlight
1429+
.. parsed-literal::
1430+
1431+
# <size>
1432+
msgpack(:samp:`{{MP_UINT unsigned integer = size(<header>) + size(<body>)}}`)
1433+
# <header>
1434+
msgpack({
1435+
IPROTO_REQUEST_TYPE: IPROTO_RAFT,
1436+
IPROTO_REPLICA_ID: :samp:`{{MP_INT integer}}`, # ID of the replica which the request came from
1437+
1438+
})
1439+
# <body>
1440+
msgpack({
1441+
IPROTO_RAFT_TERM: :samp:`{{MP_UINT unsigned integer}}`, # RAFT term of the instance
1442+
IPROTO_RAFT_VOTE: :samp:`{{MP_UINT unsigned integer}}`, # Instance vote in the current term (if any).
1443+
IPROTO_RAFT_STATE: :samp:`{{MP_UINT unsigned integer}}`, # Instance state; one of the three numbers: 1---follower, 2---candidate, 3---leader.
1444+
IPROTO_RAFT_VCLOCK: :samp:`{{MP_ARRAY {{MP_INT SRV_ID, MP_INT SRV_LSN}, {MP_INT SRV_ID, MP_INT SRV_LSN}, ...}}}` # Current vclock of the instance. Presents only on the instances in the "candidate" state (IPROTO_RAFT_STATE == 2).
1445+
})
1446+
14091447
.. _box_protocol-illustration:
14101448

14111449
Examples

0 commit comments

Comments
 (0)