The two-stage submission ZooKeeper

Two-phase commit

2PC: In a distributed system, each node machine even though it can clearly know their results during the course of the operation is a failure or success of something, but could not get the operating results of other distributed nodes directly, so things need to operate across multiple when distributed nodes, the need to introduce a unified scheduling coordinator to perform logic all nodes.

Phase One: submit a request things

  1. Things asked
    协调者向所有的参与者发送事物内容,询问是否可以执行事物操作,并开始等待各参与者的响应。
  2. Execution of things
    各参与者节点执行事物操作,并将Undo和Redo信息记入事物日志中
  3. Each participant feedback thing to ask of response coordinator
    如果参与者成功执行了事物操作,那么就反馈给协调者Yes响应,表示事物可以执行;如果参与者没有成功执行事物,那么就反馈给协调者No响应,表示事物不可以执行。

Phase II: execution request things

In phase II will be determined according to the coordinator of feedback from the participants can eventually operate things, of which there are two possibilities.

Execute things submission

If the coordinator feedback obtained from all participants are in response Yes, it will execute things in response.

  1. Send submit your request.
    协调者向所有参与者节点发出Commit请求
  2. Things submission
    参与者接收到Commit请求后,会正式执行事物提交操作,并在完成提交之后释放在整个事物执行期间占有的事物资源。
  3. Feedback things submit results
    参与者在完成事物提交之后,向协调者发送Ack消息。
  4. Completed things
    协调者接收到所有参与者反馈的Ack消息后,完成事物。

Advantages and disadvantages

  • Advantages: the principle is simple, easy to implement
  • Disadvantages: synchronous blocking, single-point problem, split brain, too conservative.

Guess you like

Origin www.cnblogs.com/we9999/p/12395200.html