~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/trx/trx0sys.c

  • Committer: Andrew Hutchings
  • Date: 2010-12-15 18:59:55 UTC
  • mto: This revision was merged to the branch mainline in revision 2006.
  • Revision ID: andrew@linuxjedi.co.uk-20101215185955-q12lkja8hdnpjqg7
Make the test look for drizzleadmin failure instead of success as this test is not possible to fix for success on our FreeBSD 8.0 box

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (C) 1996, 2010, Innobase Oy. All Rights Reserved.
 
3
Copyright (c) 1996, 2010, Innobase Oy. All Rights Reserved.
4
4
 
5
5
This program is free software; you can redistribute it and/or modify it under
6
6
the terms of the GNU General Public License as published by the Free Software
90
90
UNIV_INTERN char        trx_sys_mysql_bin_log_name[TRX_SYS_MYSQL_LOG_NAME_LEN];
91
91
/** Binlog file position, or -1 if unknown */
92
92
UNIV_INTERN ib_int64_t  trx_sys_mysql_bin_log_pos       = -1;
93
 
 
94
 
UNIV_INTERN drizzled::atomic<uint64_t> trx_sys_commit_id;
95
 
 
96
93
/* @} */
97
94
#endif /* !UNIV_HOTBACKUP */
98
95
 
181
178
        byte*   doublewrite)    /*!< in: pointer to the doublewrite buf
182
179
                                header on trx sys page */
183
180
{
184
 
  trx_doublewrite = static_cast<trx_doublewrite_t *>(mem_alloc(sizeof(trx_doublewrite_t)));
 
181
        trx_doublewrite = mem_alloc(sizeof(trx_doublewrite_t));
185
182
 
186
183
        /* Since we now start to use the doublewrite buffer, no need to call
187
184
        fsync() after every write to a data file */
198
195
                doublewrite + TRX_SYS_DOUBLEWRITE_BLOCK1);
199
196
        trx_doublewrite->block2 = mach_read_from_4(
200
197
                doublewrite + TRX_SYS_DOUBLEWRITE_BLOCK2);
201
 
        trx_doublewrite->write_buf_unaligned = static_cast<byte *>(ut_malloc(
202
 
                                                                             (1 + 2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) * UNIV_PAGE_SIZE));
 
198
        trx_doublewrite->write_buf_unaligned = ut_malloc(
 
199
                (1 + 2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) * UNIV_PAGE_SIZE);
203
200
 
204
 
        trx_doublewrite->write_buf = static_cast<byte *>(ut_align(
205
 
                                                                  trx_doublewrite->write_buf_unaligned, UNIV_PAGE_SIZE));
206
 
        trx_doublewrite->buf_block_arr = static_cast<buf_page_t **>(mem_alloc(
207
 
                                                                             2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * sizeof(void*)));
 
201
        trx_doublewrite->write_buf = ut_align(
 
202
                trx_doublewrite->write_buf_unaligned, UNIV_PAGE_SIZE);
 
203
        trx_doublewrite->buf_block_arr = mem_alloc(
 
204
                2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * sizeof(void*));
208
205
}
209
206
 
210
207
/****************************************************************//**
443
440
 
444
441
        /* We do the file i/o past the buffer pool */
445
442
 
446
 
        unaligned_read_buf = static_cast<byte *>(ut_malloc(2 * UNIV_PAGE_SIZE));
447
 
        read_buf = static_cast<byte *>(ut_align(unaligned_read_buf, UNIV_PAGE_SIZE));
 
443
        unaligned_read_buf = ut_malloc(2 * UNIV_PAGE_SIZE);
 
444
        read_buf = ut_align(unaligned_read_buf, UNIV_PAGE_SIZE);
448
445
 
449
446
        /* Read the trx sys header to check if we are using the doublewrite
450
447
        buffer */
677
674
        mtr_commit(&mtr);
678
675
}
679
676
 
 
677
/*****************************************************************//**
 
678
Updates the offset information about the end of the MySQL binlog entry
 
679
which corresponds to the transaction just being committed. In a MySQL
 
680
replication slave updates the latest master binlog position up to which
 
681
replication has proceeded. */
680
682
UNIV_INTERN
681
683
void
682
 
