{"id":70759,"date":"2023-11-21T19:04:11","date_gmt":"2023-11-21T11:04:11","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=70759"},"modified":"2023-11-21T19:04:11","modified_gmt":"2023-11-21T11:04:11","slug":"mysql-master-analysis","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/mysql-master-analysis.html","title":{"rendered":"mysql\u4e3b\u4ece\u540c\u6b65\u5f02\u6b65\u573a\u666f\u7684\u5206\u6790"},"content":{"rendered":"

\u4e4b\u6240\u4ee5\u8fdb\u884c\u8fd9\u5757\u5185\u5bb9\u7684\u7814\u7a76\uff0c\u4e3b\u8981\u9488\u5bf9\u4e4b\u524d\u9047\u5230\u7684\u4e24\u4e2a\u672a\u89e3\u7684\u7591\u60d1\uff1a<\/p>\n

a\uff0e\u00a0\u7ebf\u4e0a\u6709\u4e2a\u7cfb\u7edf\uff0c\u534a\u540c\u6b65\u72b6\u6001\u7ecf\u5e38\u4ece\u534a\u540c\u6b65\u53d8\u6210\u5f02\u6b65\uff0c\u7136\u540e\u53c8\u9a6c\u4e0a\u6062\u590d\u4e3a\u534a\u540c\u6b65\uff0c\u5177\u4f53\u539f\u56e0\u672a\u660e\uff0c\u867d\u7136\u4e4b\u524d\u4e5f\u731c\u5f97\u516b\u4e5d\u4e0d\u79bb\u5341\uff0c\u4f46\u8fd8\u662f\u672a\u5b8c\u5168\u786e\u5b9a\u3002<\/p>\n

b\uff0e\u00a0\u524d\u6bb5\u65f6\u95f4\u56e0\u4e3a\u6709\u4e1a\u52a1\u573a\u666f\u9700\u6c42\uff0c\u505a\u4e86\u8de8\u673a\u623f\u5f02\u6b65\u590d\u5236\u6d4b\u8bd5\u3002\u5f53mysql\u5199qps\u975e\u5e38\u9ad8\u7684\u65f6\u5019\uff0c\u53d1\u73b0\u5f88\u591a\u65e5\u5fd7\u8fd8\u6ca1\u6709\u6765\u5f97\u53ca\u53d1\u9001\u5230\u4ece\u5e93\uff0c\u4e5f\u5c31\u662fbinlog\u65e5\u5fd7\u5728\u4e3b\u5e93\u7684\u4ea7\u751f\u901f\u5ea6\u5927\u4e8e\u4f20\u9001\u5230\u4ece\u5e93\u7684\u901f\u5ea6\uff0c\u8fd9\u4e2a\u901f\u5ea6\u5dee\u4e00\u76f4\u5b58\u5728\uff0c\u56e0\u6b64\u5f53\u4e3b\u5e93\u5728\u6301\u7eed\u9ad8\u538b\u529b\u5730\u4ea7\u751fbinlog\u7684\u65f6\u5019\uff0c\u8d8a\u6765\u8d8a\u591a\u7684binlog\u6ca1\u6709\u4f20\u9001\u5230\u4ece\u5e93\uff0c\u4f46\u5f53\u65f6\u7684\u7f51\u7edc\u6d41\u91cf\u4e5f\u624d18M\/S\u5de6\u53f3\uff08\u4e00\u4e3b\u4e00\u4ece\uff09\uff0c\u4ece\u5e38\u89c4\u7684\u77e5\u8bc6\u8ba4\u4e3a\uff0c\u5343\u5146\u7684\u7f51\u7edc\u4f20\u9001\u7684\u901f\u5ea6\u53ef\u4ee5\u8fbe\u5230100M\uff0c\u800c\u5f53\u524d\u7684\u4e3b\u4ece\u4e4b\u95f4\u7684binlog\u4f20\u9001\u901f\u5ea6\u53ea\u8fbe\u5230\u4e8618M\u5de6\u53f3\uff0c\u539f\u56e0\u662f\u4ec0\u4e48\uff1f \u662f\u7f51\u7edc\u95ee\u9898\uff1f \u8fd8\u662f\u5176\u4ed6\u539f\u56e0\u3002<\/p>\n

\u4e3b\u4ece\u590d\u5236\u539f\u7406<\/strong><\/div>\n
Dump\u7ebf\u7a0b\u4e0eio\u7ebf\u7a0b<\/strong><\/span><\/div>\n

\u5f53\u4e3b\u4ece\u590d\u5236\u5173\u7cfb\u5efa\u7acb\u4e4b\u540e\uff0c\u4e3b\u5e93\u4e0a\u6709\u4e2adump\u7ebf\u7a0b\uff0c\u7528\u6765\u4f20\u9001\u5728\u4e3b\u5e93\u4ea7\u751f\u7684binlog\u65e5\u5fd7\u7684\uff0c\u800c\u4ece\u5e93\u4e0a\u7684io\u7ebf\u7a0b\uff0c\u5219\u7528\u6765\u63a5\u6536\u7531dump\u7ebf\u7a0b\u901a\u8fc7\u7f51\u7edc\u4f20\u9001\u5230\u4ece\u5e93\u7684binlog\u65e5\u5fd7\uff0c\u5e76\u8d1f\u8d23\u5c06\u5176\u5199\u5165relay log \u4e2d\u53bb\u3002 \u8fd9\u5c31\u662f\u4e3b\u4ece\u590d\u5236\u7684\u673a\u5236\uff0c \u540c\u65f6\uff0c\u7531\u4e8e\u662f\u5f02\u6b65\u590d\u5236\uff0c\u4f20\u9001\u8fc7\u7a0b\u4e0d\u9700\u8981ack\u7684\u786e\u8ba4\u3002<\/p>\n

\u7591\u95ee\u4e5f\u6b63\u5728\u6b64\u5904\u2014\u2014\u56e0\u4e3a\u662f\u5f02\u6b65\u4f20\u8f93\uff0c\u5982\u679c\u5355\u7eaf\u5730\u7406\u89e3\u4e3abinlog\u6587\u4ef6\u76f4\u63a5\u7f51\u7edc\u4f20\u9001\uff0c\u8fd9\u4e2a\u901f\u5ea6\u5e94\u8be5\u5f88\u5feb\u624d\u662f\uff0c\u4f46\u5b9e\u9645\u60c5\u51b5:\u5728\u6211\u4eec\u7684\u6d4b\u8bd5\u73af\u5883\u4e2d\uff0cbinlog\u65e5\u5fd7\u7684\u4f20\u9001\u901f\u5ea6\u624d18M\/s \uff0c\u5c0f\u4e8e\u65e5\u5fd7\u4ea7\u751f\u768422M\/s\u5de6\u53f3\u7684\u901f\u5ea6\u3002\u4e3a\u4ec0\u4e48\u53ea\u6709\u8fd9\u4e2a\u901f\u5ea6\uff0c\u800c\u6ca1\u6709\u628a\u7f51\u7edc\u5e26\u5bbd\u7528\u6ee1\uff1f\u539f\u56e0\u662f\u4ec0\u4e48\uff1f<\/p>\n

\u65e5\u5fd7\u4f20\u9001\u7ec6\u8282<\/strong><\/div>\n

\u4e3b\u4ece\u590d\u5236\u7684\u7ed3\u6784\u4e2d\uff0c\u4e3b\u5e93\u4e0a\u7684dump\u7ebf\u7a0b\u8ddf\u4ece\u5e93\u4e0a\u7684io\u7ebf\u7a0b\u5404\u81ea\u6709\u4e00\u4e2a\uff0c\u6240\u4ee5\u4e0d\u5b58\u5728\u591a\u7ebf\u7a0b\u5730\u5e76\u53d1\u53d1\u9001\u8ddf\u63a5\u6536\u7684\u60c5\u51b5\uff0c\u53ea\u9700\u8981\u4e86\u89e3binlog dump\u7ebf\u7a0b\u7684\u5de5\u4f5c\u673a\u5236\uff0c\u5c31\u80fd\u4e86\u89e3\u6240\u6709\u7684\u7ec6\u8282\u3002<\/p>\n

\u901a\u8fc7\u89e3\u6790binlog\u6587\u4ef6\uff0c\u6211\u4eec\u53ef\u4ee5\u77e5\u9053\uff0c\u4e00\u4e2a\u4e8b\u52a1\u53ef\u4ee5\u5305\u542b\u591a\u4e2aevent, \u4e0b\u9762\u662f\u4e00\u4e2a\u6700\u7b80\u5355\u7684\u4e8b\u7269\u7684\u5728binlog\u4e2d\u6240\u8bb0\u5f55\u7684\u4fe1\u606f\uff1a<\/p>\n

# at 33580\r\n\r\n#170531 17:22:53 server id 153443358 \u00a0end_log_pos 33645 CRC32 0x4ea17869 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0GTID \u00a0\u00a0\u00a0last_committed=125 \u00a0\u00a0\u00a0\u00a0\u00a0sequence_number=126\r\n\r\nSET @@SESSION.GTID_NEXT= \u2018e1028e43-4123-11e7-a3c2-005056aa17e6:198\u2019\/*!*\/;\r\n\r\n# at 33645\r\n\r\n#170531 17:22:53 server id 153443358 \u00a0end_log_pos 33717 CRC32 0x66820e00 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Query \u00a0\u00a0thread_id=4 \u00a0\u00a0\u00a0\u00a0exec_time=0 \u00a0\u00a0\u00a0\u00a0error_code=0\r\n\r\nSET TIMESTAMP=1496222573\/*!*\/;\r\n\r\nBEGIN\r\n\r\n\/*!*\/;\r\n\r\n# at 33717\r\n\r\n#170531 17:22:53 server id 153443358 \u00a0end_log_pos 33770 CRC32 0x22ddf25e \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Table_map: `test`.`xcytest` mapped to number 222\r\n\r\n# at 33770\r\n\r\n#170531 17:22:53 server id 153443358 \u00a0end_log_pos 33817 CRC32 0x61051ea0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Write_rows: table id 222 flags: STMT_END_F\r\n\r\nBINLOG \u2018\r\n\r\nbYsuWRMeXCUJNQAAAOqDAAAAAN4AAAAAAAEABHRlc3QAB3hjeXRlc3QAAgMPAlgCAl7y3SI=\r\n\r\nbYsuWR4eXCUJLwAAABmEAAAAAN4AAAAAAAEAAgAC\/\/x9AAAABQBzZGZhc6AeBWE=\r\n\r\n\u2018\/*!*\/;\r\n\r\n### INSERT INTO `test`.`xcytest`\r\n\r\n### SET\r\n\r\n### \u00a0\u00a0@1=125 \/* INT meta=0 nullable=0 is_null=0 *\/\r\n\r\n### \u00a0\u00a0@2=\u2019sdfas\u2019 \/* VARSTRING(600) meta=600 nullable=1 is_null=0 *\/\r\n\r\n# at 33817\r\n\r\n#170531 17:22:53 server id 153443358 \u00a0end_log_pos 33848 CRC32 0x630805b4 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Xid = 303\r\n\r\nCOMMIT\/*!*\/;<\/pre>\n

\u6bcf\u4e00\u4e2aat xxxxx\u6bb5\uff0c\u662f\u4e00\u4e2aevent .<\/p>\n

\u51fd\u6570Binlog_sender::send_events\u00a0\u5c31\u662f\u53d1\u9001binlog\u4e2d\u7684event\u4e8b\u4ef6\u7684\u51fd\u6570:<\/p>\n

\u51fd\u6570\u5165\u53c2\uff1a<\/strong><\/span><\/div>\n

end_pos\uff0c\u5f53\u524d\u8bfb\u5230\u7684binlog\u6587\u4ef6\u7684\u6700\u672b\u5c3e\u4f4d\u7f6e\u3002<\/p>\n

log_cache\uff0c\u8bb0\u5f55\u662f\u5f53\u524d\u4f20\u9001\u7684\u65e5\u5fd7\u7684\u4fe1\u606f\uff0c\u5305\u542b\u5df2\u7ecf\u4f20\u9001\u7684binlog\u65e5\u5fd7\u7684\u4f4d\u7f6e\uff0c\u4ee5\u53cabinlog\u65e5\u5fd7\u6587\u4ef6\u3002<\/p>\n

\u51fd\u6570\u903b\u8f91\u5206\u6790\uff1a<\/strong><\/span><\/div>\n

\u5982\u679c\u5f53\u524d\u5df2\u53d1\u9001\u7684\u4f4d\u7f6elog_pos\u5c0f\u4e8e\u5df2\u83b7\u53d6\u5230\u7684\u6587\u4ef6\u7684\u672b\u5c3e\u4f4d\u7f6eend_pos.\u5219\u8868\u660e\u8fd8\u6709binlog\u65e5\u5fd7\u672a\u53d1\u9001\uff0c\u8fdb\u5165\u5faa\u73af\u3002<\/p>\n

\u5faa\u73af\u4f53\u5185\uff1a<\/p>\n

a.\u00a0\u9996\u5148\u8c03\u7528\u51fd\u6570read_event,\u83b7\u53d6\u4e00\u4e2a\u4e8b\u4ef6event.<\/p>\n

b.\u00a0Log_event_type\u00a0event_type= (Log_event_type)event_ptr[EVENT_TYPE_OFFSET];<\/p>\n

\u8be5\u8bed\u53e5\u7528\u6765\u83b7\u53d6\u4e8b\u4ef6event\u7684\u7c7b\u578b\uff0c\u7136\u540e\u8fdb\u884c\u7c7b\u578b\u68c0\u67e5<\/p>\n

check_event_type(event_type, log_file, log_pos)\uff0c\u5982\u679c\u6ca1\u6709\u901a\u8fc7\u68c0\u67e5\uff0c\u76f4\u63a5\u8fd4\u56de1\u7ed9\u4e0a\u5c42\u51fd\u6570\u3002<\/p>\n

c.\u00a0log_pos= my_b_tell(log_cache); \u66f4\u65b0log_pos\u4f4d\u7f6e\uff0c\u4e5f\u5c31\u662f\u5c06\u8bfbbinlog\u4f4d\u7f6e\u7684\u6e38\u6807\u524d\u79fb\u5230\u5f53\u524d\u4f4d\u7f6e\u3002<\/p>\n

d.\u00a0\u7136\u540e\u8c03\u7528send_packet() \u51fd\u6570\u8fdb\u884cbinlog\u7684\u53d1\u9001\u3002<\/p>\n

\u539f\u6765\uff0c \u4e0d\u7ba1\u5f53\u524d\u8fd8\u6709\u591a\u5c11binlog\u6ca1\u6709\u540c\u6b65\u5230\u4ece\u5e93\uff0c\u4e3b\u5e93\u53d1\u9001binlog\u7684\u7c92\u5ea6\u4f9d\u7136\u662f\u4e00\u4e2a\u4e00\u4e2aevent\u7684\u53d1\u9001\uff0c\u53d1\u9001\u4e4b\u524d\uff0c\u8fd8\u9700\u8981\u68c0\u67e5event\u7684\u7c7b\u578b\u3002\u56e0\u4e3a\u662f\u5c0f\u5305\u53d1\u9001\uff0c\u6240\u4ee5\u7f51\u7edc\u7684\u6d41\u91cf\u5e76\u4e0d\u5927\u3002<\/p>\n

\u4f46\u9700\u8981\u8bf4\u660e\u4e00\u4e0b\u51fa\u73b0\u8fd9\u4e2a\u73b0\u8c61\u7684\u524d\u63d0\u6761\u4ef6\uff1a\u6211\u4eec\u6d4b\u8bd5\u73af\u5883\u4e2d\uff0c\u5f53\u65f6\u6570\u636e\u5e93\u7684\u5199qps\u8fbe\u5230\u4e8650000\u4ee5\u4e0a\uff0c\u6240\u4ee5\u9700\u8981\u53d1\u9001\u7684event\u7279\u522b\u591a\uff0c\u5373\u4f7f\u662f\u5f02\u6b65\uff0c\u4e5f\u5bfc\u81f4\u5355\u7ebf\u7a0b\u7684dump\u7ebf\u7a0b\u6765\u4e0d\u53ca\u53d1\u9001\u5f53\u524d\u4ea7\u751f\u7684\u65e5\u5fd7\u3002<\/p>\n

\u5f53\u5199\u7684qps\u5de8\u5927\u7684\u65f6\u5019\uff0c\u786e\u5b9e\u5b58\u5728\u6765\u4e0d\u53ca\u53d1\u9001\u65e5\u5fd7\u7684\u60c5\u666f\u3002<\/p>\n

\u603b\u7ed3<\/strong><\/div>\n

\u73b0\u5728\uff0c\u518d\u6765\u56de\u5934\u770b\u7ebf\u4e0a\u9047\u5230\u7684\u95ee\u9898\uff0c\u201c\u540c\u6b65\u72b6\u6001\u7ecf\u5e38\u4ece\u534a\u540c\u6b65\u72b6\u6001\u53d8\u6210\u5f02\u6b65\u72b6\u6001\uff0c\u7136\u540e\u53c8\u88ab\u53ca\u65f6\u590d\u539f\u5230\u534a\u540c\u6b65\u72b6\u6001\u201d\uff0c\u539f\u56e0\u662f\u8be5\u6570\u636e\u5e93\u662f\u4e00\u4e2a\u5206\u6790\u7cfb\u7edf\uff0c\u6709\u65f6\u5019\u4f1a\u505a\u6279\u91cf\u7684\u66f4\u65b0\uff0c\u4ee5\u53ca\u6279\u91cf\u7684\u5bfc\u5165\u3002\u540c\u65f6\uff0c\u6570\u636e\u5e93\u8bbe\u7f6e\u7684binlog\u683c\u5f0f\u4e3arow\u6a21\u5f0f\uff0c\u5bf9\u4e8e\u4e00\u4e2a\u66f4\u65b0\u591a\u884c\u7684\u4e8b\u52a1\uff0c\u91cc\u9762\u5305\u542b\u5f88\u591a\u7684event(\u4e00\u884c\u662f\u4e00\u4e2aevent), \u6240\u4ee5\u53d1\u9001\u8fd9\u4e2a\u4e8b\u52a1\u7684binlog\u8017\u65f6\u4f1a\u6bd4\u8f83\u957f\uff0c\u65e0\u6cd5\u57281\u79d2\u949f\u5185\u53d1\u9001\u5b8c\u6210\uff08\u534a\u540c\u6b65\u7684timeout\u65f6\u95f4\u8bbe\u7f6e\u4e3a1\uff09\uff0c\u6240\u4ee5\u534a\u540c\u6b65\u72b6\u6001\u53d8\u6210\u4e86\u5f02\u6b65\u3002<\/p>\n

\n

\u539f\u6587\u6765\u81ea\uff1ahttp:\/\/www.yunweipai.com\/archives\/19115.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttp:\/\/lrxjmw.cn\/mysql-master-analysis.html<\/a>\u7f16\u8f91\u5458\uff1a\u90ed\u5efa\u9e4f\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u4e4b\u6240\u4ee5\u8fdb\u884c\u8fd9\u5757\u5185\u5bb9\u7684\u7814\u7a76\uff0c\u4e3b\u8981\u9488\u5bf9\u4e4b\u524d\u9047\u5230\u7684\u4e24\u4e2a\u672a\u89e3\u7684\u7591\u60d1\uff1aa\uff0e\u00a0\u7ebf\u4e0a\u6709\u4e2a\u7cfb\u7edf\uff0c\u534a\u540c\u6b65\u72b6\u6001\u7ecf\u5e38\u4ece\u534a\u540c\u6b65\u53d8\u6210\u5f02\u6b65\uff0c\u7136\u540e\u53c8\u9a6c\u4e0a\u6062\u590d\u4e3a\u534a\u540c\u6b65\uff0c\u5177\u4f53\u539f\u56e0\u672a\u660e\uff0c\u867d\u7136\u4e4b\u524d\u4e5f\u731c\u5f97\u516b\u4e5d\u4e0d\u79bb\u5341\uff0c\u4f46\u8fd8\u662f\u672a\u5b8c\u5168\u786e\u5b9a\u3002<\/p>\n","protected":false},"author":323,"featured_media":83801,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-70759","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/70759","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/323"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=70759"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/70759\/revisions"}],"predecessor-version":[{"id":83812,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/70759\/revisions\/83812"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/83801"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=70759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=70759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=70759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}