MCPcopy Create free account
hub / github.com/Tencent/phxsql / recover

Method recover

phx_percona/percona/sql/binlog.cc:7594–7695  ·  view source on GitHub ↗

MYSQLD server recovers from last crashed binlog. @param log IO_CACHE of the crashed binlog. @param fdle Format_description_log_event of the crashed binlog. @param valid_pos The position of the last valid transaction or event(non-transaction) of the crashed binlog. @retval 0 ok @retval 1 error */

Source from the content-addressed store, hash-verified

7592 1 error
7593*/
7594int MYSQL_BIN_LOG::recover(IO_CACHE *log, Format_description_log_event *fdle,
7595 my_off_t *valid_pos)
7596{
7597 Log_event *ev;
7598 HASH xids;
7599 MEM_ROOT mem_root;
7600 /*
7601 The flag is used for handling the case that a transaction
7602 is partially written to the binlog.
7603 */
7604 bool in_transaction= FALSE;
7605
7606 if (! fdle->is_valid() ||
7607 my_hash_init(&xids, &my_charset_bin, TC_LOG_PAGE_SIZE/3, 0,
7608 sizeof(my_xid), 0, 0, MYF(0)))
7609 goto err1;
7610
7611 init_alloc_root(&mem_root, TC_LOG_PAGE_SIZE, TC_LOG_PAGE_SIZE);
7612
7613 while ((ev= Log_event::read_log_event(log, 0, fdle, TRUE))
7614 && ev->is_valid())
7615 {
7616 if (ev->get_type_code() == QUERY_EVENT &&
7617 !strcmp(((Query_log_event*)ev)->query, "BEGIN"))
7618 in_transaction= TRUE;
7619
7620 if (ev->get_type_code() == QUERY_EVENT &&
7621 !strcmp(((Query_log_event*)ev)->query, "COMMIT"))
7622 {
7623 DBUG_ASSERT(in_transaction == TRUE);
7624 in_transaction= FALSE;
7625 }
7626 else if (ev->get_type_code() == XID_EVENT)
7627 {
7628 DBUG_ASSERT(in_transaction == TRUE);
7629 in_transaction= FALSE;
7630 Xid_log_event *xev=(Xid_log_event *)ev;
7631 uchar *x= (uchar *) memdup_root(&mem_root, (uchar*) &xev->xid,
7632 sizeof(xev->xid));
7633 if (!x || my_hash_insert(&xids, x))
7634 goto err2;
7635 }
7636
7637 /*
7638 Recorded valid position for the crashed binlog file
7639 which did not contain incorrect events. The following
7640 positions increase the variable valid_pos:
7641
7642 1 -
7643 ...
7644 <---> HERE IS VALID <--->
7645 GTID
7646 BEGIN
7647 ...
7648 COMMIT
7649 ...
7650
7651 2 -

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected