~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2010-10-28 17:12:01 UTC
  • mfrom: (1887.1.3 merge)
  • Revision ID: brian@tangent.org-20101028171201-baj6l1bnntn1s4ad
Merge in POTFILES changes.

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, 2009, 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
39
39
#include "srv0srv.h"
40
40
#include "trx0purge.h"
41
41
#include "log0log.h"
42
 
#include "log0recv.h"
43
42
#include "os0file.h"
44
43
#include "read0read.h"
45
44
 
90
89
UNIV_INTERN char        trx_sys_mysql_bin_log_name[TRX_SYS_MYSQL_LOG_NAME_LEN];
91
90
/** Binlog file position, or -1 if unknown */
92
91
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
92
/* @} */
97
93
#endif /* !UNIV_HOTBACKUP */
98
94
 
130
126
static const ulint      FILE_FORMAT_NAME_N
131
127
        = sizeof(file_format_name_map) / sizeof(file_format_name_map[0]);
132
128
 
133
 
#ifdef UNIV_PFS_MUTEX
134
 
/* Key to register the mutex with performance schema */
135
 
UNIV_INTERN mysql_pfs_key_t     trx_doublewrite_mutex_key;
136
 
UNIV_INTERN mysql_pfs_key_t     file_format_max_mutex_key;
137
 
#endif /* UNIV_PFS_MUTEX */
138
 
 
139
129
#ifndef UNIV_HOTBACKUP
140
130
/** This is used to track the maximum file format id known to InnoDB. It's
141
 
updated via SET GLOBAL innodb_file_format_max = 'x' or when we open
 
131
updated via SET GLOBAL innodb_file_format_check = 'x' or when we open
142
132
or create a table. */
143
133
static  file_format_t   file_format_max;
144
134
 
181
171
        byte*   doublewrite)    /*!< in: pointer to the doublewrite buf
182
172
                                header on trx sys page */
183
173
{
184
 
  trx_doublewrite = static_cast<trx_doublewrite_t *>(mem_alloc(sizeof(trx_doublewrite_t)));
 
174
        trx_doublewrite = mem_alloc(sizeof(trx_doublewrite_t));
185
175
 
186
176
        /* Since we now start to use the doublewrite buffer, no need to call
187
177
        fsync() after every write to a data file */
189
179
        os_do_not_call_flush_at_each_write = TRUE;
190
180
#endif /* UNIV_DO_FLUSH */
191
181
 
192
 
        mutex_create(trx_doublewrite_mutex_key,
193
 
                     &trx_doublewrite->mutex, SYNC_DOUBLEWRITE);
 
182
        mutex_create(&trx_doublewrite->mutex, SYNC_DOUBLEWRITE);
194
183
 
195
184
        trx_doublewrite->first_free = 0;
196
185
 
198
187
                doublewrite + TRX_SYS_DOUBLEWRITE_BLOCK1);
199
188
        trx_doublewrite->block2 = mach_read_from_4(
200
189
                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));
 
190
        trx_doublewrite->write_buf_unaligned = ut_malloc(
 
191
                (1 + 2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) * UNIV_PAGE_SIZE);
203
192
 
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*)));
 
193
        trx_doublewrite->write_buf = ut_align(
 
194
                trx_doublewrite->write_buf_unaligned, UNIV_PAGE_SIZE);
 
195
        trx_doublewrite->buf_block_arr = mem_alloc(
 
196
                2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * sizeof(void*));
208
197
}
209
198
 
210
199
/****************************************************************//**
252
241
{
253
242
        buf_block_t*    block;
254
243
        buf_block_t*    block2;
255
 
#ifdef UNIV_SYNC_DEBUG
256
244
        buf_block_t*    new_block;
257
 
#endif /* UNIV_SYNC_DEBUG */
258
245
        byte*   doublewrite;
259
246
        byte*   fseg_header;
260
247
        ulint   page_no;
357
344
                        the page position in the tablespace, then the page
358
345
                        has not been written to in doublewrite. */
359
346
 
360
 
#ifdef UNIV_SYNC_DEBUG
361
 
                        new_block =
362
 
