Article Directory
background
The Distro protocol is an AP distributed protocol self-developed by the Nacos community . It is a distributed protocol designed for temporary instances. It ensures that the entire temporary instance processing system can still work normally after some Nacos nodes go down.
As an embedded protocol for stateful middleware applications, Distro ensures the unified coordination and storage of massive registration requests by each Nacos node.
design thinking
The main design ideas of the Distro protocol are as follows:
-
Each node is equal and can handle write requests while synchronizing new data to other nodes.
-
Each node is only responsible for part of the data, and regularly sends the check value of the data it is responsible for to other nodes to maintain data consistency.
-
Each node independently processes read requests and sends responses locally in a timely manner.
How the Distro protocol works
The following sections will be divided into several scenarios to introduce the working principle of the Distro protocol.
data initialization
The newly added Distro node will pull the full amount of data. The specific operation is to poll all Distro nodes and pull the full amount of data by sending requests to other machines
After the full pull operation is completed, all current registered non-persistent instance data is maintained on each machine of Nacos.
Data validation
After the Distro cluster is started, heartbeats are sent periodically between machines. The heartbeat information is mainly the metadata of all data on each machine (the reason why the metadata is used is to ensure that the magnitude of data transmission in the network is kept at a low level). This kind of data verification will be performed in the form of heartbeat, that is, each machine will initiate a data verification request to other machines at a fixed time interval.
Once during the data verification process, a machine finds that the data on other machines is inconsistent with the local data, it will initiate a full pull request to complete the data
write operation
For a Distro cluster that has been started, when a client initiates a write operation, when a write request for a registered non-persistent instance hits a certain Nacos server, the flow chart of the Distro cluster processing is as follows.
The whole step consists of several parts (from top to bottom in the figure):
- The front-end Filter intercepts the request, calculates the Distro responsible node it belongs to according to the IP and port information contained in the request, and forwards the request to the Distro responsible node it belongs to.
- The Controller on the responsible node parses the write request.
- The Distro protocol regularly executes the Sync task to synchronize all the instance information that the machine is responsible for to other nodes.
read operation
Since the full amount of data is stored on each machine, in each read operation, the Distro machine will directly pull the data from the local. Quick response
This mechanism ensures that the Distro protocol can be used as an AP protocol to respond to read operations in a timely manner.
In the case of a network partition, all read operations can also return normally; when the network is restored, each Distro node will merge and restore the data of each data fragment.
summary
The Distro protocol is a consistency protocol developed by Nacos for temporary instance data . Its data is stored in the cache, and full data synchronization will be performed at startup, and data verification will be performed periodically .
Under the design idea of the Distro protocol, each Distro node can receive read and write requests . All Distro protocol request scenarios are mainly divided into three situations:
-
When the node receives a write request belonging to the instance the node is responsible for, write directly.
-
When the node receives a write request that does not belong to the instance that the node is responsible for, it will be routed within the cluster and forwarded to the corresponding node to complete the read and write.
-
When the node receives any read request, it directly queries and returns locally (because all instances are synchronized to each machine).
Distro protocol, as Nacos' built-in temporary instance consistency protocol , ensures that in a distributed environment, the status of service information on each node can be notified to other nodes in a timely manner , and can maintain the storage and storage of hundreds of thousands of service instances. Consistency.