{"id":11542,"date":"2014-11-18T17:18:15","date_gmt":"2014-11-18T08:18:15","guid":{"rendered":"http:\/\/labs.gree.jp\/blog\/?p=11542"},"modified":"2014-11-18T17:22:21","modified_gmt":"2014-11-18T08:22:21","slug":"mysql%e3%83%a6%e3%83%bc%e3%82%b6%e3%83%bc%e3%81%ae%e3%81%9f%e3%82%81%e3%81%aemysql%e3%83%97%e3%83%ad%e3%83%88%e3%82%b3%e3%83%ab%e5%85%a5%e9%96%80-4-2","status":"publish","type":"post","link":"https:\/\/labs.gree.jp\/blog\/2014\/11\/11542\/","title":{"rendered":"MySQL\u30e6\u30fc\u30b6\u30fc\u306e\u305f\u3081\u306eMySQL\u30d7\u30ed\u30c8\u30b3\u30eb\u5165\u9580 #4"},"content":{"rendered":"<p>\u306a\u3093\u3068\u306a\u304f\u6c17\u5206\u3067\u59cb\u3081\u305fMySQL\u30d7\u30ed\u30c8\u30b3\u30eb\u5165\u9580\u3067\u3059\u304c\u4eca\u56de\u306f\u5c11\u3057\u8da3\u5411\u3092\u304b\u3048\u3066binlog format\u306b\u3064\u3044\u3066\u66f8\u3044\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>MySQL\u3067\u306e\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u5358\u4f4d\u3068\u3057\u3066\u4f7f\u308f\u308c\u3066\u3044\u308bbinlog\u3067\u3059\u304c\u3001\u305d\u3082\u305d\u3082binlog\uff08\u30d0\u30a4\u30ca\u30ea\u30fc\u30ed\u30b0\uff09\u3068\u306f\u3069\u3046\u3044\u3063\u305f\u3082\u306e\u306a\u306e\u3067\u3057\u3087\u3046\u304b\uff1f\u5b9f\u969b\u554f\u984c\u3088\u304f\u308f\u304b\u3089\u306a\u304f\u3066\u3082\u3061\u3087\u3061\u3087\u3063\u3068\u8a2d\u5b9a\u3059\u308c\u3070\u7d20\u6575\u306b\u52d5\u3044\u3066\u304f\u308c\u308b\u306e\u3067\u308f\u304b\u3089\u306a\u304f\u3066\u3082\u5927\u4e08\u592b\u3063\u3061\u3083\u30fc\u3001\u5927\u4e08\u592b\u306a\u3093\u3067\u3059\u304c\u305b\u3063\u304b\u304f\u8208\u5473\u304c\u6e67\u3044\u3066\u3057\u307e\u3063\u305f\u4e8b\u3067\u3059\u3057\u8abf\u3079\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><a href=\"http:\/\/dev.mysql.com\/doc\/internals\/en\/replication-protocol.html\">http:\/\/dev.mysql.com\/doc\/internals\/en\/replication-protocol.html<\/a> \u3088\u308a\u5f15\u7528\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<blockquote><p>\n  Replication uses binlogs to ship changes done on the master to the slave and can be written to Binlog File and sent over the network as Binlog Network Stream.\n<\/p><\/blockquote>\n<p>\u3048\u3048\u3063\u3068\u3001\u8981\u3059\u308b\u306b\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3068\u3044\u3046\u4ed5\u7d44\u307f\u306fbinlog\u3068\u3044\u3046\u3082\u306e\u3092\u4f7f\u3063\u3066master\u3067\u306e\u5909\u66f4\u3092slave\u306b\u4f1d\u3048\u3089\u308c\u308b\u3082\u306e\u3067\u3001Binlog Network Stream\u3068\u3044\u3046\u3082\u306e\u3067network\u4e0a\u3092\u6d41\u308c\u308b\u30e2\u30ce\u306e\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>\u3046\u3046\u3093\u3001\u306a\u3093\u3060\u304b\u5206\u304b\u308b\u3088\u3046\u306a\u3001\u308f\u304b\u3089\u306a\u3044\u3088\u3046\u306a\u3002\u3061\u3087\u3063\u3068\u3084\u3084\u3053\u3057\u3044\u3067\u3059\u306d\u3002<br \/>\n\u4eca\u65e5\u306e\u3068\u3053\u308d\u306f\u3072\u3068\u307e\u305aBinlog File\u3068\u3044\u3046\u3082\u306e\u304c\u3069\u3046\u3044\u3063\u305f\u3082\u306e\u306a\u306e\u304b\u306b\u3064\u3044\u3066\u898b\u3066\u884c\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>Binlog File<\/h2>\n<p><a href=\"http:\/\/dev.mysql.com\/doc\/internals\/en\/binlog-file.html\">http:\/\/dev.mysql.com\/doc\/internals\/en\/binlog-file.html<\/a><br \/>\nBinlog\u30d5\u30a1\u30a4\u30eb\u306fBinlog File Header\u3067\u59cb\u307e\u308a\u3001Binlog Event\u304c\u9023\u7d9a\u3057\u305f\u3082\u306e\u3067\u3042\u308b\u3002\u3068\u66f8\u304b\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u307e\u3093\u307e\u3059\u304e\u307e\u3059\u304c\u3001\u56f3\u3067\u66f8\u3044\u3066\u307f\u308b\u3068\u3053\u3093\u306a\u611f\u3058\u3067\u3057\u3087\u3046\u304b\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2014\/11\/Screen-Shot-2014-11-17-at-1.28.48-PM.png\" alt=\"Screen Shot 2014-11-17 at 1.28.48 PM\" width=\"357\" height=\"424\" class=\"aligncenter size-full wp-image-11549\" \/><\/p>\n<p>Binlog File Header\u3068\u306f\u3069\u3046\u3044\u3046\u3082\u306e\u304b\u3001\u3068\u3044\u3046\u3068<br \/>\n<a href=\"http:\/\/dev.mysql.com\/doc\/internals\/en\/binlog-file-header.html\">http:\/\/dev.mysql.com\/doc\/internals\/en\/binlog-file-header.html<\/a><\/p>\n<p>0xfe, 0x62, 0x69, 0x6e (0xfe bin)\u306e4byte\u304b\u3089\u59cb\u307e\u308b\u30d5\u30a1\u30a4\u30eb\u3068\u304b\u3044\u3066\u3042\u308a\u307e\u3059\u304c\u5358\u306a\u308bMagic\u3067\u3059\u306d\u3002\u3042\u307e\u308a\u91cd\u8981\u3067\u306f\u306a\u3044\u306e\u3067\u6b21\u306b\u9032\u307f\u307e\u3057\u3087\u3046<\/p>\n<h3>Binlog Event Header<\/h3>\n<p>Binlog Event\u304c\u7d9a\u3044\u305f\u3082\u306e\u2026\u2026\u3068\u66f8\u3044\u3066\u3042\u308b\u3050\u3089\u3044\u306a\u306e\u3067\u3053\u3053\u304c\u4e00\u756a\u91cd\u8981\u306a\u30dd\u30a4\u30f3\u30c8\u3063\u307d\u3044\u3067\u3059\u306d\u3002Binlog Event\u306fMySQL Packet\u3068\u540c\u3058\u3088\u3046\u306bHeader + Payload\u5f62\u5f0f\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/dev.mysql.com\/doc\/internals\/en\/binlog-event-header.html\">http:\/\/dev.mysql.com\/doc\/internals\/en\/binlog-event-header.html<\/a> \u304b\u3089\u5b9a\u7fa9\u3092\u5f15\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \" >4              timestamp\n1              event type\n4              server-id\n4              event-size\n   if binlog-version &gt; 1:\n4              log pos\n2              flags\n <\/pre>\n<p>binlog\u306eversion\u306b\u3088\u3063\u3066\u5b9a\u7fa9\u304c\u5206\u5c90\u3057\u307e\u3059\u304c\u3001\u73fe\u72b6\u306eMySQL\u3067\u306flog pos, flags\u306f\u5fc5\u305a\u3064\u304f\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u4eca\u307e\u3067\u306eMySQL\u30d7\u30ed\u30c8\u30b3\u30eb\u3092Parse\u3057\u3066\u3044\u308c\u3070\u7c21\u5358\u306bParse\u51fa\u6765\u305d\u3046\u3067\u3059\u306d\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u65e9\u901fBinlog Event Header\u3092parse\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u3044\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><code>package main\n\nimport (\n    \"fmt\"\n    \"encoding\/binary\"\n    \"encoding\/hex\"\n)\n\nfunc main() {\n    buffer := []byte{\n        0x7e, 0x8d, 0x3b, 0x54, 0x0f, 0xe9, 0x03, 0x00,\n        0x00, 0x74, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00,\n        0x00, 0x00, 0x00, 0x04, 0x00, 0x35, 0x2e, 0x36, \n        0x2e, 0x31, 0x35, 0x2d, 0x6c, 0x6f, 0x67, 0x00, \n        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \n        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \n        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \n        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \n        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, \n        0x8d, 0x3b, 0x54, 0x13, 0x38, 0x0d, 0x00, 0x08, \n        0x00, 0x12, 0x00, 0x04, 0x04, 0x04, 0x04, 0x12, \n        0x00, 0x00, 0x5c, 0x00, 0x04, 0x1a, 0x08, 0x00, \n        0x00, 0x00, 0x08, 0x08, 0x08, 0x02, 0x00, 0x00, \n        0x00, 0x0a, 0x0a, 0x0a, 0x19, 0x19, 0x00, 0x01, \n        0xfa, 0xd5, 0x17, 0x2f,\n    }\n\n    offset := 0\n    timestamp := binary.LittleEndian.Uint32(buffer[offset:offset+4])\n    offset += 4\n    event_type := buffer[offset]\n    offset += 1\n    server_id := binary.LittleEndian.Uint32(buffer[offset:offset+4])\n    offset += 4\n    event_size := binary.LittleEndian.Uint32(buffer[offset:offset+4])\n    offset += 4\n    log_pos := binary.LittleEndian.Uint32(buffer[offset:offset+4])\n    flags := binary.LittleEndian.Uint16(buffer[offset:offset+2])\n    offset += 2\n\n    fmt.Printf(\"[timestamp]: %d\\n\", timestamp)\n    fmt.Printf(\"[event_type]: %d\\n\", event_type)\n    fmt.Printf(\"[server_id]: %d\\n\", server_id)\n    fmt.Printf(\"[event_size]: %d\\n\", event_size)\n    fmt.Printf(\"[log_pos]: %d\\n\", log_pos)\n    fmt.Printf(\"[flags]: %d\\n\", flags)\n    fmt.Printf(\"[payload]:\\n%s\", hex.Dump(buffer[offset:(offset+int(event_size)-19)]))\n}\n<\/code><\/pre>\n<p>\u6bce\u5ea6\u306e\u901a\u308a\u3001PlayGround\u3067\u8a66\u305b\u307e\u3059\u3002\u5b9f\u884c\u7d50\u679c\u306f\u4e0b\u8a18\u306e\u901a\u308a\u3067\u3059\u3002<br \/>\n<a href=\"http:\/\/play.golang.org\/p\/2QL3ZD7b29\">http:\/\/play.golang.org\/p\/2QL3ZD7b29<\/a><\/p>\n<pre><code>[timestamp]: 1413188990\n[event_type]: 15\n[server_id]: 1001\n[event_size]: 116\n[log_pos]: 120\n[flags]: 120\n[payload]:\n00000000  00 00 00 00 04 00 35 2e  36 2e 31 35 2d 6c 6f 67  |......5.6.15-log|\n00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|\n00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|\n00000030  00 00 00 00 00 00 00 00  7e 8d 3b 54 13 38 0d 00  |........~.;T.8..|\n00000040  08 00 12 00 04 04 04 04  12 00 00 5c 00 04 1a 08  |...........\\....|\n00000050  00 00 00 08 08 08 02 00  00 00 0a 0a 0a 19 19 00  |................|\n00000060  01                                                |.|\n<\/code><\/pre>\n<p>Parse\u51fa\u6765\u3066\u305d\u3046\u3067\u3059\u306d\uff01\u3053\u308c\u3067\u4e2d\u8eab\u306f\u3068\u3082\u304b\u304f\u3001Binlog\u304c\u8aad\u307f\u9032\u3081\u3089\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<h2>Binlog Event Type<\/h2>\n<p>\u3072\u3068\u307e\u305aBinlog\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u3092Parse\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u304c\u3001\u5148\u307b\u3069Parse\u3057\u305f0x0f(15)\u306eEvent Type\u3068\u306f\u306a\u3093\u3060\u3063\u305f\u306e\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n<p>\u5168\u90e8\u306eEvent\u3092\u89e3\u8aac\u3057\u3066\u3044\u304f\u7d50\u69cb\u306a\u91cf\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u306e\u3067<br \/>\n<a href=\"http:\/\/dev.mysql.com\/doc\/internals\/en\/binlog-event-type.html\">http:\/\/dev.mysql.com\/doc\/internals\/en\/binlog-event-type.html<\/a> \u304b\u3089\u79c1\u304c\u8208\u5473\u6709\u308b\u90e8\u5206\u3060\u3051\u629c\u7c8b\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \" >\n0x02 QUERY_EVENT\n0x04 ROTATE_EVENT\n0x0f FORMAT_DESCRIPTION_EVENT\n<\/pre>\n<p>\u3068\u3001\u3053\u308c\u3050\u3089\u3044\u3067\u3059\u304b\u306d\u3002\u305b\u3063\u304b\u304fBinlog\u3092parse\u3059\u308b\u306e\u3067\u3059\u3057\u81ea\u529b\u3067\u30af\u30a8\u30ea\u304c\u898b\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u305f\u3044\u3067\u3059\u3088\u306d(mysqlbinlog\u3067query\u307f\u308c\u307e\u3059\u304c\u3001\u307e\u30fc\u305d\u308c\u306f\u304a\u3044\u3068\u3044\u3066)\u3002\u3042\u3068\u306fFORMAT DESCRIPTION EVENT\u3068ROTATE EVENT\u3050\u3089\u3044\u304c\u308f\u304b\u308c\u3070\u3068\u308a\u3042\u3048\u305a\u809d\u306f\u5206\u304b\u308a\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>\u305d\u308c\u3067\u306fFormat Description Event\u3092\u898b\u3066\u3044\u304d\u307e\u3059<\/p>\n<h3>Format Description Event<\/h3>\n<p><a href=\"http:\/\/dev.mysql.com\/doc\/internals\/en\/format-description-event.html\">http:\/\/dev.mysql.com\/doc\/internals\/en\/format-description-event.html<\/a> Format Description Event\u306fbinlog version 4\u306b\u304a\u3044\u3066\u6700\u521d\u306e\u30a4\u30d9\u30f3\u30c8\u3067\u3001binlog format\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3084, binlog\u3092\u4f5c\u6210\u3057\u305fMySQL Server\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u60c5\u5831\u306a\u3069\u304c\u5165\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u7d30\u304b\u3044\u8a71\u306f\u7f6e\u3044\u3068\u3044\u3066\u3001\u307e\u305a\u306fParse\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"lang:default decode:true \" >\n    2             binlog-version\n    string[50]       mysql-server version\n    4                create timestamp\n    1                event header length\n    string[p]        event type header lengths\n<\/pre>\n<p>event type header lengths\u306e\u9805\u76ee\u3060\u3051\u304c\u89e3\u91c8\u304c\u3057\u3065\u3089\u3044\u4e0a\u306b\u89e3\u8aac\u304c\u5c11\u306a\u3044\u3067\u3059\u306d\u3002<\/p>\n<p>\u3053\u3046\u3044\u3063\u305f\u8aac\u660e\u304c\u5c11\u306a\u3044\u306e\u306fMySQL\u306b\u9650\u3089\u305a\u3088\u304f\u3042\u308b\u30d1\u30bf\u30fc\u30f3\u306a\u3093\u3067\u3059\u304c\u3001\u3044\u304f\u3064\u304b\u5b9f\u969b\u306e\u30d0\u30a4\u30ca\u30ea\u3092\u773a\u3081\u3066\u3044\u308c\u3070\u306a\u3093\u3068\u306a\u304f\u7406\u89e3\u3057\u3084\u3059\u3044\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u3056\u3063\u304f\u308a\u3068\u8aac\u660e\u3059\u308b\u3068\u3053\u306e\u9805\u76ee\u306fuint8\u306e\u914d\u5217\u3067\u5404\u7a2eEvent Header\u306e\u5927\u304d\u3055\u3092\u660e\u8a18\u3060\u3051\u306e\u3082\u306e\u3067\u3059(\u914d\u5217\u306eOffset\u306fEventType - 1\u3068\u3044\u3046\u4eee\u5b9a\u306b\u306a\u3063\u3066\u3044\u307e\u3059)<br \/>\n\u4f8b\u3048\u3070\u5148\u307b\u3069\u306e0x0f format description\u306e\u5927\u304d\u3055\u304c\u3069\u308c\u304f\u3089\u3044\u304b\u3001\u3068\u3044\u3046\u5834\u5408\u306fEvent Type - 1\u306eOffset\u3092\u898b\u308c\u3070\u5927\u304d\u3055\u304c\u66f8\u3044\u3066\u3042\u308b\u3001\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>Binlog Header\u3092Parse\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u306bFormat Description Event\u3092Parse\u3059\u308b\u6a5f\u80fd\u3092\u8ffd\u52a0\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"lang:go decode:true \" >package main\n\nimport (\n    \"fmt\"\n    \"encoding\/binary\"\n    \"encoding\/hex\"\n)\n\ntype EventType int\n\nconst (\n    UNKNOWN_EVENT EventType = 0x00\n    START_EVENT_V3 EventType = 0x01\n    QUERY_EVENT EventType = 0x02\n    STOP_EVENT EventType = 0x03\n    ROTATE_EVENT EventType = 0x04\n    INTVAR_EVENT EventType = 0x05\n    LOAD_EVENT EventType = 0x06\n    SLAVE_EVENT EventType = 0x07\n    CREATE_FILE_EVENT EventType = 0x08\n    APPEND_BLOCK_EVENT EventType = 0x09\n    EXEC_LOAD_EVENT EventType = 0x0a\n    DELETE_FILE_EVENT EventType = 0x0b\n    NEW_LOAD_EVENT EventType = 0x0c\n    RAND_EVENT EventType = 0x0d\n    USER_VAR_EVENT EventType = 0x0e\n    FORMAT_DESCRIPTION_EVENT EventType = 0x0f\n    XID_EVENT EventType = 0x10\n    BEGIN_LOAD_QUERY_EVENT EventType = 0x11\n    EXECUTE_LOAD_QUERY_EVENT EventType = 0x12\n    TABLE_MAP_EVENT EventType = 0x13\n    WRITE_ROWS_EVENTv0 EventType = 0x14\n    UPDATE_ROWS_EVENTv0 EventType = 0x15\n    DELETE_ROWS_EVENTv0 EventType = 0x16\n    WRITE_ROWS_EVENTv1 EventType = 0x17\n    UPDATE_ROWS_EVENTv1 EventType = 0x18\n    DELETE_ROWS_EVENTv1 EventType = 0x19\n    INCIDENT_EVENT EventType = 0x1a\n    HEARTBEAT_EVENT EventType = 0x1b\n    IGNORABLE_EVENT EventType = 0x1c\n    ROWS_QUERY_EVENT EventType = 0x1d\n    WRITE_ROWS_EVENTv2 EventType = 0x1e\n    UPDATE_ROWS_EVENTv2 EventType = 0x1f\n    DELETE_ROWS_EVENTv2 EventType = 0x20\n    GTID_EVENT EventType = 0x21\n    ANONYMOUS_GTID_EVENT EventType = 0x22\n    PREVIOUS_GTIDS_EVENT EventType = 0x23\n)\n\nfunc main() {\n    buffer := []byte{\n        0x7e, 0x8d, 0x3b, 0x54, 0x0f, 0xe9, 0x03, 0x00,\n        0x00, 0x74, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00,\n        0x00, 0x00, 0x00, 0x04, 0x00, 0x35, 0x2e, 0x36, \n        0x2e, 0x31, 0x35, 0x2d, 0x6c, 0x6f, 0x67, 0x00, \n        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \n        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \n        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \n        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \n        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, \n        0x8d, 0x3b, 0x54, 0x13, 0x38, 0x0d, 0x00, 0x08, \n        0x00, 0x12, 0x00, 0x04, 0x04, 0x04, 0x04, 0x12, \n        0x00, 0x00, 0x5c, 0x00, 0x04, 0x1a, 0x08, 0x00, \n        0x00, 0x00, 0x08, 0x08, 0x08, 0x02, 0x00, 0x00, \n        0x00, 0x0a, 0x0a, 0x0a, 0x19, 0x19, 0x00, 0x01, \n        0xfa, 0xd5, 0x17, 0x2f,\n    }\n\n    offset := 0\n    timestamp := binary.LittleEndian.Uint32(buffer[offset:offset+4])\n    offset += 4\n    event_type := buffer[offset]\n    offset += 1\n    server_id := binary.LittleEndian.Uint32(buffer[offset:offset+4])\n    offset += 4\n    event_size := binary.LittleEndian.Uint32(buffer[offset:offset+4])\n    offset += 4\n    log_pos := binary.LittleEndian.Uint32(buffer[offset:offset+4])\n    offset += 4\n    flags := binary.LittleEndian.Uint16(buffer[offset:offset+2])\n    offset += 2\n\n    fmt.Printf(\"[timestamp]: %d\\n\", timestamp)\n    fmt.Printf(\"[event_type]: %d\\n\", event_type)\n    fmt.Printf(\"[server_id]: %d\\n\", server_id)\n    fmt.Printf(\"[event_size]: %d\\n\", event_size)\n    fmt.Printf(\"[log_pos]: %d\\n\", log_pos)\n    fmt.Printf(\"[flags]: %d\\n\", flags)\n    fmt.Printf(\"[payload]:\\n%s\\n\", hex.Dump(buffer[offset:(offset+int(event_size)-19)]))\n\n    payload := buffer[offset:(offset+int(event_size)-19)]\n\n    offset = 0\n    binlog_version := binary.LittleEndian.Uint16(payload[offset:offset+2])\n    offset += 2\n    server_version := payload[offset:offset+50]\n    offset += 50\n    create_timestamp := binary.LittleEndian.Uint32(payload[offset:offset+4])\n    offset += 4\n    event_header_length := payload[offset]\n    offset += 1\n\n    fmt.Printf(\"[binlog_version]: %d\\n\", binlog_version)\n    fmt.Printf(\"[server_version]: %s\\n\", server_version)\n    fmt.Printf(\"[create_timestamp]: %d\\n\", create_timestamp)\n    fmt.Printf(\"[event_header_lengthphp]: %d\\n\", event_header_length)\n    fmt.Printf(\"[lengths]:\\n%s\", hex.Dump(payload[offset:]))\n\n    for i := 0; i+offset &lt; len(payload) || i &lt;= (int)(PREVIOUS_GTIDS_EVENT); i++ {\n        fmt.Printf(\"  Event %d Length: %d\\n\", i + 1, payload[offset+i])\n    }\n}\n<\/pre>\n<p>Format Description Event\u3092Parse\u3059\u308b\u3053\u3068\u3067\u5404\u30a4\u30d9\u30f3\u30c8\u306e\u30b5\u30a4\u30ba\u304c\u308f\u304b\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<br \/>\n<a href=\"http:\/\/play.golang.org\/p\/m8cFKfsLIG\">http:\/\/play.golang.org\/p\/m8cFKfsLIG<\/a><\/p>\n<p>\u305d\u3044\u3067\u306f\u6b21\u3059\u3059\u307f\u307e\u3059\u3002<\/p>\n<h2>Rotate Event<\/h2>\n<p>Replication\u3092\u3057\u3066\u3044\u308b\u3068binlog\u304crotation\u3057\u3066\u3044\u308b\u3053\u3068\u306b\u6c17\u304c\u3064\u304f\u3068\u601d\u3044\u307e\u3059\u3002\u3053\u306eRotate Event\u3067\u306f\u4e3b\u306bbinlog\u306erotation\u3092\u884c\u3046\u6642\u306b\u3069\u3046\u3057\u305f\u3089\u3088\u3044\u304b\u3001\u3068\u3044\u3046\u3053\u3068\u304c\u8a18\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\n<a href=\"http:\/\/dev.mysql.com\/doc\/internals\/en\/rotate-event.html\">http:\/\/dev.mysql.com\/doc\/internals\/en\/rotate-event.html<\/a>\u3000\u304b\u3089\u629c\u7c8b\u3059\u308b\u3068<\/p>\n<pre class=\"lang:default decode:true \" >\n    8              position\n    string[p]      name of the next binlog\n<\/pre>\n<p>binlog version 1\u306f\u73fe\u72b6\u306eversion\u3067\u306f\u306a\u3044\u306e\u3067\u7701\u3044\u3066\u304a\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>uint64\u306eposition\u3068\u6b21\u306ebinlog file\u306e\u540d\u524d\u304c\u5165\u3063\u3066\u3044\u308b\u3060\u3051\u306a\u306e\u3067parse\u7c21\u5358\u3067\u3059\u306d\u3002\u9069\u5f53\u306b\u66f8\u304f\u3068\u3053\u3093\u306a\u611f\u3058\u3067\u3057\u3087\u3046\u304b<\/p>\n<pre><code>position := binary.LittleEndian.Uint64(buffer[0:8])\nname := buffer[8:]\n<\/code><\/pre>\n<p>\u5b9f\u969bRotate Event\u306fRotation\u4ee5\u5916\u306e\u7528\u9014\u306b\u3082\u4f7f\u308f\u308c\u305f\u308a\u3059\u308b\u306e\u3067\u3059\u304c\u3001\u73fe\u72b6\u306f\u3068\u308a\u3042\u3048\u305aParse\u3057\u3066\u307f\u308b\u4e8b\u304c\u76ee\u7684\u306a\u306e\u3067\u307e\u305f\u5f8c\u65e5\u306b\u3067\u3082\u89e3\u8aac\u3057\u3088\u3046\u3068\u601d\u3044\u307e\u3059<\/p>\n<h2>Query Event<\/h2>\n<p>\u3055\u3041\u3001\u3088\u3046\u3084\u304f\u304a\u307e\u3061\u304b\u306d\u306eQuery Event\u3067\u3059\u3002<br \/>\n<a href=\"http:\/\/dev.mysql.com\/doc\/internals\/en\/query-event.html\">http:\/\/dev.mysql.com\/doc\/internals\/en\/query-event.html<\/a><\/p>\n<pre class=\"lang:default decode:true \" >\n    [Post Header]\n    4              slave_proxy_id\n    4              execution time\n    1              schema length\n    2              error-code\n      if binlog-version \u2265 4:\n    2              status-vars length\n    [Payload]\n    string[$len]   status-vars\n    string[$len]   schema\n    1              [00]\n    string[EOF]    query\n<\/pre>\n<p>\u3053\u3053\u3089\u3078\u3093\u307e\u3067\u3084\u3063\u3066\u304d\u305f\u7686\u3055\u3093\u3067\u3042\u308c\u3070\u3082\u3046\u30b5\u30af\u30b5\u30af\u3068Parse\u3067\u304d\u308b\u306f\u305a\u3067\u3059\u3002\u6c7a\u3057\u3066\u89e3\u8aac\u304c\u9762\u5012\u306b\u306a\u3063\u3066\u304d\u305f\u308f\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u30e8!?<\/p>\n<p>\u4e00\u7b87\u6240status-vars\u306e\u90e8\u5206\u3060\u3051\u5206\u304b\u308a\u3065\u3089\u3044\u306e\u3067\u88dc\u8db3\u3057\u3066\u304a\u304d\u307e\u3059\u3002<br \/>\nstatus-vars\u306f\u9023\u7d9a\u3057\u305fbyte\u3067\u8868\u3057\u305fkey value\u3067key\u304c1byte, value size\u306fkey\u306b\u3088\u3063\u3066\u4e8b\u524d\u306b\u5b9a\u7fa9\u3055\u308c\u305f\u9577\u3055\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070status-vars\u306eoffset 0\u304c0x00\u306e\u5834\u5408\u306fKey\u304cQ_FLAGS2_CODE\u3068\u306a\u308a\u3001Value\u306e\u9577\u3055\u306f4byte\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u307e\u30fc\u3001\u3076\u3063\u3061\u3083\u3051\u3053\u308c\u3089\u306estatus-vars\u306e\u60c5\u5831\u306f\u81ea\u524d\u3067Replication\u3092\u3057\u3088\u3046\u3068\u304b\u3044\u3063\u305f\u5834\u5408\u4ee5\u5916\u306b\u306f\u4e0d\u8981\u306a\u60c5\u5831\u3067\u3059\u3057\u5b9f\u88c5\u3059\u308b\u306e\u304c\u7d50\u69cb\u9762\u5012\u3060\u3063\u305f\u308a\u3059\u308b\u306e\u3067\u30b9\u30eb\u30fc\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>\u7d42\u308f\u308a\u306b<\/h2>\n<p>Binlog File\u306eParse\u3092\u901a\u3057\u3066Event\u306b\u3064\u3044\u3066\u5b66\u3076\u3053\u3068\u304c\u51fa\u6765\u307e\u3057\u305f\u3002<\/p>\n<p>\u5b9f\u969b\u306fmysqlbinlog\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u3046\u3060\u3051\u3067\u5341\u5206\u306a\u3093\u3067\u3059\u304c\u3001\u30d5\u30a1\u30a4\u30eb\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u307e\u3067\u8a73\u3057\u304f\u306a\u3063\u3066\u3044\u308b\u3068binlog\u304c\u58ca\u308c\u305f\u6642\u3082\u30d0\u30a4\u30ca\u30ea\u3092\u773a\u3081\u308c\u3070\u3069\u3053\u304c\u60aa\u3044\u306e\u304b\u60f3\u50cf\u304c\u3064\u304f\u3088\u3046\u306b\u306a\u308b\u306e\u3067\u899a\u3048\u3066\u304a\u3044\u3066\u640d\u306f\u306a\u3044\u3067\u3059\u306d\u3002<\/p>\n<p>\u4eca\u65e5\u8aac\u660e\u3057\u305f\u5185\u5bb9\u306e\u30b5\u30f3\u30d7\u30eb\u3092 <a href=\"http:\/\/play.golang.org\/p\/-icwpXv2J-\">\u3053\u3053<\/a> \u306b\u304a\u3044\u3066\u304a\u304d\u307e\u3059\u306e\u3067\u8208\u5473\u304c\u3042\u308b\u4eba\u306f\u66f8\u3044\u3066\u307f\u3066\u7b54\u3048\u5408\u308f\u305b\u3057\u3066\u307f\u305f\u308a\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u305d\u3046\u305d\u3046\u3001\u3053\u3046\u3044\u3063\u305f\u65b0\u3057\u3044\u4e8b\u3068\u304b\u77e5\u3089\u306a\u3044\u4e8b\u306b\u3064\u3044\u3066\u3084\u3089\u306a\u3044\u7406\u7531\u3068\u304b\u308f\u304b\u3089\u306a\u3044\u7406\u7531\u3053\u306d\u304f\u308a\u56de\u3059\u306e\u306f\u305d\u308c\u306f\u305d\u308c\u3067\u697d\u3057\u3044\u3093\u3067\u3059\u304c\u3001\u307c\u304f\u305f\u3061\u5275\u9020\u7684\u306a\u958b\u767a\u8005\u3067\u3059\u3057\u3001\u3054\u305f\u3054\u305f\u3044\u3063\u3066\u306d\u30fc\u3067\u30b3\u30fc\u30c9\u66f8\u3053\u3046\u3063\u3066\u59ff\u52e2\u3063\u3066\u5927\u4e8b\u3060\u3063\u305f\u308a\u3057\u307e\u3059\u3002\u6700\u521d\u306f\u96e3\u3057\u3044\u304b\u3082\u3057\u308c\u306a\u3044\u3051\u3069\u3061\u3087\u3063\u3068\u30c8\u30e9\u30a4\u3057\u305f\u3089\u7d76\u5bfe\u3067\u304d\u308b\u304b\u3089\u3002<br \/>\n\u3053\u3046\u3044\u3063\u305f\u4e8b\u306f\u300c\u3084\u308b\u304b\u3084\u3063\u305f\u304b\u300d\uff08\u3084\u308b\u304b\u3084\u3089\u306a\u3044\u304b\u3001\u3058\u3083\u306a\u3044\u3088\uff09\u306a\u306e\u3067\u3069\u3093\u3069\u3093\u66f8\u3044\u3066\u5f15\u304d\u51fa\u3057\u5897\u3084\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3002<\/p>\n<p>\u305d\u3093\u306a\u3053\u3068\u306f\u3055\u3066\u304a\u304d\u3001\u6b21\u56de\u306fBinlog Event\u306e\u4e2d\u3067\u3082Row Based Replication\u90e8\u5206\u306b\u7126\u70b9\u3092\u5f53\u3066\u3066\u89e3\u8aac\u3057\u3066\u884c\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002\u5e74\u672b\u9032\u884c&amp;\u79c1\u304cAdvent Calendar\u306b\u53c2\u52a0\u3057\u3059\u304e\u3066\u3057\u307e\u3044\u6b21\u306e\u8a18\u4e8b\u307e\u3067\u671f\u9593\u304c\u3042\u3044\u3066\u3057\u307e\u3046\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u3044\u307e\u3057\u3070\u3089\u304f\u304a\u5f85\u3061\u3044\u305f\u3060\u3051\u308c\u3070\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h1>Treasure Data Advent Calendar\u3078\u306e\u304a\u8a98\u3044<\/h1>\n<p>\u4eca\u5e74\u306f<a href=\"http:\/\/qiita.com\/advent-calendar\/2014\/td\">http:\/\/qiita.com\/advent-calendar\/2014\/td<\/a> \u3068\u3044\u3046\u306e\u3092\u4e3b\u50ac\u3057\u3066\u304a\u308a\u307e\u3059\u306e\u3067\u3001\u307f\u306a\u3055\u3093\u3082\u662f\u975e\u662f\u975e\u3054\u53c2\u52a0\u3044\u305f\u3060\u3051\u308c\u3070\u3068\u601d\u3044\u307e\u3059\u3002\u79c1\u3082GREE\u3067\u5b9f\u969b\u306e\u73fe\u5834\u3067\u4f7f\u308f\u308c\u3066\u3044\u308b\u4e2d\u304b\u3089\u3061\u3087\u308d\u3061\u3087\u308d\u3068\u4e8b\u4f8b\u3092\u3054\u7d39\u4ecb\u3067\u304d\u308b\u3088\u3046\u306b\u8abf\u6574\u3059\u3059\u3081\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>TD\u4f7f\u3044\u59cb\u3081\u306e\u65b9\u3078\u306etips\u3084\u5b9f\u969b\u306e\u4e8b\u4f8b\u306a\u3069\u306e\u5171\u6709\u304c\u3067\u304d\u308c\u3070\u5e78\u3044\u3067\u3059\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u306a\u3093\u3068\u306a\u304f\u6c17\u5206\u3067\u59cb\u3081\u305fMySQL\u30d7\u30ed\u30c8\u30b3\u30eb\u5165\u9580\u3067\u3059\u304c\u4eca\u56de\u306f\u5c11\u3057\u8da3\u5411\u3092\u304b\u3048\u3066binlog format\u306b\u3064\u3044\u3066\u66f8\u3044\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002 MySQL\u3067\u306e\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u5358\u4f4d\u3068\u3057\u3066\u4f7f\u308f\u308c\u3066\u3044\u308bbinlog\u3067\u3059\u304c\u3001\u305d [&hellip;]<\/p>\n","protected":false},"author":100,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[80,17],"class_list":["post-11542","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","tag-golang","tag-mysql"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/11542","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/users\/100"}],"replies":[{"embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/comments?post=11542"}],"version-history":[{"count":3,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/11542\/revisions"}],"predecessor-version":[{"id":11571,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/11542\/revisions\/11571"}],"wp:attachment":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/media?parent=11542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/categories?post=11542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/tags?post=11542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}