~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/log/log0recv.c

  • Committer: Stewart Smith
  • Date: 2008-07-09 01:40:54 UTC
  • mfrom: (105 drizzle)
  • mto: This revision was merged to the branch mainline in revision 111.
  • Revision ID: stewart@flamingspork.com-20080709014054-xfgfzirbhqzrzkkj
mergeĀ fromĀ mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
1529
1529
        mutex_exit(&(recv_sys->mutex));
1530
1530
}
1531
1531
 
1532
 
/* This page is allocated from the buffer pool and used in the function
1533
 
below */
1534
 
static page_t* recv_backup_application_page     = NULL;
1535
 
 
1536
 
/***********************************************************************
1537
 
Applies log records in the hash table to a backup. */
1538
 
 
1539
 
void
1540
 
recv_apply_log_recs_for_backup(void)
1541
 
/*================================*/
1542
 
{
1543
 
        recv_addr_t*    recv_addr;
1544
 
        ulint           n_hash_cells;
1545
 
        byte*           page;
1546
 
        ulint           actual_size;
1547
 
        ibool           success;
1548
 
        ulint           error;
1549
 
        ulint           i;
1550
 
 
1551
 
        recv_sys->apply_log_recs = TRUE;
1552
 
        recv_sys->apply_batch_on = TRUE;
1553
 
 
1554
 
        if (recv_backup_application_page == NULL) {
1555
 
                recv_backup_application_page = buf_frame_alloc();
1556
 
        }
1557
 
 
1558
 
        page = recv_backup_application_page;
1559
 
 
1560
 
        fputs("InnoDB: Starting an apply batch of log records"
1561
 
              " to the database...\n"
1562
 
              "InnoDB: Progress in percents: ", stderr);
1563
 
 
1564
 
        n_hash_cells = hash_get_n_cells(recv_sys->addr_hash);
1565
 
 
1566
 
        for (i = 0; i < n_hash_cells; i++) {
1567
 
                /* The address hash table is externally chained */
1568
 
                recv_addr = hash_get_nth_cell(recv_sys->addr_hash, i)->node;
1569
 
 
1570
 
                while (recv_addr != NULL) {
1571
 
 
1572
 
                        if (!fil_tablespace_exists_in_mem(recv_addr->space)) {
1573
 
#if 0
1574
 
                                fprintf(stderr,
1575
 
                                        "InnoDB: Warning: cannot apply"
1576
 
                                        " log record to"
1577
 
                                        " tablespace %lu page %lu,\n"
1578
 
                                        "InnoDB: because tablespace with"
1579
 
                                        " that id does not exist.\n",
1580
 
                                        recv_addr->space, recv_addr->page_no);
1581
 
#endif
1582
 
                                recv_addr->state = RECV_PROCESSED;
1583
 
 
1584
 
                                ut_a(recv_sys->n_addrs);
1585
 
                                recv_sys->n_addrs--;
1586
 
 
1587
 
                                goto skip_this_recv_addr;
1588
 
                        }
1589
 
 
1590
 
                        /* We simulate a page read made by the buffer pool, to
1591
 
                        make sure the recovery apparatus works ok, for
1592
 
                        example, the buf_frame_align() function. We must init
1593
 
                        the block corresponding to buf_pool->frame_zero
1594
 
                        (== page). */
1595
 
 
1596
 
                        buf_page_init_for_backup_restore(
1597
 
                                recv_addr->space, recv_addr->page_no,
1598
 
                                buf_block_align(page));
1599
 
 
1600
 
                        /* Extend the tablespace's last file if the page_no
1601
 
                        does not fall inside its bounds; we assume the last
1602
 
                        file is auto-extending, and ibbackup copied the file
1603
 
                        when it still was smaller */
1604
 
 
1605
 
                        success = fil_extend_space_to_desired_size(
1606
 
                                &actual_size,
1607
 
                                recv_addr->space, recv_addr->page_no + 1);
1608
 
                        if (!success) {
1609
 
                                fprintf(stderr,
1610
 
                                        "InnoDB: Fatal error: cannot extend"
1611
 
                                        " tablespace %lu to hold %lu pages\n",
1612
 
                                        recv_addr->space, recv_addr->page_no);
1613
 
 
1614
 
                                exit(1);
1615
 
                        }
1616
 
 
1617
 
                        /* Read the page from the tablespace file using the
1618
 
                        fil0fil.c routines */
1619
 
 
1620
 
                        error = fil_io(OS_FILE_READ, TRUE, recv_addr->space,
1621
 
                                       recv_addr->page_no, 0, UNIV_PAGE_SIZE,
1622
 
                                       page, NULL);
1623
 
                        if (error != DB_SUCCESS) {
1624
 
                                fprintf(stderr,
1625
 
                                        "InnoDB: Fatal error: cannot read"
1626
 
                                        " from tablespace"
1627
 
                                        " %lu page number %lu\n",
1628
 
                                        (ulong) recv_addr->space,
1629
 
                                        (ulong) recv_addr->page_no);
1630
 
 
1631
 
                                exit(1);
1632
 
                        }
1633
 
 
1634
 
                        /* Apply the log records to this page */
1635
 
                        recv_recover_page(TRUE, FALSE, page, recv_addr->space,
1636
 
                                          recv_addr->page_no);
1637
 
 
1638
 
                        /* Write the page back to the tablespace file using the
1639
 
                        fil0fil.c routines */
1640
 
 
1641
 
                        buf_flush_init_for_writing(
1642
 
                                page, mach_read_from_8(page + FIL_PAGE_LSN),
1643
 
                                recv_addr->space, recv_addr->page_no);
1644
 
 
1645
 
                        error = fil_io(OS_FILE_WRITE, TRUE, recv_addr->space,
1646
 
                                       recv_addr->page_no, 0, UNIV_PAGE_SIZE,
1647
 
                                       page, NULL);
1648
 
skip_this_recv_addr:
1649
 
                        recv_addr = HASH_GET_NEXT(addr_hash, recv_addr);
1650
 
                }
1651
 
 
1652
 
                if ((100 * i) / n_hash_cells
1653
 
                    != (100 * (i + 1)) / n_hash_cells) {
1654
 
                        fprintf(stderr, "%lu ",
1655
 
                                (ulong) ((100 * i) / n_hash_cells));
1656
 
                        fflush(stderr);
1657
 
                }
1658
 
        }
1659
 
 
1660
 
        recv_sys_empty_hash();
1661
 
}
1662
1532
 
1663
1533
/***********************************************************************
1664
1534
Tries to parse a single log record and returns its length. */
1757
1627
}
1758
1628
 
1759
1629
/***********************************************************
1760
 
Checks that the parser recognizes incomplete initial segments of a log
1761
 
record as incomplete. */
1762
 
 
1763
 
void
1764
 
recv_check_incomplete_log_recs(
1765
 
/*===========================*/
1766
 
        byte*   ptr,    /* in: pointer to a complete log record */
1767
 
        ulint   len)    /* in: length of the log record */
1768
 
{
1769
 
        ulint   i;
1770
 
        byte    type;
1771
 
        ulint   space;
1772
 
        ulint   page_no;
1773
 
        byte*   body;
1774
 
 
1775
 
        for (i = 0; i < len; i++) {
1776
 
                ut_a(0 == recv_parse_log_rec(ptr, ptr + i, &type, &space,
1777
 
                                             &page_no, &body));
1778
 
        }
1779
 
}
1780
 
 
1781
 
/***********************************************************
1782
1630
Prints diagnostic info of corrupt log. */
1783
1631
static
1784
1632
void