头图
This article was first published on the Nebula Graph Community public account

One of the more important features of Nebula Graph v2.6 is TOSS. Through this article, I will take you to fully understand what TOSS is.

Start with a GO statement

As we all know, there are two types of edges: undirected edges and directed edges. So when exploring by directed edge, you can traverse by forward edge/reverse edge. Nebula Graph also supports this semantics. for example:

 go from "101" over known reversely yield known.kdate, id($$);

The above statement starts from point 101 to find all the corresponding adjacent edges in reverse. However, when the user inserts an edge using Nebula, the commands are all similar to:

 insert edge known(degree) VALUES "100" -> "101":(299792458);

The above statement seems to only write the forward edge, and does not enter the reverse edge: this is because when Nebula is designed, when the user inserts an edge, the system will silently write a reverse edge in the background.

Talk about how Nebula Graph inserts an edge

Taking the INSERT statement above as an example, the execution flow in the background is as follows:

  • Nebula Console sends INSERT the corresponding request to the connected Nebula Graph Server;
  • After Nebula Graph Server receives it, it supplements the information of the reverse edge according to the information of the forward edge, and sends the AddEdgeRequest to the hosts corresponding to the forward and reverse edges respectively;
  • After Nebula Storage Server receives this AddEdgeRequest, it inserts the corresponding edge locally (through raft), and returns the result to Graph Server;
  • After Nebula Graph Server receives the results from both sides, it returns to Nebula Console;

The flow chart is as follows:

正反向边的最终一致性——TOSS 介绍

Here, students who are familiar with network/distributed programming may see the problem now: because Graph uses RPC for two Storage calls, then when the INSERT operation is executed enough times, it will be Encounter a situation where one RPC succeeds and the other RPC fails (timeout). In other words, there may be a situation where INSERT the forward side succeeds and the reverse side fails.

This result will be fed back to the client: if the user has the requirement to have the same attributes of the forward and reverse edges, it needs to retry the failed request infinitely. However, as a database, Nebula Graph is not suitable for guaranteeing the atomicity of data to an external (client).

Therefore, a requirement was born - to ensure the atomicity of forward and reverse edges, that is, when changing an edge, the forward and reverse edges are either successfully changed at the same time, or fail to be changed at the same time. This is the origin of TOSS (Transaction on storage side), which is used to ensure the eventual consistency of INSERT , UPDATE or UPSERT operations.

How to use TOSS

With the release of Nebula v2.6.0, the TOSS function has been launched. However, based on performance and stability considerations, Nebula Graph sets this function to the default disable state by default. Friends who have the requirement of forward and reverse edge consistency can find this option in the configuration of Nebula Graph Server enable_experimental_feature , set it to true and restart graphd. as follows:

 --enable_experimental_feature=true

Then INSERT / UPDATE / UPSERT will be consistent. (Do the same as before CREATE SPACE / CREATE EDGE / INSERT / UPDATE , no additional operations are required)

Note: After TOSS is turned on, it is only valid for incremental data. If there is an inconsistency between the positive and negative sides of the existing data, it will not be corrected.


Nebula community's first essay contest is officially launched🔗 The prizes are generous, covering the whole scene: mechanical keyboard, mobile phone wireless charging, health assistant smart bracelet, more database design, knowledge map practice books waiting for you to pick up, and Nebula exquisite Non-stop delivery around

Welcome friends who are interested in Nebula and who like to study and write interesting stories about themselves and Nebula~

Exchange graph database technology? To join the Nebula exchange group, please fill in your Nebula business card first, and the Nebula assistant will pull you into the group~~


NebulaGraph
169 声望684 粉丝

NebulaGraph:一个开源的分布式图数据库。欢迎来 GitHub 交流:[链接]