trx_sys_flush_commit_id(uint64_t commit_id, ulint field, mtr_t* mtr)
 
684
trx_sys_update_mysql_binlog_offset(
 
685
/*===============================*/
 
686
        const char*     file_name,/*!< in: MySQL log file name */
 
687
        ib_int64_t      offset, /*!< in: position in that log file */
 
688
        ulint           field,  /*!< in: offset of the MySQL log info field in
 
689
                                the trx sys header */
 
690
        mtr_t*          mtr)    /*!< in: mtr */
683
691
{
684
 
        trx_sysf_t*     sys_header;
685
 
  
 
692
        trx_sysf_t*     sys_header;
 
693
 
 
694
        if (ut_strlen(file_name) >= TRX_SYS_MYSQL_LOG_NAME_LEN) {
 
695
 
 
696
                /* We cannot fit the name to the 512 bytes we have reserved */
 
697
 
 
698
                return;
 
699
        }
 
700
 
686
701
        sys_header = trx_sysf_get(mtr);
687
702
 
688
 
        mlog_write_ull(sys_header + field + TRX_SYS_DRIZZLE_MAX_COMMIT_ID, 
689
 
                       commit_id, mtr);
 
703
        if (mach_read_from_4(sys_header + field
 
704
                             + TRX_SYS_MYSQL_LOG_MAGIC_N_FLD)
 
705
            != TRX_SYS_MYSQL_LOG_MAGIC_N) {
 
706
 
 
707
                mlog_write_ulint(sys_header + field
 
708
                                 + TRX_SYS_MYSQL_LOG_MAGIC_N_FLD,
 
709
                                 TRX_SYS_MYSQL_LOG_MAGIC_N,
 
710
                                 MLOG_4BYTES, mtr);
 
711
        }
 
712
 
 
713
        if (0 != strcmp((char*) (sys_header + field + TRX_SYS_MYSQL_LOG_NAME),
 
714
                        file_name)) {
 
715
 
 
716
                mlog_write_string(sys_header + field
 
717
                                  + TRX_SYS_MYSQL_LOG_NAME,
 
718
                                  (byte*) file_name, 1 + ut_strlen(file_name),
 
719
                                  mtr);
 
720
        }
 
721
 
 
722
        if (mach_read_from_4(sys_header + field
 
723
                             + TRX_SYS_MYSQL_LOG_OFFSET_HIGH) > 0
 
724
            || (offset >> 32) > 0) {
 
725
 
 
726
                mlog_write_ulint(sys_header + field
 
727
                                 + TRX_SYS_MYSQL_LOG_OFFSET_HIGH,
 
728
                                 (ulint)(offset >> 32),
 
729
                                 MLOG_4BYTES, mtr);
 
730
        }
 
731
 
 
732
        mlog_write_ulint(sys_header + field
 
733
                         + TRX_SYS_MYSQL_LOG_OFFSET_LOW,
 
734
                         (ulint)(offset & 0xFFFFFFFFUL),
 
735
                         MLOG_4BYTES, mtr);
690
736
}
691
737
 
692
 
 
 
738
/*****************************************************************//**
 
739
Stores the MySQL binlog offset info in the trx system header if
 
740
the magic number shows it valid, and print the info to stderr */
693
741
UNIV_INTERN
694
742
void
695
 
trx_sys_read_commit_id(void)
 