#endif /* UNIV_SYNC_DEBUG */
363
 
                        buf_page_get(TRX_SYS_SPACE, 0, page_no,
364
 
                                     RW_X_LATCH, &mtr);
 
347
                        new_block = buf_page_get(TRX_SYS_SPACE, 0, page_no,
 
348
                                                 RW_X_LATCH, &mtr);
365
349
                        buf_block_dbg_add_level(new_block,
366
350
                                                SYNC_NO_ORDER_CHECK);
367
351
 
443
427
 
444
428
        /* We do the file i/o past the buffer pool */
445
429
 
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));
 
430
        unaligned_read_buf = ut_malloc(2 * UNIV_PAGE_SIZE);
 
431
        read_buf = ut_align(unaligned_read_buf, UNIV_PAGE_SIZE);
448
432
 
449
433
        /* Read the trx sys header to check if we are using the doublewrite
450
434
        buffer */
600
584
                                                " recover the database"
601
585
                                                " with the my.cnf\n"
602
586
                                                "InnoDB: option:\n"
603
 
                                                "InnoDB:"
604
 
                                                " innodb_force_recovery=6\n");
 
587
                                                "InnoDB: set-variable="
 
588
                                                "innodb_force_recovery=6\n");
605
589
                                        exit(1);
606
590
                                }
607
591
 
672
656
 
673
657
        sys_header = trx_sysf_get(&mtr);
674
658
 
675
 
        mlog_write_ull(sys_header + TRX_SYS_TRX_ID_STORE,
676
 
                       trx_sys->max_trx_id, &mtr);
 
659
        mlog_write_dulint(sys_header + TRX_SYS_TRX_ID_STORE,
 
660
                          trx_sys->max_trx_id, &mtr);
677
661
        mtr_commit(&mtr);
678
662
}
679
663
 
 
664
/*****************************************************************//**
 
665
Updates the offset information about the end of the MySQL binlog entry
 
666
which corresponds to the transaction just being committed. In a MySQL
 
667
replication slave updates the latest master binlog position up to which
 
668
replication has proceeded. */
680
669
UNIV_INTERN
681
670
void
682
 
trx_sys_flush_commit_id(uint64_t commit_id, ulint field, mtr_t* mtr)
 
671
trx_sys_update_mysql_binlog_offset(
 
672
/*===============================*/
 
673
        const char*     file_name,/*!< in: MySQL log file name */
 
674
        ib_int64_t      offset, /*!< in: position in that log file */
 
675
        ulint           field,  /*!< in: offset of the MySQL log info field in
 
676
                                the trx sys header */
 
677
        mtr_t*          mtr)    /*!< in: mtr */
683
678
{
684
 
        trx_sysf_t*     sys_header;
685
 
  
 
679
        trx_sysf_t*     sys_header;
 
680
 
 
681
        if (ut_strlen(file_name) >= TRX_SYS_MYSQL_LOG_NAME_LEN) {
 
682
 
 
683
                /* We cannot fit the name to the 512 bytes we have reserved */
 
684
 
 
685
                return;
 
686
        }
 
687
 
686
688
        sys_header = trx_sysf_get(mtr);
687
689
 
688
 
        mlog_write_ull(sys_header + field + TRX_SYS_DRIZZLE_MAX_COMMIT_ID, 
689
 
                       commit_id, mtr);
 
690
        if (mach_read_from_4(sys_header + field
 
691
                             + TRX_SYS_MYSQL_LOG_MAGIC_N_FLD)
 
692
            != TRX_SYS_MYSQL_LOG_MAGIC_N) {
 
693
 
 
694
                mlog_write_ulint(sys_header + field
 
695
                                 + TRX_SYS_MYSQL_LOG_MAGIC_N_FLD,
 
696
                                 TRX_SYS_MYSQL_LOG_MAGIC_N,
 
697
                                 MLOG_4BYTES, mtr);
 
698
        }
 
699
 
 
700
        if (0 != strcmp((char*) (sys_header + field + TRX_SYS_MYSQL_LOG_NAME),
 
701
                        file_name)) {
 
702
 
 
703
                mlog_write_string(sys_header + field
 
704
                                  + TRX_SYS_MYSQL_LOG_NAME,
 
705
                                  (byte*) file_name, 1 + ut_strlen(file_name),
 
706
                                  mtr);
 
707
        }
 
708
 
 
709
        if (mach_read_from_4(sys_header + field
 
710
                             + TRX_SYS_MYSQL_LOG_OFFSET_HIGH) > 0
 
711
            || (offset >> 32) > 0) {
 
712
 
 
713
                mlog_write_ulint(sys_header + field
 
714
                                 + TRX_SYS_MYSQL_LOG_OFFSET_HIGH,
 
715
                                 (ulint)(offset >> 32),
 
716
                                 MLOG_4BYTES, mtr);
 
717
        }
 
718
 
 
719
        mlog_write_ulint(sys_header + field
 
720
                         + TRX_SYS_MYSQL_LOG_OFFSET_LOW,
 
721
                         (ulint)(offset & 0xFFFFFFFFUL),
 
722
                         MLOG_4BYTES, mtr);
690
723
}
691
724
 
