~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Marisa Plumb
  • Date: 2010-12-04 02:38:29 UTC
  • mto: This revision was merged to the branch mainline in revision 1984.
  • Revision ID: marisa.plumb@gmail.com-20101204023829-2khzxh30wxi256db
updates to a few sql docs 

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
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
 
52
51
                                        fields */
53
52
};
54
53
 
55
 
#include <drizzled/errmsg_print.h>
56
 
 
57
54
/** The file format tag */
58
55
typedef struct file_format_struct       file_format_t;
59
56
 
92
89
UNIV_INTERN char        trx_sys_mysql_bin_log_name[TRX_SYS_MYSQL_LOG_NAME_LEN];
93
90
/** Binlog file position, or -1 if unknown */
94
91
UNIV_INTERN ib_int64_t  trx_sys_mysql_bin_log_pos       = -1;
95
 
 
96
 
UNIV_INTERN drizzled::atomic<uint64_t> trx_sys_commit_id;
97
 
 
98
92
/* @} */
99
93
#endif /* !UNIV_HOTBACKUP */
100
94
 
132
126
static const ulint      FILE_FORMAT_NAME_N
133
127
        = sizeof(file_format_name_map) / sizeof(file_format_name_map[0]);
134
128
 
135
 
#ifdef UNIV_PFS_MUTEX
136
 
/* Key to register the mutex with performance schema */
137
 
UNIV_INTERN mysql_pfs_key_t     trx_doublewrite_mutex_key;
138
 
UNIV_INTERN mysql_pfs_key_t     file_format_max_mutex_key;
139
 
#endif /* UNIV_PFS_MUTEX */
140
 
 
141
129
#ifndef UNIV_HOTBACKUP
142
130
/** This is used to track the maximum file format id known to InnoDB. It's
143
 
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
144
132
or create a table. */
145
133
static  file_format_t   file_format_max;
146
134
 
183
171
        byte*   doublewrite)    /*!< in: pointer to the doublewrite buf
184
172
                                header on trx sys page */
185
173
{
186
 
  trx_doublewrite = static_cast<trx_doublewrite_t *>(mem_alloc(sizeof(trx_doublewrite_t)));
 
174
        trx_doublewrite = mem_alloc(sizeof(trx_doublewrite_t));
187
175
 
188
176
        /* Since we now start to use the doublewrite buffer, no need to call
189
177
        fsync() after every write to a data file */
191
179
        os_do_not_call_flush_at_each_write = TRUE;
192
180
#endif /* UNIV_DO_FLUSH */
193
181
 
194
 
        mutex_create(trx_doublewrite_mutex_key,
195
 
                     &trx_doublewrite->mutex, SYNC_DOUBLEWRITE);
 
182
        mutex_create(&trx_doublewrite->mutex, SYNC_DOUBLEWRITE);
196
183
 
197
184
        trx_doublewrite->first_free = 0;
198
185
 
200
187
                doublewrite + TRX_SYS_DOUBLEWRITE_BLOCK1);
201
188
        trx_doublewrite->block2 = mach_read_from_4(
202
189
                doublewrite + TRX_SYS_DOUBLEWRITE_BLOCK2);
203
 
        trx_doublewrite->write_buf_unaligned = static_cast<byte *>(ut_malloc(
204
 
                                                                             (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);
205
192
 
206
 
        trx_doublewrite->write_buf = static_cast<byte *>(ut_align(
207
 
                                                                  trx_doublewrite->write_buf_unaligned, UNIV_PAGE_SIZE));
208
 
        trx_doublewrite->buf_block_arr = static_cast<buf_page_t **>(mem_alloc(
209
 
                                                                             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*));
210
197
}
211
198
 
212
199
/****************************************************************//**
254
241
{
255
242
        buf_block_t*    block;
256
243
        buf_block_t*    block2;
257
 
#ifdef UNIV_SYNC_DEBUG
258
244
        buf_block_t*    new_block;
259
 
#endif /* UNIV_SYNC_DEBUG */
260
245
        byte*   doublewrite;
261
246
        byte*   fseg_header;
262
247
        ulint   page_no;
359
344
                        the page position in the tablespace, then the page
360
345
                        has not been written to in doublewrite. */
361
346
 
362
 
#ifdef UNIV_SYNC_DEBUG
363
 
                        new_block =
364
 
#endif /* UNIV_SYNC_DEBUG */
365
 
                        buf_page_get(TRX_SYS_SPACE, 0, page_no,
366
 
                                     RW_X_LATCH, &mtr);
 
347
                        new_block = buf_page_get(TRX_SYS_SPACE, 0, page_no,
 
348
                                                 RW_X_LATCH, &mtr);
367
349
                        buf_block_dbg_add_level(new_block,
368
350
                                                SYNC_NO_ORDER_CHECK);
369
351
 
445
427
 
446
428
        /* We do the file i/o past the buffer pool */
447
429
 
448
 
        unaligned_read_buf = static_cast<byte *>(ut_malloc(2 * UNIV_PAGE_SIZE));
449
 
        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);