743
trx_sys_print_mysql_binlog_offset(void)
696
744
/*===================================*/
697
745
{
698
 
        trx_sysf_t*     sys_header;
699
 
        mtr_t           mtr;
700
 
 
701
 
        mtr_start(&mtr);
702
 
 
703
 
        sys_header = trx_sysf_get(&mtr);
704
 
 
705
 
        trx_sys_commit_id = mach_read_from_8(sys_header + TRX_SYS_DRIZZLE_LOG_INFO 
706
 
                                             + TRX_SYS_DRIZZLE_MAX_COMMIT_ID);
707
 
 
 
746
        trx_sysf_t*     sys_header;
 
747
        mtr_t           mtr;
 
748
        ulint           trx_sys_mysql_bin_log_pos_high;
 
749
        ulint           trx_sys_mysql_bin_log_pos_low;
 
750
 
 
751
        mtr_start(&mtr);
 
752
 
 
753
        sys_header = trx_sysf_get(&mtr);
 
754
 
 
755
        if (mach_read_from_4(sys_header + TRX_SYS_MYSQL_LOG_INFO
 
756
                             + TRX_SYS_MYSQL_LOG_MAGIC_N_FLD)
 
757
            != TRX_SYS_MYSQL_LOG_MAGIC_N) {
 
758
 
 
759
                mtr_commit(&mtr);
 
760
 
 
761
                return;
 
762
        }
 
763
 
 
764
        trx_sys_mysql_bin_log_pos_high = mach_read_from_4(
 
765
                sys_header + TRX_SYS_MYSQL_LOG_INFO
 
766
                + TRX_SYS_MYSQL_LOG_OFFSET_HIGH);
 
767
        trx_sys_mysql_bin_log_pos_low = mach_read_from_4(
 
768
                sys_header + TRX_SYS_MYSQL_LOG_INFO
 
769
                + TRX_SYS_MYSQL_LOG_OFFSET_LOW);
 
770
 
 
771
        trx_sys_mysql_bin_log_pos
 
772
                = (((ib_int64_t)trx_sys_mysql_bin_log_pos_high) << 32)
 
773
                + (ib_int64_t)trx_sys_mysql_bin_log_pos_low;
 
774
 
 
775
        ut_memcpy(trx_sys_mysql_bin_log_name,
 
776
                  sys_header + TRX_SYS_MYSQL_LOG_INFO
 
777
                  + TRX_SYS_MYSQL_LOG_NAME, TRX_SYS_MYSQL_LOG_NAME_LEN);
 
778
 
 
779
        fprintf(stderr,
 
780
                "InnoDB: Last MySQL binlog file position %lu %lu,"
 
781
                " file name %s\n",
 
782
                trx_sys_mysql_bin_log_pos_high, trx_sys_mysql_bin_log_pos_low,
 
783
                trx_sys_mysql_bin_log_name);
 
784
 
 
785
        mtr_commit(&mtr);
 
786
}
 
787
 
 
788
/*****************************************************************//**
 
789
Prints to stderr the MySQL master log offset info in the trx system header if
 
790
the magic number shows it valid. */
 
791
UNIV_INTERN
 
792
void
 
793
trx_sys_print_mysql_master_log_pos(void)
 
794
/*====================================*/
 
795
{
 
796
        trx_sysf_t*     sys_header;
 
797
        mtr_t           mtr;
 
798
 
 
799
        mtr_start(&mtr);
 
800
 
 
801
        sys_header = trx_sysf_get(&mtr);
 
802
 
 
803
        if (mach_read_from_4(sys_header + TRX_SYS_MYSQL_MASTER_LOG_INFO
 
804
                             + TRX_SYS_MYSQL_LOG_MAGIC_N_FLD)
 
805
            != TRX_SYS_MYSQL_LOG_MAGIC_N) {
 
806
 
 
807
                mtr_commit(&mtr);
 
808
 
 
809
                return;
 
810
        }
 
811
 
 
812
        fprintf(stderr,
 
813
                "InnoDB: In a MySQL replication slave the last"
 
814
                " master binlog file\n"
 
815
                "InnoDB: position %lu %lu, file name %s\n",
 
816
                (ulong) mach_read_from_4(sys_header
 
817
                                         + TRX_SYS_MYSQL_MASTER_LOG_INFO
 
818
                                         + TRX_SYS_MYSQL_LOG_OFFSET_HIGH),
 
819
                (ulong) mach_read_from_4(sys_header
 
820
                                         + TRX_SYS_MYSQL_MASTER_LOG_INFO
 
821
                                         + TRX_SYS_MYSQL_LOG_OFFSET_LOW),
 
822
                sys_header + TRX_SYS_MYSQL_MASTER_LOG_INFO
 
823
                + TRX_SYS_MYSQL_LOG_NAME);
 
824
        /* Copy the master log position info to global variables we can
 
825
        use in ha_innobase.cc to initialize glob_mi to right values */
 
826
 
 
827
        ut_memcpy(trx_sys_mysql_master_log_name,
 
828
                  sys_header + TRX_SYS_MYSQL_MASTER_LOG_INFO
 
829
                  + TRX_SYS_MYSQL_LOG_NAME,
 
830
                  TRX_SYS_MYSQL_LOG_NAME_LEN);
 
831
 
 
832
        trx_sys_mysql_master_log_pos
 
833
                = (((ib_int64_t) mach_read_from_4(
 
834
                            sys_header + TRX_SYS_MYSQL_MASTER_LOG_INFO
 
835
                            + TRX_SYS_MYSQL_LOG_OFFSET_HIGH)) << 32)
 
836
                + ((ib_int64_t) mach_read_from_4(
 
837
                           sys_header + TRX_SYS_MYSQL_MASTER_LOG_INFO
 
838
                           + TRX_SYS_MYSQL_LOG_OFFSET_LOW));
708
839
        mtr_commit(&mtr);
709
840
}
710
841
 
834
965
 
835
966
        mutex_enter(&kernel_mutex);
836
967
 
837
 
        trx_sys = static_cast<trx_sys_t *>(mem_alloc(sizeof(trx_sys_t)));
 
968
        trx_sys = mem_alloc(sizeof(trx_sys_t));
838
969
 
839
970
        sys_header = trx_sysf_get(&mtr);
840
971
 
1210
1341
}
1211
1342
 
1212
1343
#else /* !UNIV_HOTBACKUP */
 
1344
/*****************************************************************//**
 
1345
Prints to stderr the MySQL binlog info in the system header if the
 
1346
magic number shows it valid. */
 
1347
UNIV_INTERN
 
1348
void
 
1349
trx_sys_print_mysql_binlog_offset_from_page(
 
1350
/*========================================*/
 
1351
        const byte*     page)   /*!< in: buffer containing the trx
 
1352
                                system header page, i.e., page number
 
1353
                                TRX_SYS_PAGE_NO in the tablespace */
 
1354
{
 
1355
        const trx_sysf_t*       sys_header;
 
1356
 
 
1357
        sys_header = page + TRX_SYS;
 
1358
 
 
1359
        if (mach_read_from_4(sys_header + TRX_SYS_MYSQL_LOG_INFO
 
1360
                             + TRX_SYS_MYSQL_LOG_MAGIC_N_FLD)
 
1361
            == TRX_SYS_MYSQL_LOG_MAGIC_N) {
 
1362
 
 
1363
                fprintf(stderr,
 
1364
                        "ibbackup: Last MySQL binlog file position %lu %lu,"
 
1365
                        " file name %s\n",
 
1366
                        (ulong) mach_read_from_4(
 
1367
                                sys_header + TRX_SYS_MYSQL_LOG_INFO
 
1368
                                + TRX_SYS_MYSQL_LOG_OFFSET_HIGH),
 
1369
                        (ulong) mach_read_from_4(
 
1370
                                sys_header + TRX_SYS_MYSQL_LOG_INFO
 
1371
                                + TRX_SYS_MYSQL_LOG_OFFSET_LOW),
 
1372
                        sys_header + TRX_SYS_MYSQL_LOG_INFO
 
1373
                        + TRX_SYS_MYSQL_LOG_NAME);
 
1374
        }
 
1375
}
 
1376
 
1213
1377
 
1214
1378
/* THESE ARE COPIED FROM NON-HOTBACKUP PART OF THE INNODB SOURCE TREE
1215
1379
   (This code duplicaton should be fixed at some point!)
1431
1595
                        "InnoDB: Error: all read views were not closed"
1432
1596
                        " before shutdown:\n"
1433
1597
                        "InnoDB: %lu read views open \n",
1434
 
                        static_cast<ulint>(UT_LIST_GET_LEN(trx_sys->view_list)) - 1);
 
1598
                        UT_LIST_GET_LEN(trx_sys->view_list) - 1);
1435
1599
        }
1436
1600
 
1437
1601
        sess_close(trx_dummy_sess);