12. 新节点加入过程解读 | 深入浅出MGR

本文从日志解读MGR节点加入过程。

1. 从日志理解(手动)加入新节点过程

新节点加入MGR集群时,通过观察它的日志(设置 log_error_verbosity=3 日志中能记录更多信息,便于跟踪和排查故障),能更好的理解MGR的工作过程及数据同步机制。

下面是(命令行手工操作方式,不是通过MySQL Shell调用)新节点加入时,从Primary节点看到的日志(对时间戳、主机名等做了简单处理):

-- 1. 确定当前集群中已存在的三个节点 17:05:48.297323 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] Re-using server node 0 host 127.0.0.1' 17:05:48.297347 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] Re-using server node 1 host 127.0.0.1' 17:05:48.297351 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] Re-using server node 2 host 127.0.0.1' -- 2. 有新节点要加入了 17:05:48.297355 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] Creating new server node 3 host 127.0.0.1' 17:05:48.297373 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] pid 6541 Installed site start={ff389be 7249 0} boot_key={ff389be 7238 0} event_horizon=10 node 0 chksum_node_list(&site->nodes) 3840072444' -- 3. 准备进行view change 17:05:48.959766 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] xcom_receive_local_view is called' 17:05:48.959828 [Note] [MY-011071] [Repl] Plugin group_replication reported: 'on_suspicions is activated' 17:05:48.959847 [Note] [MY-011071] [Repl] Plugin group_replication reported: 'on_suspicions is called over' 17:05:48.959853 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] xcom_receive_local_view return true' 17:05:48.960279 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] ::xcom_receive_global_view() is called' 17:05:49.960937 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] xcom_communication do_send_message CT_INTERNAL_STATE_EXCHANGE' 17:05:49.961025 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] ::xcom_receive_global_view():: state exchange started.' 17:05:49.961207 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] Do receive CT_INTERNAL_STATE_EXCHANGE message from xcom' 17:05:49.961227 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] ::process_control_message():: Received a control message' 17:05:49.961352 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] Do receive CT_INTERNAL_STATE_EXCHANGE message from xcom' 17:05:49.961392 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] ::process_control_message():: Received a control message' 17:05:49.961436 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] Do receive CT_INTERNAL_STATE_EXCHANGE message from xcom' 17:05:49.961445 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] ::process_control_message():: Received a control message' 17:05:49.961451 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] Do receive CT_INTERNAL_STATE_EXCHANGE message from xcom' 17:05:49.961457 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] ::process_control_message():: Received a control message' - 4. 确认通信协议版本 17:05:49.961466 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] Group is able to support up to communication protocol version 8.0.16' -- 5. 确认新节点可以加入,准备修改view 17:05:49.961472 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] ::process_control_message()::Install new view' 17:05:49.961479 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] Processing exchanged data while installing the new view' 17:05:49.961482 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] Processing exchanged data while installing the new view' 17:05:49.961486 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] Processing exchanged data while installing the new view' 17:05:49.961491 [Note] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] Processing exchanged data while installing the new view' 17:05:49.961498 [Note] [MY-011071] [Repl] Plugin group_replication reported: 'on_view_changed is called' -- 6. 新节点成功加入 17:05:49.961538 [Note] [MY-011501] [Repl] Plugin group_replication reported: 'Members joined the group: 127.0.0.1:3312' -- 7. 准备是否需要进行新主选举 17:05:49.961565 [Note] [MY-011071] [Repl] Plugin group_replication reported: 'handle_leader_election_if_needed is activated,suggested_primary:' -- 8. 确认新的view 17:05:49.961591 [System] [MY-011503] [Repl] Plugin group_replication reported: 'Group membership changed to 127.0.0.1:3312, 127.0.0.1:3311, 127.0.0.1:3310, 127.0.0.1:3309 on view 16444111732158542:6.' -- 9. 启动binlog dump线程发送日志 17:05:51.033352 [Note] [MY-010462] [Repl] Start binlog_dump to master_thread_id(49) slave_server(3312), pos(, 4) -- 10. 数据同步完成,宣告新节点转成online状态,正式加入MGR集群 17:05:51.157744 [System] [MY-011492] [Repl] Plugin group_replication reported: 'The member with address 127.0.0.1:3312 was declared online within the replication group.'