692
 
 
 
725
/*****************************************************************//**
 
726
Stores the MySQL binlog offset info in the trx system header if
 
727
the magic number shows it valid, and print the info to stderr */
693
728
UNIV_INTERN
694
729
void
695
 
trx_sys_read_commit_id(void)
 
730
trx_sys_print_mysql_binlog_offset(void)
696
731
/*===================================*/
697
732
{
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
 
 
 
733
        trx_sysf_t*     sys_header;
 
734
        mtr_t           mtr;
 
735
        ulint           trx_sys_mysql_bin_log_pos_high;
 
736
        ulint           trx_sys_mysql_bin_log_pos_low;
 
737
 
 
738
        mtr_start(&mtr);
 
739
 
 
740
        sys_header = trx_sysf_get(&mtr);
 
741
 
 
742
        if (mach_read_from_4(sys_header + TRX_SYS_MYSQL_LOG_INFO
 
743
                             + TRX_SYS_MYSQL_LOG_MAGIC_N_FLD)
 
744
            != TRX_SYS_MYSQL_LOG_MAGIC_N) {
 
745
 
 
746
                mtr_commit(&mtr);
 
747
 
 
748
                return;
 
749
        }
 
750
 
 
751
        trx_sys_mysql_bin_log_pos_high = mach_read_from_4(
 
752
                sys_header + TRX_SYS_MYSQL_LOG_INFO
 
753
                + TRX_SYS_MYSQL_LOG_OFFSET_HIGH);
 
754
        trx_sys_mysql_bin_log_pos_low = mach_read_from_4(
 
755
                sys_header + TRX_SYS_MYSQL_LOG_INFO
 
756
                + TRX_SYS_MYSQL_LOG_OFFSET_LOW);
 
757
 
 
758
        trx_sys_mysql_bin_log_pos
 
759
                = (((ib_int64_t)trx_sys_mysql_bin_log_pos_high) << 32)
 
760
                + (ib_int64_t)trx_sys_mysql_bin_log_pos_low;
 
761
 
 
762
        ut_memcpy(trx_sys_mysql_bin_log_name,
 
763
                  sys_header + TRX_SYS_MYSQL_LOG_INFO
 
764
                  + TRX_SYS_MYSQL_LOG_NAME, TRX_SYS_MYSQL_LOG_NAME_LEN);
 
765
 
 
766
        fprintf(stderr,
 
767
                "InnoDB: Last MySQL binlog file position %lu %lu,"
 
768
                " file name %s\n",
 
769
                trx_sys_mysql_bin_log_pos_high, trx_sys_mysql_bin_log_pos_low,
 
770
                trx_sys_mysql_bin_log_name);
 
771
 
 
772
        mtr_commit(&mtr);
 
773
}
 
774
 
 
775
/*****************************************************************//**
 
776
Prints to stderr the MySQL master log offset info in the trx system header if
 
777
the magic number shows it valid. */
 
778
UNIV_INTERN
 
779
void
 
780
trx_sys_print_mysql_master_log_pos(void)
 
781
/*====================================*/
 
782
{
 
783
        trx_sysf_t*     sys_header;
 
784
        mtr_t           mtr;
 
785
 
 
786
        mtr_start(&mtr);
 
787
 
 
788
        sys_header = trx_sysf_get(&mtr);
 
789
 
 
790
        if (mach_read_from_4(sys_header + TRX_SYS_MYSQL_MASTER_LOG_INFO
 
791
                             + TRX_SYS_MYSQL_LOG_MAGIC_N_FLD)
 
792
            != TRX_SYS_MYSQL_LOG_MAGIC_N) {
 
793
 
 
794
                mtr_commit(&mtr);
 
795
 
 
796
                return;
 
797
        }
 
798
 
 
799
        fprintf(stderr,
 
800
                "InnoDB: In a MySQL replication slave the last"
 
801
                " master binlog file\n"
 
802
                "InnoDB: position %lu %lu, file name %s\n",
 
803
                (ulong) mach_read_from_4(sys_header
 
804
                                         + TRX_SYS_MYSQL_MASTER_LOG_INFO
 
805
                                         + TRX_SYS_MYSQL_LOG_OFFSET_HIGH),
 
806
                (ulong) mach_read_from_4(sys_header
 
807
                                         + TRX_SYS_MYSQL_MASTER_LOG_INFO
 
808
                                         + TRX_SYS_MYSQL_LOG_OFFSET_LOW),
 
809
                sys_header + TRX_SYS_MYSQL_MASTER_LOG_INFO
 
810
                + TRX_SYS_MYSQL_LOG_NAME);
 
811
        /* Copy the master log position info to global variables we can
 
812
        use in ha_innobase.cc to initialize glob_mi to right values */
 
813
 
 
814
        ut_memcpy(trx_sys_mysql_master_log_name,
 
815
                  sys_header + TRX_SYS_MYSQL_MASTER_LOG_INFO
 
816
                  + TRX_SYS_MYSQL_LOG_NAME,
 
817
                  TRX_SYS_MYSQL_LOG_NAME_LEN);
 
818
 
 
819
        trx_sys_mysql_master_log_pos
 
820
                = (((ib_int64_t) mach_read_from_4(
 
821
                            sys_header + TRX_SYS_MYSQL_MASTER_LOG_INFO
 
822
                            + TRX_SYS_MYSQL_LOG_OFFSET_HIGH)) << 32)
 
823
                + ((ib_int64_t) mach_read_from_4(
 
824
                           sys_header + TRX_SYS_MYSQL_MASTER_LOG_INFO
 
825
                           + TRX_SYS_MYSQL_LOG_OFFSET_LOW));
708
826
        mtr_commit(&mtr);
709
827
}
710
828
 
752
870
        buf_block_t*    block;
753
871
        page_t*         page;
754
872
        ulint           page_no;
755
 
        byte*           ptr;
756
 
        ulint           len;
 
873
        ulint           i;
757
874
 
758
875
        ut_ad(mtr);
759
876
 
786
903
        sys_header = trx_sysf_get(mtr);
787
904
 
788
905
        /* Start counting transaction ids from number 1 up */
789
 
        mach_write_to_8(sys_header + TRX_SYS_TRX_ID_STORE, 1);
790
 
 
791
 
        /* Reset the rollback segment slots.  Old versions of InnoDB
792
 
        define TRX_SYS_N_RSEGS as 256 (TRX_SYS_OLD_N_RSEGS) and expect
793
 
        that the whole array is initialized. */
794
 
        ptr = TRX_SYS_RSEGS + sys_header;
795
 
        len = ut_max(TRX_SYS_OLD_N_RSEGS, TRX_SYS_N_RSEGS)
796
 
                * TRX_SYS_RSEG_SLOT_SIZE;
797
 
        memset(ptr, 0xff, len);
798
 
        ptr += len;
799
 
        ut_a(ptr <= page + (UNIV_PAGE_SIZE - FIL_PAGE_DATA_END));
800
 
 
801
 
        /* Initialize all of the page.  This part used to be uninitialized. */
802
 
        memset(ptr, 0, UNIV_PAGE_SIZE - FIL_PAGE_DATA_END + page - ptr);
803
 
 
804
 
        mlog_log_string(sys_header, UNIV_PAGE_SIZE - FIL_PAGE_DATA_END
805
 
                        + page - sys_header, mtr);
 
906
        mlog_write_dulint(sys_header + TRX_SYS_TRX_ID_STORE,
 
907
                          ut_dulint_create(0, 1), mtr);
 
908
 
 
909
        /* Reset the rollback segment slots */
 
910
        for (i = 0; i < TRX_SYS_N_RSEGS; i++) {
 
911
 
 
912
                trx_sysf_rseg_set_space(sys_header, i, ULINT_UNDEFINED, mtr);
 
913
                trx_sysf_rseg_set_page_no(sys_header, i, FIL_NULL, mtr);
 
914
        }
 
915
 
 
916
        /* The remaining area (up to the page trailer) is uninitialized.
 
917
        Silence Valgrind warnings about it. */
 
918
        UNIV_MEM_VALID(sys_header + (TRX_SYS_RSEGS
 
919
                                     + TRX_SYS_N_RSEGS * TRX_SYS_RSEG_SLOT_SIZE
 
920
                                     + TRX_SYS_RSEG_SPACE),
 
921
                       (UNIV_PAGE_SIZE - FIL_PAGE_DATA_END
 
922
                        - (TRX_SYS_RSEGS
 
923
                           + TRX_SYS_N_RSEGS * TRX_SYS_RSEG_SLOT_SIZE
 
924
                           + TRX_SYS_RSEG_SPACE))
 
925
                       + page - sys_header);
806
926
 
807
927
        /* Create the first rollback segment in the SYSTEM tablespace */
808
 
        slot_no = trx_sysf_rseg_find_free(mtr);
809
 
        page_no = trx_rseg_header_create(TRX_SYS_SPACE, 0, ULINT_MAX, slot_no,
 
928
        page_no = trx_rseg_header_create(TRX_SYS_SPACE, 0, ULINT_MAX, &slot_no,
810
929
                                         mtr);
811
930
        ut_a(slot_no == TRX_SYS_SYSTEM_RSEG_ID);
812
 
        ut_a(page_no == FSP_FIRST_RSEG_PAGE_NO);
 
931
        ut_a(page_no != FIL_NULL);
813
932
 
814
933
        mutex_exit(&kernel_mutex);
815
934
}
823
942
/*==========================*/
824
943
{
825
944
        trx_sysf_t*     sys_header;
826
 
        ib_uint64_t     rows_to_undo    = 0;
 
945
        ib_int64_t      rows_to_undo    = 0;
827
946
        const char*     unit            = "";
828
947
        trx_t*          trx;
829
948
        mtr_t           mtr;
834
953
 
835
954
        mutex_enter(&kernel_mutex);
836
955
 
837
 
        trx_sys = static_cast<trx_sys_t *>(mem_alloc(sizeof(trx_sys_t)));
 
956
        trx_sys = mem_alloc(sizeof(trx_sys_t));
838
957
 
839
958
        sys_header = trx_sysf_get(&mtr);
840
959
 
849
968
        to the disk-based header! Thus trx id values will not overlap when
850
969
        the database is repeatedly started! */
851
970
 
852
 
        trx_sys->max_trx_id = 2 * TRX_SYS_TRX_ID_WRITE_MARGIN
853
 
                + ut_uint64_align_up(mach_read_from_8(sys_header
854
 
                                                   + TRX_SYS_TRX_ID_STORE),
855
 
                                     TRX_SYS_TRX_ID_WRITE_MARGIN);
 
971
        trx_sys->max_trx_id = ut_dulint_add(
 
972
                ut_dulint_align_up(mtr_read_dulint(
 
973
                                           sys_header
 
974
                                           + TRX_SYS_TRX_ID_STORE, &mtr),
 
975
                                   TRX_SYS_TRX_ID_WRITE_MARGIN),
 
976
                2 * TRX_SYS_TRX_ID_WRITE_MARGIN);
856
977
 
857
978
        UT_LIST_INIT(trx_sys->mysql_trx_list);
858
979
        trx_dummy_sess = sess_open();
863
984
 
864
985
                for (;;) {
865
986
 
866
 
                        if (trx->conc_state != TRX_PREPARED) {
867
 
                                rows_to_undo += trx->undo_no;
 
987
                        if ( trx->conc_state != TRX_PREPARED) {
 
988
                                rows_to_undo += ut_conv_dulint_to_longlong(
 
989
                                        trx->undo_no);
868
990
                        }
869
991
 
870
992
                        trx = UT_LIST_GET_NEXT(trx_list, trx);
887
1009
                        (ulong) rows_to_undo, unit);
888
1010
 
889
1011
                fprintf(stderr, "InnoDB: Trx id counter is " TRX_ID_FMT "\n",
890
 
                        trx_sys->max_trx_id);
 
1012
                        TRX_ID_PREP_PRINTF(trx_sys->max_trx_id));
891
1013
        }
892
1014
 
893
1015
        UT_LIST_INIT(trx_sys->view_list);
931
1053
        mtr_t           mtr;
932
1054
        byte*           ptr;
933
1055
        buf_block_t*    block;
934
 
        ib_uint64_t     tag_value;
 
1056
        ulint           tag_value_low;
935
1057
 
936
1058
        mtr_start(&mtr);
937
1059
 
942
1064
        file_format_max.name = trx_sys_file_format_id_to_name(format_id);
943
1065
 
944
1066
        ptr = buf_block_get_frame(block) + TRX_SYS_FILE_FORMAT_TAG;
945
 
        tag_value = format_id + TRX_SYS_FILE_FORMAT_TAG_MAGIC_N;
 
1067
        tag_value_low = format_id + TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_LOW;
946
1068
 
947
1069
        if (name) {
948
1070
                *name = file_format_max.name;
949
1071
        }
950
1072
 
951
 
        mlog_write_ull(ptr, tag_value, &mtr);
 
1073
        mlog_write_dulint(
 
1074
                ptr,
 
1075
                ut_dulint_create(TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_HIGH,
 
1076
                                 tag_value_low),
 
1077
                &mtr);
952
1078
 
953
1079
        mtr_commit(&mtr);
954
1080
 
966
1092
        mtr_t                   mtr;
967
1093
        const byte*             ptr;
968
1094
        const buf_block_t*      block;
969
 
        ib_id_t                 file_format_id;
 
1095
        ulint                   format_id;
 
1096
        dulint                  file_format_id;
970
1097
 
971
1098
        /* Since this is called during the startup phase it's safe to
972
1099
        read the value without a covering mutex. */
980
1107
 
981
1108
        mtr_commit(&mtr);
982
1109
 
983
 
        file_format_id -= TRX_SYS_FILE_FORMAT_TAG_MAGIC_N;
 
1110
        format_id = file_format_id.low - TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_LOW;
984
1111
 
985
 
        if (file_format_id >= FILE_FORMAT_NAME_N) {
 
1112
        if (file_format_id.high != TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_HIGH
 
1113
            || format_id >= FILE_FORMAT_NAME_N) {
986
1114
 
987
1115
                /* Either it has never been tagged, or garbage in it. */
988
1116
                return(ULINT_UNDEFINED);
989
1117
        }
990
1118
 
991
 
        return((ulint) file_format_id);
 
1119
        return(format_id);
992
1120
}
993
1121
 
994
1122
/*****************************************************************//**
1024
1152
        if (format_id == ULINT_UNDEFINED) {
1025
1153
                /* Format ID was not set. Set it to minimum possible
1026
1154
                value. */
1027
 
                format_id = DICT_TF_FORMAT_MIN;
 
1155
                format_id = DICT_TF_FORMAT_51;
1028
1156
        }
1029
1157
 
1030
1158
        ut_print_timestamp(stderr);
1104
1232
 
1105
1233
        /* If format_id is not set then set it to the minimum. */
1106
1234
        if (format_id == ULINT_UNDEFINED) {
1107
 
                trx_sys_file_format_max_set(DICT_TF_FORMAT_MIN, NULL);
 
1235
                trx_sys_file_format_max_set(DICT_TF_FORMAT_51, NULL);
1108
1236
        }
1109
1237
}
1110
1238
 
1155
1283
trx_sys_file_format_init(void)
1156
1284
/*==========================*/
1157
1285
{
1158
 
        mutex_create(file_format_max_mutex_key,
1159
 
                     &file_format_max.mutex, SYNC_FILE_FORMAT_TAG);
 
1286
        mutex_create(&file_format_max.mutex, SYNC_FILE_FORMAT_TAG);
1160
1287
 
1161
1288
        /* We don't need a mutex here, as this function should only
1162
1289
        be called once at start up. */
1163
 
        file_format_max.id = DICT_TF_FORMAT_MIN;
 
1290
        file_format_max.id = DICT_TF_FORMAT_51;
1164
1291
 
1165
1292
        file_format_max.name = trx_sys_file_format_id_to_name(
1166
1293
                file_format_max.id);
1175
1302
{
1176
1303
        /* Does nothing at the moment */
1177
1304
}
1178
 
 
1179
 
/*********************************************************************
1180
 
Creates the rollback segments */
1181
 
UNIV_INTERN
1182
 
void
1183
 
trx_sys_create_rsegs(
1184
 
/*=================*/
1185
 
        ulint   n_rsegs)        /*!< number of rollback segments to create */
1186
 
{
1187
 
        ulint   new_rsegs = 0;
1188
 
 
1189
 
        /* Do not create additional rollback segments if
1190
 
        innodb_force_recovery has been set and the database
1191
 
        was not shutdown cleanly. */
1192
 
        if (!srv_force_recovery && !recv_needed_recovery) {
1193
 
                ulint   i;
1194
 
 
1195
 
                for (i = 0;  i < n_rsegs; ++i) {
1196
 
 
1197
 
                        if (trx_rseg_create() != NULL) {
1198
 
                                ++new_rsegs;
1199
 
                        } else {
1200
 
                                break;
1201
 
                        }
1202
 
                }
1203
 
        }
1204
 
 
1205
 
        if (new_rsegs > 0) {
1206
 
                fprintf(stderr,
1207
 
                        "InnoDB: %lu rollback segment(s) active.\n",
1208
 
                        new_rsegs);
1209
 
        }
1210
 
}
1211
 
 
1212
1305
#else /* !UNIV_HOTBACKUP */
 
1306
/*****************************************************************//**
 
1307
Prints to stderr the MySQL binlog info in the system header if the
 
1308
magic number shows it valid. */
 
1309
UNIV_INTERN
 
1310
void
 
1311
trx_sys_print_mysql_binlog_offset_from_page(
 
1312
/*========================================*/
 
1313
        const byte*     page)   /*!< in: buffer containing the trx
 
1314
                                system header page, i.e., page number
 
1315
                                TRX_SYS_PAGE_NO in the tablespace */
 
1316
{
 
1317
        const trx_sysf_t*       sys_header;
 
1318
 
 
1319
        sys_header = page + TRX_SYS;
 
1320
 
 
1321
        if (mach_read_from_4(sys_header + TRX_SYS_MYSQL_LOG_INFO
 
1322
                             + TRX_SYS_MYSQL_LOG_MAGIC_N_FLD)
 
1323
            == TRX_SYS_MYSQL_LOG_MAGIC_N) {
 
1324
 
 
1325
                fprintf(stderr,
 
1326
                        "ibbackup: Last MySQL binlog file position %lu %lu,"
 
1327
                        " file name %s\n",
 
1328
                        (ulong) mach_read_from_4(
 
1329
                                sys_header + TRX_SYS_MYSQL_LOG_INFO
 
1330
                                + TRX_SYS_MYSQL_LOG_OFFSET_HIGH),
 
1331
                        (ulong) mach_read_from_4(
 
1332
                                sys_header + TRX_SYS_MYSQL_LOG_INFO
 
1333
                                + TRX_SYS_MYSQL_LOG_OFFSET_LOW),
 
1334
                        sys_header + TRX_SYS_MYSQL_LOG_INFO
 
1335
                        + TRX_SYS_MYSQL_LOG_NAME);
 
1336
        }
 
1337
}
 
1338
 
1213
1339
 
1214
1340
/* THESE ARE COPIED FROM NON-HOTBACKUP PART OF THE INNODB SOURCE TREE
1215
1341
   (This code duplicaton should be fixed at some point!)
1247
1373
        byte            buf[UNIV_PAGE_SIZE * 2];
1248
1374
        page_t*         page = ut_align(buf, UNIV_PAGE_SIZE);
1249
1375
        const byte*     ptr;
1250
 
        ib_id_t         file_format_id;
 
1376
        dulint          file_format_id;
1251
1377
 
1252
1378
        *format_id = ULINT_UNDEFINED;
1253
 
 
 
1379
        
1254
1380
        file = os_file_create_simple_no_error_handling(
1255
 
                innodb_file_data_key,
1256
1381
                pathname,
1257
1382
                OS_FILE_OPEN,
1258
1383
                OS_FILE_READ_ONLY,
1261
1386
        if (!success) {
1262
1387
                /* The following call prints an error message */
1263
1388
                os_file_get_last_error(TRUE);
1264
 
 
 
1389
        
1265
1390
                ut_print_timestamp(stderr);
1266
 
 
 
1391
        
1267
1392
                fprintf(stderr,
1268
1393
"  ibbackup: Error: trying to read system tablespace file format,\n"
1269
1394
"  ibbackup: but could not open the tablespace file %s!\n",
1280
1405
        if (!success) {
1281
1406
                /* The following call prints an error message */
1282
1407
                os_file_get_last_error(TRUE);
1283
 
 
 
1408
        
1284
1409
                ut_print_timestamp(stderr);
1285
 
 
 
1410
        
1286
1411
                fprintf(stderr,
1287
1412
"  ibbackup: Error: trying to read system table space file format,\n"
1288
1413
"  ibbackup: but failed to read the tablespace file %s!\n",
1296
1421
        /* get the file format from the page */
1297
1422
        ptr = page + TRX_SYS_FILE_FORMAT_TAG;
1298
1423
        file_format_id = mach_read_from_8(ptr);
1299
 
        file_format_id -= TRX_SYS_FILE_FORMAT_TAG_MAGIC_N;
1300
 
 
1301
 
        if (file_format_id >= FILE_FORMAT_NAME_N) {
 
1424
 
 
1425
        *format_id = file_format_id.low - TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_LOW;
 
1426
 
 
1427
        if (file_format_id.high != TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_HIGH
 
1428
            || *format_id >= FILE_FORMAT_NAME_N) {
1302
1429
 
1303
1430
                /* Either it has never been tagged, or garbage in it. */
 
1431
                *format_id = ULINT_UNDEFINED;
1304
1432
                return(TRUE);
1305
1433
        }
1306
 
 
1307
 
        *format_id = (ulint) file_format_id;
1308
 
 
 
1434
        
1309
1435
        return(TRUE);
1310
1436
}
1311
1437
 
1330
1456
        ib_uint32_t     flags;
1331
1457
 
1332
1458
        *format_id = ULINT_UNDEFINED;
1333
 
 
 
1459
        
1334
1460
        file = os_file_create_simple_no_error_handling(
1335
 
                innodb_file_data_key,
1336
1461
                pathname,
1337
1462
                OS_FILE_OPEN,
1338
1463
                OS_FILE_READ_ONLY,
1410
1535
 
1411
1536
#endif /* !UNIV_HOTBACKUP */
1412
1537
 
1413
 
#ifndef UNIV_HOTBACKUP
1414
1538
/*********************************************************************
1415
1539
Shutdown/Close the transaction system. */
1416
1540
UNIV_INTERN
1431
1555
                        "InnoDB: Error: all read views were not closed"
1432
1556
                        " before shutdown:\n"
1433
1557
                        "InnoDB: %lu read views open \n",
1434
 
                        static_cast<ulint>(UT_LIST_GET_LEN(trx_sys->view_list)) - 1);
 
1558
                        UT_LIST_GET_LEN(trx_sys->view_list) - 1);
1435
1559
        }
1436
1560
 
1437
1561
        sess_close(trx_dummy_sess);
1487
1611
        trx_sys = NULL;
1488
1612
        mutex_exit(&kernel_mutex);
1489
1613
}
1490
 
#endif /* !UNIV_HOTBACKUP */