450
432
 
451
433
        /* Read the trx sys header to check if we are using the doublewrite
452
434
        buffer */
674
656
 
675
657
        sys_header = trx_sysf_get(&mtr);
676
658
 
677
 
        mlog_write_ull(sys_header + TRX_SYS_TRX_ID_STORE,
678
 
                       trx_sys->max_trx_id, &mtr);
 
659
        mlog_write_dulint(sys_header + TRX_SYS_TRX_ID_STORE,
 
660
                          trx_sys->max_trx_id, &mtr);
679
661
        mtr_commit(&mtr);
680
662
}
681
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. */
682
669
UNIV_INTERN
683
670
void
684
 
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 */
685
678
{
686
 
        trx_sysf_t*     sys_header;
687
 
  
 
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
 
688
688
        sys_header = trx_sysf_get(mtr);
689
689
 
690
 
        mlog_write_ull(sys_header + field + TRX_SYS_DRIZZLE_MAX_COMMIT_ID, 
691
 
                       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);
692
723
}
693
724
 
694
 
 
 
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 */
695
728
UNIV_INTERN
696
729
void
697
 
trx_sys_read_commit_id(void)
 
730
trx_sys_print_mysql_binlog_offset(void)
698
731
/*===================================*/
699
732
{
700
 
        trx_sysf_t*     sys_header;
701
 
        mtr_t           mtr;
702
 
 
703
 
        mtr_start(&mtr);
704
 
 
705
 
        sys_header = trx_sysf_get(&mtr);
706
 
 
707
 
        trx_sys_commit_id = mach_read_from_8(sys_header + TRX_SYS_DRIZZLE_LOG_INFO 
708
 
                                             + TRX_SYS_DRIZZLE_MAX_COMMIT_ID);
709
 
 
 
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));
710
826
        mtr_commit(&mtr);
711
827
}
712
828
 
754
870
        buf_block_t*    block;
755
871
        page_t*         page;
756
872
        ulint           page_no;
757
 
        byte*           ptr;
758
 
        ulint           len;
 
873
        ulint           i;
759
874
 
760
875
        ut_ad(mtr);
761
876
 
788
903
        sys_header = trx_sysf_get(mtr);
789
904
 
790
905
        /* Start counting transaction ids from number 1 up */
791
 
        mach_write_to_8(sys_header + TRX_SYS_TRX_ID_STORE, 1);
792
 
 
793
 
        /* Reset the rollback segment slots.  Old versions of InnoDB
794
 
        define TRX_SYS_N_RSEGS as 256 (TRX_SYS_OLD_N_RSEGS) and expect
795
 
        that the whole array is initialized. */
796
 
        ptr = TRX_SYS_RSEGS + sys_header;
797
 
        len = ut_max(TRX_SYS_OLD_N_RSEGS, TRX_SYS_N_RSEGS)
798
 
                * TRX_SYS_RSEG_SLOT_SIZE;
799
 
        memset(ptr, 0xff, len);
800
 
        ptr += len;
801
 
        ut_a(ptr <= page + (UNIV_PAGE_SIZE - FIL_PAGE_DATA_END));
802
 
 
803
 
        /* Initialize all of the page.  This part used to be uninitialized. */
804
 
        memset(ptr, 0, UNIV_PAGE_SIZE - FIL_PAGE_DATA_END + page - ptr);
805
 
 
806
 
        mlog_log_string(sys_header, UNIV_PAGE_SIZE - FIL_PAGE_DATA_END
807
 
                        + 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);
808
926
 
809
927
        /* Create the first rollback segment in the SYSTEM tablespace */
810
 
        slot_no = trx_sysf_rseg_find_free(mtr);
811
 
        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,
812
929
                                         mtr);
813
930
        ut_a(slot_no == TRX_SYS_SYSTEM_RSEG_ID);
814
 
        ut_a(page_no == FSP_FIRST_RSEG_PAGE_NO);
 
931
        ut_a(page_no != FIL_NULL);
815
932
 
816
933
        mutex_exit(&kernel_mutex);
817
934
}
825
942
/*==========================*/
826
943
{
827
944
        trx_sysf_t*     sys_header;
828
 
        ib_uint64_t     rows_to_undo    = 0;
 
945
        ib_int64_t      rows_to_undo    = 0;
829
946
        const char*     unit            = "";
830
947
        trx_t*          trx;
831
948
        mtr_t           mtr;
836
953
 
837
954
        mutex_enter(&kernel_mutex);
838
955
 
839
 
        trx_sys = static_cast<trx_sys_t *>(mem_alloc(sizeof(trx_sys_t)));
 
956
        trx_sys = mem_alloc(sizeof(trx_sys_t));
840
957
 
841
958
        sys_header = trx_sysf_get(&mtr);
842
959
 
851
968
        to the disk-based header! Thus trx id values will not overlap when
852
969
        the database is repeatedly started! */
853
970
 
854
 
        trx_sys->max_trx_id = 2 * TRX_SYS_TRX_ID_WRITE_MARGIN
855
 
                + ut_uint64_align_up(mach_read_from_8(sys_header
856
 
                                                   + TRX_SYS_TRX_ID_STORE),
857
 
                                     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);
858
977
 
859
978
        UT_LIST_INIT(trx_sys->mysql_trx_list);
860
979
        trx_dummy_sess = sess_open();
865
984
 
866
985
                for (;;) {
867
986
 
868
 
                        if (trx->conc_state != TRX_PREPARED) {
869
 
                                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);
870
990
                        }
871
991
 
872
992
                        trx = UT_LIST_GET_NEXT(trx_list, trx);
889
1009
                        (ulong) rows_to_undo, unit);
890
1010
 
891
1011
                fprintf(stderr, "InnoDB: Trx id counter is " TRX_ID_FMT "\n",
892
 
                        trx_sys->max_trx_id);
 
1012
                        TRX_ID_PREP_PRINTF(trx_sys->max_trx_id));
893
1013
        }
894
1014
 
895
1015
        UT_LIST_INIT(trx_sys->view_list);
933
1053
        mtr_t           mtr;
934
1054
        byte*           ptr;
935
1055
        buf_block_t*    block;
936
 
        ib_uint64_t     tag_value;
 
1056
        ulint           tag_value_low;
937
1057
 
938
1058
        mtr_start(&mtr);
939
1059
 
944
1064
        file_format_max.name = trx_sys_file_format_id_to_name(format_id);
945
1065
 
946
1066
        ptr = buf_block_get_frame(block) + TRX_SYS_FILE_FORMAT_TAG;
947
 
        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;
948
1068
 
949
1069
        if (name) {
950
1070
                *name = file_format_max.name;
951
1071
        }
952
1072
 
953
 
        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);
954
1078
 
955
1079
        mtr_commit(&mtr);
956
1080
 
968
1092
        mtr_t                   mtr;
969
1093
        const byte*             ptr;
970
1094
        const buf_block_t*      block;
971
 
        ib_id_t                 file_format_id;
 
1095
        ulint                   format_id;
 
1096
        dulint                  file_format_id;
972
1097
 
973
1098
        /* Since this is called during the startup phase it's safe to
974
1099
        read the value without a covering mutex. */
982
1107
 
983
1108
        mtr_commit(&mtr);
984
1109
 
985
 
        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;
986
1111
 
987
 
        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) {
988
1114
 
989
1115
                /* Either it has never been tagged, or garbage in it. */
990
1116
                return(ULINT_UNDEFINED);
991
1117
        }
992
1118
 
993
 
        return((ulint) file_format_id);
 
1119
        return(format_id);
994
1120
}
995
1121
 
996
1122
/*****************************************************************//**
1026
1152
        if (format_id == ULINT_UNDEFINED) {
1027
1153
                /* Format ID was not set. Set it to minimum possible
1028
1154
                value. */
1029
 
                format_id = DICT_TF_FORMAT_MIN;
 
1155
                format_id = DICT_TF_FORMAT_51;
1030
1156
        }
1031
1157
 
1032
 
        drizzled::errmsg_printf(drizzled::error::INFO, "InnoDB: highest supported file format is %s",
1033
 
                                trx_sys_file_format_id_to_name(DICT_TF_FORMAT_MAX));
 
1158
        ut_print_timestamp(stderr);
 
1159
        fprintf(stderr,
 
1160
                "  InnoDB: highest supported file format is %s.\n",
 
1161
                trx_sys_file_format_id_to_name(DICT_TF_FORMAT_MAX));
1034
1162
 
1035
1163
        if (format_id > DICT_TF_FORMAT_MAX) {
1036
1164
 
1037
1165
                ut_a(format_id < FILE_FORMAT_NAME_N);
1038
1166
 
1039
 
                drizzled::errmsg_printf(drizzled::error::ERROR,
1040
 
                        "InnoDB: %s: the system tablespace is in a file "
1041
 
                        "format that this version doesn't support - %s",
 
1167
                ut_print_timestamp(stderr);
 
1168
                fprintf(stderr,
 
1169
                        "  InnoDB: %s: the system tablespace is in a file "
 
1170
                        "format that this version doesn't support - %s\n",
1042
1171
                        ((max_format_id <= DICT_TF_FORMAT_MAX)
1043
1172
                                ? "Error" : "Warning"),
1044
1173
                        trx_sys_file_format_id_to_name(format_id));
1103
1232
 
1104
1233
        /* If format_id is not set then set it to the minimum. */
1105
1234
        if (format_id == ULINT_UNDEFINED) {
1106
 
                trx_sys_file_format_max_set(DICT_TF_FORMAT_MIN, NULL);
 
1235
                trx_sys_file_format_max_set(DICT_TF_FORMAT_51, NULL);
1107
1236
        }
1108
1237
}
1109
1238
 
1154
1283
trx_sys_file_format_init(void)
1155
1284
/*==========================*/
1156
1285
{
1157
 
        mutex_create(file_format_max_mutex_key,
1158
 
                     &file_format_max.mutex, SYNC_FILE_FORMAT_TAG);
 
1286
        mutex_create(&file_format_max.mutex, SYNC_FILE_FORMAT_TAG);
1159
1287
 
1160
1288
        /* We don't need a mutex here, as this function should only
1161
1289
        be called once at start up. */
1162
 
        file_format_max.id = DICT_TF_FORMAT_MIN;
 
1290
        file_format_max.id = DICT_TF_FORMAT_51;
1163
1291
 
1164
1292
        file_format_max.name = trx_sys_file_format_id_to_name(
1165
1293
                file_format_max.id);
1174
1302
{
1175
1303
        /* Does nothing at the moment */
1176
1304
}
1177
 
 
1178
 
/*********************************************************************
1179
 
Creates the rollback segments */
1180
 
UNIV_INTERN
1181
 
void
1182
 
trx_sys_create_rsegs(
1183
 
/*=================*/
1184
 
        ulint   n_rsegs)        /*!< number of rollback segments to create */
1185
 
{
1186
 
        ulint   new_rsegs = 0;
1187
 
 
1188
 
        /* Do not create additional rollback segments if
1189
 
        innodb_force_recovery has been set and the database
1190
 
        was not shutdown cleanly. */
1191
 
        if (!srv_force_recovery && !recv_needed_recovery) {
1192
 
                ulint   i;
1193
 
 
1194
 
                for (i = 0;  i < n_rsegs; ++i) {
1195
 
 
1196
 
                        if (trx_rseg_create() != NULL) {
1197
 
                                ++new_rsegs;
1198
 
                        } else {
1199
 
                                break;
1200
 
                        }
1201
 
                }
1202
 
        }
1203
 
 
1204
 
        if (new_rsegs > 0) {
1205
 
                fprintf(stderr,
1206
 
                        "InnoDB: %lu rollback segment(s) active.\n",
1207
 
                        new_rsegs);
1208
 
        }
1209
 
}
1210
 
 
1211
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
 
1212
1339
 
1213
1340
/* THESE ARE COPIED FROM NON-HOTBACKUP PART OF THE INNODB SOURCE TREE
1214
1341
   (This code duplicaton should be fixed at some point!)
1246
1373
        byte            buf[UNIV_PAGE_SIZE * 2];
1247
1374
        page_t*         page = ut_align(buf, UNIV_PAGE_SIZE);
1248
1375
        const byte*     ptr;
1249
 
        ib_id_t         file_format_id;
 
1376
        dulint          file_format_id;
1250
1377
 
1251
1378
        *format_id = ULINT_UNDEFINED;
1252
 
 
 
1379
        
1253
1380
        file = os_file_create_simple_no_error_handling(
1254
 
                innodb_file_data_key,
1255
1381
                pathname,
1256
1382
                OS_FILE_OPEN,
1257
1383
                OS_FILE_READ_ONLY,
1260
1386
        if (!success) {
1261
1387
                /* The following call prints an error message */
1262
1388
                os_file_get_last_error(TRUE);
1263
 
 
 
1389
        
1264
1390
                ut_print_timestamp(stderr);
1265
 
 
 
1391
        
1266
1392
                fprintf(stderr,
1267
1393
"  ibbackup: Error: trying to read system tablespace file format,\n"
1268
1394
"  ibbackup: but could not open the tablespace file %s!\n",
1279
1405
        if (!success) {
1280
1406
                /* The following call prints an error message */
1281
1407
                os_file_get_last_error(TRUE);
1282
 
 
 
1408
        
1283
1409
                ut_print_timestamp(stderr);
1284
 
 
 
1410
        
1285
1411
                fprintf(stderr,
1286
1412
"  ibbackup: Error: trying to read system table space file format,\n"
1287
1413
"  ibbackup: but failed to read the tablespace file %s!\n",
1295
1421
        /* get the file format from the page */
1296
1422
        ptr = page + TRX_SYS_FILE_FORMAT_TAG;
1297
1423
        file_format_id = mach_read_from_8(ptr);
1298
 
        file_format_id -= TRX_SYS_FILE_FORMAT_TAG_MAGIC_N;
1299
 
 
1300
 
        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) {
1301
1429
 
1302
1430
                /* Either it has never been tagged, or garbage in it. */
 
1431
                *format_id = ULINT_UNDEFINED;
1303
1432
                return(TRUE);
1304
1433
        }
1305
 
 
1306
 
        *format_id = (ulint) file_format_id;
1307
 
 
 
1434
        
1308
1435
        return(TRUE);
1309
1436
}
1310
1437
 
1329
1456
        ib_uint32_t     flags;
1330
1457
 
1331
1458
        *format_id = ULINT_UNDEFINED;
1332
 
 
 
1459
        
1333
1460
        file = os_file_create_simple_no_error_handling(
1334
 
                innodb_file_data_key,
1335
1461
                pathname,
1336
1462
                OS_FILE_OPEN,
1337
1463
                OS_FILE_READ_ONLY,
1430
1556
                        "InnoDB: Error: all read views were not closed"
1431
1557
                        " before shutdown:\n"
1432
1558
                        "InnoDB: %lu read views open \n",
1433
 
                        static_cast<ulint>(UT_LIST_GET_LEN(trx_sys->view_list)) - 1);
 
1559
                        UT_LIST_GET_LEN(trx_sys->view_list) - 1);
1434
1560
        }
1435
1561
 
1436
1562
        sess_close(trx_dummy_sess);