~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/srv/srv0start.c

  • Committer: Padraig O'Sullivan
  • Date: 2009-03-21 01:02:23 UTC
  • mto: (960.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 961.
  • Revision ID: osullivan.padraig@gmail.com-20090321010223-j8cph7eeyt1u3xol
Fixed function object to ensure it correctly returns a boolean type since
memcmp returns an integer. Added some more comments.

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
Copyright (c) 2008, Google Inc.
5
 
Copyright (c) 2009, Percona Inc.
6
5
 
7
6
Portions of this file contain modifications contributed and copyrighted by
8
7
Google, Inc. Those modifications are gratefully acknowledged and are described
10
9
incorporated with their permission, and subject to the conditions contained in
11
10
the file COPYING.Google.
12
11
 
13
 
Portions of this file contain modifications contributed and copyrighted
14
 
by Percona Inc.. Those modifications are
15
 
gratefully acknowledged and are described briefly in the InnoDB
16
 
documentation. The contributions by Percona Inc. are incorporated with
17
 
their permission, and subject to the conditions contained in the file
18
 
COPYING.Percona.
19
 
 
20
12
This program is free software; you can redistribute it and/or modify it under
21
13
the terms of the GNU General Public License as published by the Free Software
22
14
Foundation; version 2 of the License.
26
18
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
27
19
 
28
20
You should have received a copy of the GNU General Public License along with
29
 
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
30
 
St, Fifth Floor, Boston, MA 02110-1301 USA
 
21
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
22
Place, Suite 330, Boston, MA 02111-1307 USA
31
23
 
32
24
*****************************************************************************/
33
25
 
34
 
/********************************************************************//**
35
 
@file srv/srv0start.c
 
26
/************************************************************************
36
27
Starts the InnoDB database server
37
28
 
38
29
Created 2/16/1996 Heikki Tuuri
39
30
*************************************************************************/
40
31
 
 
32
#include "os0proc.h"
 
33
#include "sync0sync.h"
41
34
#include "ut0mem.h"
42
35
#include "mem0mem.h"
43
36
#include "data0data.h"
44
37
#include "data0type.h"
45
38
#include "dict0dict.h"
46
39
#include "buf0buf.h"
 
40
#include "buf0flu.h"
 
41
#include "buf0rea.h"
47
42
#include "os0file.h"
48
43
#include "os0thread.h"
49
44
#include "fil0fil.h"
50
45
#include "fsp0fsp.h"
51
46
#include "rem0rec.h"
 
47
#include "rem0cmp.h"
52
48
#include "mtr0mtr.h"
53
49
#include "log0log.h"
54
50
#include "log0recv.h"
55
51
#include "page0page.h"
56
52
#include "page0cur.h"
57
53
#include "trx0trx.h"
 
54
#include "dict0boot.h"
 
55
#include "dict0load.h"
58
56
#include "trx0sys.h"
 
57
#include "dict0crea.h"
59
58
#include "btr0btr.h"
 
59
#include "btr0pcur.h"
60
60
#include "btr0cur.h"
 
61
#include "btr0sea.h"
61
62
#include "rem0rec.h"
 
63
#include "srv0srv.h"
 
64
#include "que0que.h"
 
65
#include "usr0sess.h"
 
66
#include "lock0lock.h"
 
67
#include "trx0roll.h"
 
68
#include "trx0purge.h"
 
69
#include "row0ins.h"
 
70
#include "row0sel.h"
 
71
#include "row0upd.h"
 
72
#include "row0row.h"
 
73
#include "row0mysql.h"
 
74
#include "lock0lock.h"
62
75
#include "ibuf0ibuf.h"
 
76
#include "pars0pars.h"
 
77
#include "btr0sea.h"
63
78
#include "srv0start.h"
64
 
#include "srv0srv.h"
65
 
#ifndef UNIV_HOTBACKUP
66
 
# include "os0proc.h"
67
 
# include "sync0sync.h"
68
 
# include "buf0flu.h"
69
 
# include "buf0rea.h"
70
 
# include "dict0boot.h"
71
 
# include "dict0load.h"
72
 
# include "que0que.h"
73
 
# include "usr0sess.h"
74
 
# include "lock0lock.h"
75
 
# include "trx0roll.h"
76
 
# include "trx0purge.h"
77
 
# include "lock0lock.h"
78
 
# include "pars0pars.h"
79
 
# include "btr0sea.h"
80
 
# include "rem0cmp.h"
81
 
# include "dict0crea.h"
82
 
# include "row0ins.h"
83
 
# include "row0sel.h"
84
 
# include "row0upd.h"
85
 
# include "row0row.h"
86
 
# include "row0mysql.h"
87
 
# include "btr0pcur.h"
88
 
# include "thr0loc.h"
89
 
# include "os0sync.h" /* for INNODB_RW_LOCKS_USE_ATOMICS */
90
 
# include "zlib.h" /* for ZLIB_VERSION */
91
 
 
92
 
#include <errno.h>
93
 
#include <unistd.h>
94
 
 
95
 
/** Log sequence number immediately after startup */
 
79
#include "que0que.h"
 
80
 
 
81
/* Log sequence number immediately after startup */
96
82
UNIV_INTERN ib_uint64_t srv_start_lsn;
97
 
/** Log sequence number at shutdown */
 
83
/* Log sequence number at shutdown */
98
84
UNIV_INTERN ib_uint64_t srv_shutdown_lsn;
99
85
 
100
86
#ifdef HAVE_DARWIN_THREADS
101
87
# include <sys/utsname.h>
102
 
/** TRUE if the F_FULLFSYNC option is available */
103
88
UNIV_INTERN ibool       srv_have_fullfsync = FALSE;
104
89
#endif
105
90
 
106
 
/** TRUE if a raw partition is in use */
107
91
UNIV_INTERN ibool       srv_start_raw_disk_in_use = FALSE;
108
92
 
109
 
/** TRUE if the server is being started, before rolling back any
110
 
incomplete transactions */
111
93
UNIV_INTERN ibool       srv_startup_is_before_trx_rollback_phase = FALSE;
112
 
/** TRUE if the server is being started */
113
94
UNIV_INTERN ibool       srv_is_being_started = FALSE;
114
 
/** TRUE if the server was successfully started */
115
95
UNIV_INTERN ibool       srv_was_started = FALSE;
116
 
/** TRUE if innobase_start_or_create_for_mysql() has been called */
 
96
#ifndef UNIV_HOTBACKUP
117
97
static ibool    srv_start_has_been_called = FALSE;
118
 
 
119
 
/** At a shutdown this value climbs from SRV_SHUTDOWN_NONE to
120
 
SRV_SHUTDOWN_CLEANUP and then to SRV_SHUTDOWN_LAST_PHASE, and so on */
121
 
UNIV_INTERN enum srv_shutdown_state     srv_shutdown_state = SRV_SHUTDOWN_NONE;
122
 
 
123
 
/** Files comprising the system tablespace */
 
98
#endif /* !UNIV_HOTBACKUP */
 
99
 
 
100
/* At a shutdown the value first climbs to SRV_SHUTDOWN_CLEANUP
 
101
and then to SRV_SHUTDOWN_LAST_PHASE */
 
102
UNIV_INTERN ulint               srv_shutdown_state = 0;
 
103
 
 
104
#ifndef UNIV_HOTBACKUP
124
105
static os_file_t        files[1000];
125
106
 
126
 
/** Mutex protecting the ios count */
127
107
static mutex_t          ios_mutex;
128
 
/** Count of I/O operations in io_handler_thread() */
129
108
static ulint            ios;
130
109
 
131
 
/** io_handler_thread parameters for thread identification */
132
 
static ulint            n[SRV_MAX_N_IO_THREADS + 6];
133
 
/** io_handler_thread identifiers */
134
 
static os_thread_id_t   thread_ids[SRV_MAX_N_IO_THREADS + 6];
 
110
static ulint            n[SRV_MAX_N_IO_THREADS + 5];
 
111
static os_thread_id_t   thread_ids[SRV_MAX_N_IO_THREADS + 5];
135
112
 
136
 
/** We use this mutex to test the return value of pthread_mutex_trylock
 
113
/* We use this mutex to test the return value of pthread_mutex_trylock
137
114
   on successful locking. HP-UX does NOT return 0, though Linux et al do. */
138
115
static os_fast_mutex_t  srv_os_test_mutex;
139
116
 
140
 
/** Name of srv_monitor_file */
 
117
/* Name of srv_monitor_file */
141
118
static char*    srv_monitor_file_name;
142
119
#endif /* !UNIV_HOTBACKUP */
143
120
 
144
 
/** */
145
121
#define SRV_N_PENDING_IOS_PER_THREAD    OS_AIO_N_PENDING_IOS_PER_THREAD
146
122
#define SRV_MAX_N_PENDING_SYNC_IOS      100
147
123
 
148
 
#ifdef UNIV_PFS_THREAD
149
 
/* Keys to register InnoDB threads with performance schema */
150
 
UNIV_INTERN mysql_pfs_key_t     io_handler_thread_key;
151
 
UNIV_INTERN mysql_pfs_key_t     srv_lock_timeout_thread_key;
152
 
UNIV_INTERN mysql_pfs_key_t     srv_error_monitor_thread_key;
153
 
UNIV_INTERN mysql_pfs_key_t     srv_monitor_thread_key;
154
 
UNIV_INTERN mysql_pfs_key_t     srv_master_thread_key;
155
 
#endif /* UNIV_PFS_THREAD */
156
 
 
157
 
#ifdef UNIV_PFS_MUTEX
158
 
/* Key to register ios_mutex_key with performance schema */
159
 
UNIV_INTERN mysql_pfs_key_t     ios_mutex_key;
160
 
#endif /* UNIV_PFS_MUTEX */
161
 
 
162
 
/*********************************************************************//**
163
 
Convert a numeric string that optionally ends in G or M, to a number
164
 
containing megabytes.
165
 
@return next character in string */
 
124
 
166
125
static
167
126
char*
168
127
srv_parse_megabytes(
169
128
/*================*/
170
 
        char*   str,    /*!< in: string containing a quantity in bytes */
171
 
        ulint*  megs)   /*!< out: the number in megabytes */
 
129
                        /* out: next character in string */
 
130
        char*   str,    /* in: string containing a quantity in bytes */
 
131
        ulint*  megs)   /* out: the number in megabytes */
172
132
{
173
133
        char*   endp;
174
134
        ulint   size;
193
153
        return(str);
194
154
}
195
155
 
196
 
/*********************************************************************//**
 
156
/*************************************************************************
197
157
Reads the data files and their sizes from a character string given in
198
 
the .cnf file.
199
 
@return TRUE if ok, FALSE on parse error */
 
158
the .cnf file. */
200
159
UNIV_INTERN
201
160
ibool
202
161
srv_parse_data_file_paths_and_sizes(
203
162
/*================================*/
204
 
        char*   str)    /*!< in/out: the data file path string */
 
163
                        /* out: TRUE if ok, FALSE on parse error */
 
164
        char*   str)    /* in/out: the data file path string */
205
165
{
206
166
        char*   input_str;
207
167
        char*   path;
377
337
        return(TRUE);
378
338
}
379
339
 
380
 
/*********************************************************************//**
 
340
/*************************************************************************
381
341
Reads log group home directories from a character string given in
382
 
the .cnf file.
383
 
@return TRUE if ok, FALSE on parse error */
 
342
the .cnf file. */
384
343
UNIV_INTERN
385
344
ibool
386
345
srv_parse_log_group_home_dirs(
387
346
/*==========================*/
388
 
        char*   str)    /*!< in/out: character string */
 
347
                        /* out: TRUE if ok, FALSE on parse error */
 
348
        char*   str)    /* in/out: character string */
389
349
{
390
350
        char*   input_str;
391
351
        char*   path;
449
409
        return(TRUE);
450
410
}
451
411
 
452
 
/*********************************************************************//**
 
412
/*************************************************************************
453
413
Frees the memory allocated by srv_parse_data_file_paths_and_sizes()
454
414
and srv_parse_log_group_home_dirs(). */
455
415
UNIV_INTERN
468
428
}
469
429
 
470
430
#ifndef UNIV_HOTBACKUP
471
 
/********************************************************************//**
472
 
I/o-handler thread function.
473
 
@return OS_THREAD_DUMMY_RETURN */
 
431
/************************************************************************
 
432
I/o-handler thread function. */
474
433
static
 
434
 
475
435
os_thread_ret_t
476
436
io_handler_thread(
477
437
/*==============*/
478
 
        void*   arg)    /*!< in: pointer to the number of the segment in
479
 
                        the aio array */
 
438
        void*   arg)
480
439
{
481
440
        ulint   segment;
 
441
        ulint   i;
482
442
 
483
443
        segment = *((ulint*)arg);
484
444
 
486
446
        fprintf(stderr, "Io handler thread %lu starts, id %lu\n", segment,
487
447
                os_thread_pf(os_thread_get_curr_id()));
488
448
#endif
489
 
 
490
 
#ifdef UNIV_PFS_THREAD
491
 
        pfs_register_thread(io_handler_thread_key);
492
 
#endif /* UNIV_PFS_THREAD */
493
 
 
494
 
        while (srv_shutdown_state != SRV_SHUTDOWN_EXIT_THREADS) {
 
449
        for (i = 0;; i++) {
495
450
                fil_aio_wait(segment);
496
451
 
497
452
                mutex_enter(&ios_mutex);
499
454
                mutex_exit(&ios_mutex);
500
455
        }
501
456
 
502
 
        thr_local_free(os_thread_get_curr_id());
503
 
 
504
457
        /* We count the number of threads in os_thread_exit(). A created
505
458
        thread should always use that to exit and not use return() to exit.
506
459
        The thread actually never comes here because it is exited in an
507
460
        os_event_wait(). */
 
461
#ifndef UNIV_SOLARIS
508
462
        return 0;
 
463
#endif
509
464
}
510
465
#endif /* !UNIV_HOTBACKUP */
511
466
 
515
470
#define SRV_PATH_SEPARATOR      '/'
516
471
#endif
517
472
 
518
 
/*********************************************************************//**
 
473
/*************************************************************************
519
474
Normalizes a directory path for Windows: converts slashes to backslashes. */
520
475
UNIV_INTERN
521
476
void
522
477
srv_normalize_path_for_win(
523
478
/*=======================*/
524
 
        char*   str __attribute__((unused)))    /*!< in/out: null-terminated
 
479
        char*   str __attribute__((unused)))    /* in/out: null-terminated
525
480
                                                character string */
526
481
{
527
482
#ifdef __WIN__
534
489
#endif
535
490
}
536
491
 
 
492
/*************************************************************************
 
493
Adds a slash or a backslash to the end of a string if it is missing
 
494
and the string is not empty. */
 
495
UNIV_INTERN
 
496
char*
 
497
srv_add_path_separator_if_needed(
 
498
/*=============================*/
 
499
                        /* out: string which has the separator if the
 
500
                        string is not empty */
 
501
        char*   str)    /* in: null-terminated character string */
 
502
{
 
503
        char*   out_str;
 
504
        ulint   len     = ut_strlen(str);
 
505
 
 
506
        if (len == 0 || str[len - 1] == SRV_PATH_SEPARATOR) {
 
507
 
 
508
                return(str);
 
509
        }
 
510
 
 
511
        out_str = ut_malloc(len + 2);
 
512
        memcpy(out_str, str, len);
 
513
        out_str[len] = SRV_PATH_SEPARATOR;
 
514
        out_str[len + 1] = 0;
 
515
 
 
516
        return(out_str);
 
517
}
 
518
 
537
519
#ifndef UNIV_HOTBACKUP
538
 
/*********************************************************************//**
 
520
/*************************************************************************
539
521
Calculates the low 32 bits when a file size which is given as a number
540
 
database pages is converted to the number of bytes.
541
 
@return low 32 bytes of file size when expressed in bytes */
 
522
database pages is converted to the number of bytes. */
542
523
static
543
524
ulint
544
525
srv_calc_low32(
545
526
/*===========*/
546
 
        ulint   file_size)      /*!< in: file size in database pages */
 
527
                                /* out: low 32 bytes of file size when
 
528
                                expressed in bytes */
 
529
        ulint   file_size)      /* in: file size in database pages */
547
530
{
548
531
        return(0xFFFFFFFFUL & (file_size << UNIV_PAGE_SIZE_SHIFT));
549
532
}
550
533
 
551
 
/*********************************************************************//**
 
534
/*************************************************************************
552
535
Calculates the high 32 bits when a file size which is given as a number
553
 
database pages is converted to the number of bytes.
554
 
@return high 32 bytes of file size when expressed in bytes */
 
536
database pages is converted to the number of bytes. */
555
537
static
556
538
ulint
557
539
srv_calc_high32(
558
540
/*============*/
559
 
        ulint   file_size)      /*!< in: file size in database pages */
 
541
                                /* out: high 32 bytes of file size when
 
542
                                expressed in bytes */
 
543
        ulint   file_size)      /* in: file size in database pages */
560
544
{
561
545
        return(file_size >> (32 - UNIV_PAGE_SIZE_SHIFT));
562
546
}
563
547
 
564
 
/*********************************************************************//**
565
 
Creates or opens the log files and closes them.
566
 
@return DB_SUCCESS or error code */
 
548
/*************************************************************************
 
549
Creates or opens the log files and closes them. */
567
550
static
568
551
ulint
569
552
open_or_create_log_file(
570
553
/*====================*/
571
 
        ibool   create_new_db,          /*!< in: TRUE if we should create a
 
554
                                        /* out: DB_SUCCESS or error code */
 
555
        ibool   create_new_db,          /* in: TRUE if we should create a
572
556
                                        new database */
573
 
        ibool*  log_file_created,       /*!< out: TRUE if new log file
 
557
        ibool*  log_file_created,       /* out: TRUE if new log file
574
558
                                        created */
575
 
        ibool   log_file_has_been_opened,/*!< in: TRUE if a log file has been
 
559
        ibool   log_file_has_been_opened,/* in: TRUE if a log file has been
576
560
                                        opened before: then it is an error
577
561
                                        to try to create another log file */
578
 
        ulint   k,                      /*!< in: log group number */
579
 
        ulint   i)                      /*!< in: log file number in group */
 
562
        ulint   k,                      /* in: log group number */
 
563
        ulint   i)                      /* in: log file number in group */
580
564
{
581
565
        ibool   ret;
582
566
        ulint   size;
583
567
        ulint   size_high;
584
568
        char    name[10000];
585
 
        ulint   dirnamelen;
586
569
 
587
570
        UT_NOT_USED(create_new_db);
588
571
 
589
572
        *log_file_created = FALSE;
590
573
 
591
574
        srv_normalize_path_for_win(srv_log_group_home_dirs[k]);
592
 
 
593
 
        dirnamelen = strlen(srv_log_group_home_dirs[k]);
594
 
        ut_a(dirnamelen < (sizeof name) - 10 - sizeof "ib_logfile");
595
 
        memcpy(name, srv_log_group_home_dirs[k], dirnamelen);
596
 
 
597
 
        /* Add a path separator if needed. */
598
 
        if (dirnamelen && name[dirnamelen - 1] != SRV_PATH_SEPARATOR) {
599
 
                name[dirnamelen++] = SRV_PATH_SEPARATOR;
600
 
        }
601
 
 
602
 
        sprintf(name + dirnamelen, "%s%lu", "ib_logfile", (ulong) i);
603
 
 
604
 
        files[i] = os_file_create(innodb_file_log_key, name,
605
 
                                  OS_FILE_CREATE, OS_FILE_NORMAL,
 
575
        srv_log_group_home_dirs[k] = srv_add_path_separator_if_needed(
 
576
                srv_log_group_home_dirs[k]);
 
577
 
 
578
        ut_a(strlen(srv_log_group_home_dirs[k])
 
579
             < (sizeof name) - 10 - sizeof "ib_logfile");
 
580
        sprintf(name, "%s%s%lu", srv_log_group_home_dirs[k],
 
581
                "ib_logfile", (ulong) i);
 
582
 
 
583
        files[i] = os_file_create(name, OS_FILE_CREATE, OS_FILE_NORMAL,
606
584
                                  OS_LOG_FILE, &ret);
607
585
        if (ret == FALSE) {
608
586
                if (os_file_get_last_error(FALSE) != OS_FILE_ALREADY_EXISTS
620
598
                        return(DB_ERROR);
621
599
                }
622
600
 
623
 
                files[i] = os_file_create(innodb_file_log_key, name,
624
 
                                          OS_FILE_OPEN, OS_FILE_AIO,
 
601
                files[i] = os_file_create(name, OS_FILE_OPEN, OS_FILE_AIO,
625
602
                                          OS_LOG_FILE, &ret);
626
603
                if (!ret) {
627
604
                        fprintf(stderr,
721
698
        return(DB_SUCCESS);
722
699
}
723
700
 
724
 
/*********************************************************************//**
725
 
Creates or opens database data files and closes them.
726
 
@return DB_SUCCESS or error code */
 
701
/*************************************************************************
 
702
Creates or opens database data files and closes them. */
727
703
static
728
704
ulint
729
705
open_or_create_data_files(
730
706
/*======================*/
731
 
        ibool*          create_new_db,  /*!< out: TRUE if new database should be
 
707
                                        /* out: DB_SUCCESS or error code */
 
708
        ibool*          create_new_db,  /* out: TRUE if new database should be
732
709
                                        created */
733
710
#ifdef UNIV_LOG_ARCHIVE
734
 
        ulint*          min_arch_log_no,/*!< out: min of archived log
 
711
        ulint*          min_arch_log_no,/* out: min of archived log
735
712
                                        numbers in data files */
736
 
        ulint*          max_arch_log_no,/*!< out: max of archived log
 
713
        ulint*          max_arch_log_no,/* out: max of archived log
737
714
                                        numbers in data files */
738
715
#endif /* UNIV_LOG_ARCHIVE */
739
 
        ib_uint64_t*    min_flushed_lsn,/*!< out: min of flushed lsn
740
 
                                        values in data files */
741
 
        ib_uint64_t*    max_flushed_lsn,/*!< out: max of flushed lsn
742
 
                                        values in data files */
743
 
        ulint*          sum_of_new_sizes)/*!< out: sum of sizes of the
 
716
        ib_uint64_t*    min_flushed_lsn,/* out: min of flushed lsn
 
717
                                        values in data files */
 
718
        ib_uint64_t*    max_flushed_lsn,/* out: max of flushed lsn
 
719
                                        values in data files */
 
720
        ulint*          sum_of_new_sizes)/* out: sum of sizes of the
744
721
                                        new files added */
745
722
{
746
723
        ibool   ret;
764
741
        *create_new_db = FALSE;
765
742
 
766
743
        srv_normalize_path_for_win(srv_data_home);
 
744
        srv_data_home = srv_add_path_separator_if_needed(srv_data_home);
767
745
 
768
746
        for (i = 0; i < srv_n_data_files; i++) {
769
 
                ulint   dirnamelen;
770
 
 
771
747
                srv_normalize_path_for_win(srv_data_file_names[i]);
772
 
                dirnamelen = strlen(srv_data_home);
773
748
 
774
 
                ut_a(dirnamelen + strlen(srv_data_file_names[i])
 
749
                ut_a(strlen(srv_data_home) + strlen(srv_data_file_names[i])
775
750
                     < (sizeof name) - 1);
776
 
                memcpy(name, srv_data_home, dirnamelen);
777
 
                /* Add a path separator if needed. */
778
 
                if (dirnamelen && name[dirnamelen - 1] != SRV_PATH_SEPARATOR) {
779
 
                        name[dirnamelen++] = SRV_PATH_SEPARATOR;
780
 
                }
781
 
 
782
 
                strcpy(name + dirnamelen, srv_data_file_names[i]);
 
751
                sprintf(name, "%s%s", srv_data_home, srv_data_file_names[i]);
783
752
 
784
753
                if (srv_data_file_is_raw_partition[i] == 0) {
785
754
 
786
755
                        /* First we try to create the file: if it already
787
756
                        exists, ret will get value FALSE */
788
757
 
789
 
                        files[i] = os_file_create(innodb_file_data_key,
790
 
                                                  name, OS_FILE_CREATE,
 
758
                        files[i] = os_file_create(name, OS_FILE_CREATE,
791
759
                                                  OS_FILE_NORMAL,
792
760
                                                  OS_DATA_FILE, &ret);
793
761
 
814
782
                        srv_start_raw_disk_in_use = TRUE;
815
783
                        srv_created_new_raw = TRUE;
816
784
 
817
 
                        files[i] = os_file_create(innodb_file_data_key,
818
 
                                                  name, OS_FILE_OPEN_RAW,
 
785
                        files[i] = os_file_create(name, OS_FILE_OPEN_RAW,
819
786
                                                  OS_FILE_NORMAL,
820
787
                                                  OS_DATA_FILE, &ret);
821
788
                        if (!ret) {
848
815
 
849
816
                        if (srv_data_file_is_raw_partition[i] == SRV_OLD_RAW) {
850
817
                                files[i] = os_file_create(
851
 
                                        innodb_file_data_key,
852
818
                                        name, OS_FILE_OPEN_RAW,
853
819
                                        OS_FILE_NORMAL, OS_DATA_FILE, &ret);
854
820
                        } else if (i == 0) {
855
821
                                files[i] = os_file_create(
856
 
                                        innodb_file_data_key,
857
822
                                        name, OS_FILE_OPEN_RETRY,
858
823
                                        OS_FILE_NORMAL, OS_DATA_FILE, &ret);
859
824
                        } else {
860
825
                                files[i] = os_file_create(
861
 
                                        innodb_file_data_key,
862
826
                                        name, OS_FILE_OPEN, OS_FILE_NORMAL,
863
827
                                        OS_DATA_FILE, &ret);
864
828
                        }
1001
965
 
1002
966
        ios = 0;
1003
967
 
1004
 
        mutex_create(ios_mutex_key, &ios_mutex, SYNC_NO_ORDER_CHECK);
 
968
        mutex_create(&ios_mutex, SYNC_NO_ORDER_CHECK);
1005
969
 
1006
970
        return(DB_SUCCESS);
1007
971
}
1008
972
 
1009
973
/********************************************************************
1010
974
Starts InnoDB and creates a new database if database files
1011
 
are not found and the user wants.
1012
 
@return DB_SUCCESS or error code */
 
975
are not found and the user wants. */
1013
976
UNIV_INTERN
1014
977
int
1015
978
innobase_start_or_create_for_mysql(void)
1016
979
/*====================================*/
 
980
                                /* out: DB_SUCCESS or error code */
1017
981
{
 
982
        buf_pool_t*     ret;
1018
983
        ibool           create_new_db;
1019
984
        ibool           log_file_created;
1020
985
        ibool           log_created     = FALSE;
1030
995
        ulint           tablespace_size_in_header;
1031
996
        ulint           err;
1032
997
        ulint           i;
1033
 
        ulint           io_limit;
1034
998
        my_bool         srv_file_per_table_original_value
1035
999
                = srv_file_per_table;
1036
1000
        mtr_t           mtr;
1080
1044
#ifdef UNIV_IBUF_DEBUG
1081
1045
        fprintf(stderr,
1082
1046
                "InnoDB: !!!!!!!! UNIV_IBUF_DEBUG switched on !!!!!!!!!\n"
1083
 
# ifdef UNIV_IBUF_COUNT_DEBUG
1084
 
                "InnoDB: !!!!!!!! UNIV_IBUF_COUNT_DEBUG switched on !!!!!!!!!\n"
1085
 
                "InnoDB: Crash recovery will fail with UNIV_IBUF_COUNT_DEBUG\n"
1086
 
# endif
1087
 
                );
 
1047
                "InnoDB: Crash recovery will fail with UNIV_IBUF_DEBUG\n");
1088
1048
#endif
1089
1049
 
1090
1050
#ifdef UNIV_SYNC_DEBUG
1097
1057
                "InnoDB: !!!!!!!! UNIV_SEARCH_DEBUG switched on !!!!!!!!!\n");
1098
1058
#endif
1099
1059
 
1100
 
#ifdef UNIV_LOG_LSN_DEBUG
1101
 
        fprintf(stderr,
1102
 
                "InnoDB: !!!!!!!! UNIV_LOG_LSN_DEBUG switched on !!!!!!!!!\n");
1103
 
#endif /* UNIV_LOG_LSN_DEBUG */
1104
1060
#ifdef UNIV_MEM_DEBUG
1105
1061
        fprintf(stderr,
1106
1062
                "InnoDB: !!!!!!!! UNIV_MEM_DEBUG switched on !!!!!!!!!\n");
1111
1067
                        "InnoDB: The InnoDB memory heap is disabled\n");
1112
1068
        }
1113
1069
 
1114
 
        fputs("InnoDB: " IB_ATOMICS_STARTUP_MSG
1115
 
              "\nInnoDB: Compressed tables use zlib " ZLIB_VERSION
1116
 
#ifdef UNIV_ZIP_DEBUG
1117
 
              " with validation"
1118
 
#endif /* UNIV_ZIP_DEBUG */
1119
 
#ifdef UNIV_ZIP_COPY
1120
 
              " and extra copying"
1121
 
#endif /* UNIV_ZIP_COPY */
1122
 
              "\n" , stderr);
1123
 
 
 
1070
#ifdef HAVE_GCC_ATOMIC_BUILTINS
 
1071
#ifdef INNODB_RW_LOCKS_USE_ATOMICS
 
1072
        fprintf(stderr,
 
1073
                "InnoDB: Mutexes and rw_locks use GCC atomic builtins.\n");
 
1074
#else /* INNODB_RW_LOCKS_USE_ATOMICS */
 
1075
        fprintf(stderr,
 
1076
                "InnoDB: Mutexes use GCC atomic builtins, rw_locks do not.\n");
 
1077
#endif /* INNODB_RW_LOCKS_USE_ATOMICS */
 
1078
#else /* HAVE_GCC_ATOMIC_BUILTINS */
 
1079
        fprintf(stderr,
 
1080
                "InnoDB: Neither mutexes nor rw_locks use GCC atomic builtins.\n");
 
1081
#endif /* HAVE_GCC_ATOMIC_BUILTINS */
1124
1082
 
1125
1083
        /* Since InnoDB does not currently clean up all its internal data
1126
1084
        structures in MySQL Embedded Server Library server_end(), we
1129
1087
 
1130
1088
        if (srv_start_has_been_called) {
1131
1089
                fprintf(stderr,
1132
 
                        "InnoDB: Error: startup called second time"
 
1090
                        "InnoDB: Error:startup called second time"
1133
1091
                        " during the process lifetime.\n"
1134
1092
                        "InnoDB: In the MySQL Embedded Server Library"
1135
1093
                        " you cannot call server_init()\n"
1146
1104
 
1147
1105
        srv_is_being_started = TRUE;
1148
1106
        srv_startup_is_before_trx_rollback_phase = TRUE;
 
1107
        os_aio_use_native_aio = FALSE;
1149
1108
 
1150
1109
#ifdef __WIN__
1151
 
        switch (os_get_os_version()) {
1152
 
        case OS_WIN95:
1153
 
        case OS_WIN31:
1154
 
        case OS_WINNT:
 
1110
        if (os_get_os_version() == OS_WIN95
 
1111
            || os_get_os_version() == OS_WIN31
 
1112
            || os_get_os_version() == OS_WINNT) {
 
1113
 
1155
1114
                /* On Win 95, 98, ME, Win32 subsystem for Windows 3.1,
1156
1115
                and NT use simulated aio. In NT Windows provides async i/o,
1157
1116
                but when run in conjunction with InnoDB Hot Backup, it seemed
1158
1117
                to corrupt the data files. */
1159
1118
 
1160
 
                srv_use_native_aio = FALSE;
1161
 
                break;
1162
 
 
1163
 
        case OS_WIN2000:
1164
 
        case OS_WINXP:
1165
 
                /* On 2000 and XP, async IO is available. */
1166
 
                srv_use_native_aio = TRUE;
1167
 
                break;
1168
 
 
1169
 
        default:
1170
 
                /* Vista and later have both async IO and condition variables */
1171
 
                srv_use_native_aio = TRUE;
1172
 
                srv_use_native_conditions = TRUE;
1173
 
                break;
1174
 
        }
1175
 
 
1176
 
#elif defined(LINUX_NATIVE_AIO)
1177
 
 
1178
 
        if (srv_use_native_aio) {
1179
 
                ut_print_timestamp(stderr);
1180
 
                fprintf(stderr,
1181
 
                        "  InnoDB: Using Linux native AIO\n");
1182
 
        }
1183
 
#else
1184
 
        /* Currently native AIO is supported only on windows and linux
1185
 
        and that also when the support is compiled in. In all other
1186
 
        cases, we ignore the setting of innodb_use_native_aio. */
1187
 
        srv_use_native_aio = FALSE;
1188
 
 
 
1119
                os_aio_use_native_aio = FALSE;
 
1120
        } else {
 
1121
                /* On Win 2000 and XP use async i/o */
 
1122
                os_aio_use_native_aio = TRUE;
 
1123
        }
1189
1124
#endif
1190
 
 
1191
1125
        if (srv_file_flush_method_str == NULL) {
1192
1126
                /* These are the default options */
1193
1127
 
1212
1146
#else
1213
1147
        } else if (0 == ut_strcmp(srv_file_flush_method_str, "normal")) {
1214
1148
                srv_win_file_flush_method = SRV_WIN_IO_NORMAL;
1215
 
                srv_use_native_aio = FALSE;
 
1149
                os_aio_use_native_aio = FALSE;
1216
1150
 
1217
1151
        } else if (0 == ut_strcmp(srv_file_flush_method_str, "unbuffered")) {
1218
1152
                srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
1219
 
                srv_use_native_aio = FALSE;
 
1153
                os_aio_use_native_aio = FALSE;
1220
1154
 
1221
1155
        } else if (0 == ut_strcmp(srv_file_flush_method_str,
1222
1156
                                  "async_unbuffered")) {
1238
1172
        maximum number of threads that can wait in the 'srv_conc array' for
1239
1173
        their time to enter InnoDB. */
1240
1174
 
 
1175
#if defined(__NETWARE__)
 
1176
 
 
1177
        /* Create less event semaphores because Win 98/ME had
 
1178
        difficulty creating 40000 event semaphores.  Comment from
 
1179
        Novell, Inc.: also, these just take a lot of memory on
 
1180
        NetWare. */
 
1181
        srv_max_n_threads = 1000;
 
1182
#else
1241
1183
        if (srv_buf_pool_size >= 1000 * 1024 * 1024) {
1242
1184
                /* If buffer pool is less than 1000 MB,
1243
 
                assume fewer threads. Also use only one
1244
 
                buffer pool instance */
 
1185
                assume fewer threads. */
1245
1186
                srv_max_n_threads = 50000;
1246
1187
 
1247
1188
        } else if (srv_buf_pool_size >= 8 * 1024 * 1024) {
1248
1189
 
1249
 
                srv_buf_pool_instances = 1;
1250
1190
                srv_max_n_threads = 10000;
1251
1191
        } else {
1252
 
                srv_buf_pool_instances = 1;
1253
1192
                srv_max_n_threads = 1000;       /* saves several MB of memory,
1254
1193
                                                especially in 64-bit
1255
1194
                                                computers */
1256
1195
        }
1257
 
 
 
1196
#endif
1258
1197
        err = srv_boot();
1259
1198
 
1260
1199
        if (err != DB_SUCCESS) {
1262
1201
                return((int) err);
1263
1202
        }
1264
1203
 
1265
 
        mutex_create(srv_monitor_file_mutex_key,
1266
 
                     &srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK);
 
1204
        mutex_create(&srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK);
1267
1205
 
1268
1206
        if (srv_innodb_status) {
1269
1207
                srv_monitor_file_name = mem_alloc(
1285
1223
                }
1286
1224
        }
1287
1225
 
1288
 
        mutex_create(srv_dict_tmpfile_mutex_key,
1289
 
                     &srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION);
 
1226
        mutex_create(&srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION);
1290
1227
 
1291
1228
        srv_dict_tmpfile = os_file_create_tmpfile();
1292
1229
        if (!srv_dict_tmpfile) {
1293
1230
                return(DB_ERROR);
1294
1231
        }
1295
1232
 
1296
 
        mutex_create(srv_misc_tmpfile_mutex_key,
1297
 
                     &srv_misc_tmpfile_mutex, SYNC_ANY_LATCH);
 
1233
        mutex_create(&srv_misc_tmpfile_mutex, SYNC_ANY_LATCH);
1298
1234
 
1299
1235
        srv_misc_tmpfile = os_file_create_tmpfile();
1300
1236
        if (!srv_misc_tmpfile) {
1301
1237
                return(DB_ERROR);
1302
1238
        }
1303
1239
 
1304
 
        /* innodb_file_io_threads used to be user settable.
1305
 
           It is now just a combination of read_io_threads and
1306
 
           write_io_threads that is set by innodb internally. */
1307
 
 
1308
 
        /* Now overwrite the value on srv_n_file_io_threads */
1309
 
        srv_n_file_io_threads = 2 + srv_n_read_io_threads
1310
 
                                + srv_n_write_io_threads;
1311
 
 
1312
 
        ut_a(srv_n_file_io_threads <= SRV_MAX_N_IO_THREADS);
1313
 
 
1314
 
        /* TODO: Investigate if SRV_N_PENDING_IOS_PER_THREAD (32) limit
1315
 
        still applies to windows. */
1316
 
        if (!srv_use_native_aio) {
1317
 
                io_limit = 8 * SRV_N_PENDING_IOS_PER_THREAD;
1318
 
        } else {
1319
 
                io_limit = SRV_N_PENDING_IOS_PER_THREAD;
1320
 
        }
1321
 
 
1322
 
        os_aio_init(io_limit,
1323
 
                    srv_n_read_io_threads,
1324
 
                    srv_n_write_io_threads,
1325
 
                    SRV_MAX_N_PENDING_SYNC_IOS);
1326
 
 
1327
 
        fil_init(srv_file_per_table ? 50000 : 5000,
1328
 
                 srv_max_n_open_files);
1329
 
 
1330
 
        /* Print time to initialize the buffer pool */
1331
 
        ut_print_timestamp(stderr);
1332
 
        fprintf(stderr,
1333
 
                "  InnoDB: Initializing buffer pool, size =");
1334
 
 
1335
 
        if (srv_buf_pool_size >= 1024 * 1024 * 1024) {
1336
 
                fprintf(stderr,
1337
 
                        " %.1fG\n",
1338
 
                        ((double) srv_buf_pool_size) / (1024 * 1024 * 1024));
1339
 
        } else {
1340
 
                fprintf(stderr,
1341
 
                        " %.1fM\n",
1342
 
                        ((double) srv_buf_pool_size) / (1024 * 1024));
1343
 
        }
1344
 
 
1345
 
        err = buf_pool_init(srv_buf_pool_size, srv_buf_pool_instances);
1346
 
 
1347
 
        ut_print_timestamp(stderr);
1348
 
        fprintf(stderr,
1349
 
                "  InnoDB: Completed initialization of buffer pool\n");
1350
 
 
1351
 
        if (err != DB_SUCCESS) {
 
1240
        /* Restrict the maximum number of file i/o threads */
 
1241
        if (srv_n_file_io_threads > SRV_MAX_N_IO_THREADS) {
 
1242
 
 
1243
                srv_n_file_io_threads = SRV_MAX_N_IO_THREADS;
 
1244
        }
 
1245
 
 
1246
        if (!os_aio_use_native_aio) {
 
1247
                /* In simulated aio we currently have use only for 4 threads */
 
1248
                srv_n_file_io_threads = 4;
 
1249
 
 
1250
                os_aio_init(8 * SRV_N_PENDING_IOS_PER_THREAD
 
1251
                            * srv_n_file_io_threads,
 
1252
                            srv_n_file_io_threads,
 
1253
                            SRV_MAX_N_PENDING_SYNC_IOS);
 
1254
        } else {
 
1255
                os_aio_init(SRV_N_PENDING_IOS_PER_THREAD
 
1256
                            * srv_n_file_io_threads,
 
1257
                            srv_n_file_io_threads,
 
1258
                            SRV_MAX_N_PENDING_SYNC_IOS);
 
1259
        }
 
1260
 
 
1261
        fil_init(srv_max_n_open_files);
 
1262
 
 
1263
        ret = buf_pool_init();
 
1264
 
 
1265
        if (ret == NULL) {
1352
1266
                fprintf(stderr,
1353
1267
                        "InnoDB: Fatal error: cannot allocate the memory"
1354
1268
                        " for the buffer pool\n");
1418
1332
                sum_of_new_sizes += srv_data_file_sizes[i];
1419
1333
        }
1420
1334
 
1421
 
        if (sum_of_new_sizes < 10485760 / UNIV_PAGE_SIZE) {
 
1335
        if (sum_of_new_sizes < 640) {
1422
1336
                fprintf(stderr,
1423
1337
                        "InnoDB: Error: tablespace size must be"
1424
1338
                        " at least 10 MB\n");
1545
1459
 
1546
1460
        if (create_new_db) {
1547
1461
                mtr_start(&mtr);
1548
 
 
1549
1462
                fsp_header_init(0, sum_of_new_sizes, &mtr);
1550
1463
 
1551
1464
                mtr_commit(&mtr);
1552
1465
 
1553
 
                /* To maintain backward compatibility we create only
1554
 
                the first rollback segment before the double write buffer.
1555
 
                All the remaining rollback segments will be created later,
1556
 
                after the double write buffer has been created. */
1557
1466
                trx_sys_create();
1558
 
 
1559
1467
                dict_create();
1560
 
 
1561
1468
                srv_startup_is_before_trx_rollback_phase = FALSE;
1562
1469
 
1563
1470
#ifdef UNIV_LOG_ARCHIVE
1576
1483
                in any disk i/o, first call dict_boot */
1577
1484
 
1578
1485
                dict_boot();
1579
 
 
1580
1486
                trx_sys_init_at_db_start();
1581
 
 
1582
1487
                srv_startup_is_before_trx_rollback_phase = FALSE;
1583
1488
 
1584
1489
                /* Initialize the fsp free limit global variable in the log
1602
1507
                consistent state, this is REQUIRED for the recovery
1603
1508
                process to work. */
1604
1509
                err = trx_sys_file_format_max_check(
1605
 
                        srv_max_file_format_at_startup);
 
1510
                        srv_check_file_format_at_startup);
1606
1511
 
1607
1512
                if (err != DB_SUCCESS) {
1608
1513
                        return(err);
1636
1541
                dict_boot();
1637
1542
                trx_sys_init_at_db_start();
1638
1543
 
1639
 
                /* Initialize the fsp free limit global variable in the log
1640
 
                system */
1641
 
                fsp_header_get_free_limit();
1642
 
 
1643
 
                /* recv_recovery_from_checkpoint_finish needs trx lists which
1644
 
                are initialized in trx_sys_init_at_db_start(). */
1645
 
 
1646
 
                recv_recovery_from_checkpoint_finish();
1647
1544
                if (srv_force_recovery < SRV_FORCE_NO_IBUF_MERGE) {
1648
1545
                        /* The following call is necessary for the insert
1649
1546
                        buffer to work with multiple tablespaces. We must
1659
1556
                        every table in the InnoDB data dictionary that has
1660
1557
                        an .ibd file.
1661
1558
 
1662
 
                        We also determine the maximum tablespace id used. */
 
1559
                        We also determine the maximum tablespace id used.
 
1560
 
 
1561
                        TODO: We may have incomplete transactions in the
 
1562
                        data dictionary tables. Does that harm the scanning of
 
1563
                        the data dictionary below? */
1663
1564
 
1664
1565
                        dict_check_tablespaces_and_store_max_id(
1665
1566
                                recv_needed_recovery);
1666
1567
                }
1667
1568
 
1668
1569
                srv_startup_is_before_trx_rollback_phase = FALSE;
1669
 
                recv_recovery_rollback_active();
 
1570
 
 
1571
                /* Initialize the fsp free limit global variable in the log
 
1572
                system */
 
1573
                fsp_header_get_free_limit();
 
1574
 
 
1575
                /* recv_recovery_from_checkpoint_finish needs trx lists which
 
1576
                are initialized in trx_sys_init_at_db_start(). */
 
1577
 
 
1578
                recv_recovery_from_checkpoint_finish();
1670
1579
 
1671
1580
                /* It is possible that file_format tag has never
1672
1581
                been set. In this case we initialize it to minimum
1715
1624
        /* fprintf(stderr, "Max allowed record size %lu\n",
1716
1625
        page_get_free_space_of_empty() / 2); */
1717
1626
 
1718
 
        if (trx_doublewrite == NULL) {
1719
 
                /* Create the doublewrite buffer to a new tablespace */
1720
 
 
1721
 
                trx_sys_create_doublewrite_buf();
1722
 
        }
1723
 
 
1724
 
        /* Here the double write buffer has already been created and so
1725
 
        any new rollback segments will be allocated after the double
1726
 
        write buffer. The default segment should already exist.
1727
 
        We create the new segments only if it's a new database or
1728
 
        the database was shutdown cleanly. */
1729
 
 
1730
 
        /* Note: When creating the extra rollback segments during an upgrade
1731
 
        we violate the latching order, even if the change buffer is empty.
1732
 
        We make an exception in sync0sync.c and check srv_is_being_started
1733
 
        for that violation. It cannot create a deadlock because we are still
1734
 
        running in single threaded mode essentially. Only the IO threads
1735
 
        should be running at this stage. */
1736
 
 
1737
 
        trx_sys_create_rsegs(TRX_SYS_N_RSEGS - 1);
1738
 
 
1739
 
        /* Create the thread which watches the timeouts for lock waits */
1740
 
        os_thread_create(&srv_lock_timeout_thread, NULL,
 
1627
        /* Create the thread which watches the timeouts for lock waits
 
1628
        and prints InnoDB monitor info */
 
1629
 
 
1630
        os_thread_create(&srv_lock_timeout_and_monitor_thread, NULL,
1741
1631
                         thread_ids + 2 + SRV_MAX_N_IO_THREADS);
1742
1632
 
1743
1633
        /* Create the thread which warns of long semaphore waits */
1744
1634
        os_thread_create(&srv_error_monitor_thread, NULL,
1745
1635
                         thread_ids + 3 + SRV_MAX_N_IO_THREADS);
1746
 
 
1747
 
        /* Create the thread which prints InnoDB monitor info */
1748
 
        os_thread_create(&srv_monitor_thread, NULL,
1749
 
                         thread_ids + 4 + SRV_MAX_N_IO_THREADS);
1750
 
 
1751
1636
        srv_is_being_started = FALSE;
1752
1637
 
 
1638
        if (trx_doublewrite == NULL) {
 
1639
                /* Create the doublewrite buffer to a new tablespace */
 
1640
 
 
1641
                trx_sys_create_doublewrite_buf();
 
1642
        }
 
1643
 
1753
1644
        err = dict_create_or_check_foreign_constraint_tables();
1754
1645
 
1755
1646
        if (err != DB_SUCCESS) {
1761
1652
 
1762
1653
        os_thread_create(&srv_master_thread, NULL, thread_ids
1763
1654
                         + (1 + SRV_MAX_N_IO_THREADS));
1764
 
 
1765
 
        /* Currently we allow only a single purge thread. */
1766
 
        ut_a(srv_n_purge_threads == 0 || srv_n_purge_threads == 1);
1767
 
 
1768
 
        /* If the user has requested a separate purge thread then
1769
 
        start the purge thread. */
1770
 
        if (srv_n_purge_threads == 1) {
1771
 
                os_thread_create(&srv_purge_thread, NULL, NULL);
1772
 
        }
1773
 
 
1774
1655
#ifdef UNIV_DEBUG
1775
1656
        /* buf_debug_prints = TRUE; */
1776
1657
#endif /* UNIV_DEBUG */
1864
1745
        if (srv_print_verbose_log) {
1865
1746
                ut_print_timestamp(stderr);
1866
1747
                fprintf(stderr,
1867
 
                        "  InnoDB %s started; "
 
1748
                        " InnoDB Plugin %s started; "
1868
1749
                        "log sequence number %"PRIu64"\n",
1869
1750
                        INNODB_VERSION_STR, srv_start_lsn);
1870
1751
        }
1922
1803
                        " to an earlier version of\n"
1923
1804
                        "InnoDB: InnoDB! But if you absolutely need to"
1924
1805
                        " downgrade, see\n"
1925
 
                        "InnoDB: " REFMAN "multiple-tablespaces.html\n"
 
1806
                        "InnoDB: http://dev.mysql.com/doc/refman/5.1/en/"
 
1807
                        "multiple-tablespaces.html\n"
1926
1808
                        "InnoDB: for instructions.\n");
1927
1809
        }
1928
1810
 
1942
1824
        return((int) DB_SUCCESS);
1943
1825
}
1944
1826
 
1945
 
/****************************************************************//**
1946
 
Shuts down the InnoDB database.
1947
 
@return DB_SUCCESS or error code */
 
1827
/********************************************************************
 
1828
Shuts down the InnoDB database. */
1948
1829
UNIV_INTERN
1949
1830
int
1950
1831
innobase_shutdown_for_mysql(void)
1951
1832
/*=============================*/
 
1833
                                /* out: DB_SUCCESS or error code */
1952
1834
{
1953
1835
        ulint   i;
 
1836
#ifdef __NETWARE__
 
1837
        extern ibool panic_shutdown;
 
1838
#endif
1954
1839
        if (!srv_was_started) {
1955
1840
                if (srv_is_being_started) {
1956
1841
                        ut_print_timestamp(stderr);
1979
1864
                        "InnoDB will do a crash recovery!\n");
1980
1865
        }
1981
1866
 
1982
 
        logs_empty_and_mark_files_at_shutdown();
 
1867
#ifdef __NETWARE__
 
1868
        if(!panic_shutdown)
 
1869
#endif
 
1870
                logs_empty_and_mark_files_at_shutdown();
1983
1871
 
1984
1872
        if (srv_conc_n_threads != 0) {
1985
1873
                fprintf(stderr,
2018
1906
                /* c. We wake the master thread so that it exits */
2019
1907
                srv_wake_master_thread();
2020
1908
 
2021
 
                /* d. We wake the purge thread so that it exits */
2022
 
                srv_wake_purge_thread();
2023
 
 
2024
 
                /* e. Exit the i/o threads */
 
1909
                /* d. Exit the i/o threads */
2025
1910
 
2026
1911
                os_aio_wake_all_threads_at_shutdown();
2027
1912
 
2031
1916
                        /* All the threads have exited or are just exiting;
2032
1917
                        NOTE that the threads may not have completed their
2033
1918
                        exit yet. Should we use pthread_join() to make sure
2034
 
                        they have exited? If we did, we would have to
2035
 
                        remove the pthread_detach() from
2036
 
                        os_thread_exit().  Now we just sleep 0.1
2037
 
                        seconds and hope that is enough! */
 
1919
                        they have exited? Now we just sleep 0.1 seconds and
 
1920
                        hope that is enough! */
2038
1921
 
2039
1922
                        os_mutex_exit(os_sync_mutex);
2040
1923
 
2073
1956
                srv_misc_tmpfile = 0;
2074
1957
        }
2075
1958
 
2076
 
        /* This must be disabled before closing the buffer pool
2077
 
        and closing the data dictionary.  */
2078
 
        btr_search_disable();
2079
 
 
2080
 
        ibuf_close();
2081
 
        log_shutdown();
2082
 
        lock_sys_close();
2083
 
        thr_local_close();
2084
1959
        trx_sys_file_format_close();
2085
 
        trx_sys_close();
2086
1960
 
2087
1961
        mutex_free(&srv_monitor_file_mutex);
2088
1962
        mutex_free(&srv_dict_tmpfile_mutex);
2089
1963
        mutex_free(&srv_misc_tmpfile_mutex);
2090
 
        dict_close();
2091
 
        btr_search_sys_free();
2092
1964
 
2093
1965
        /* 3. Free all InnoDB's own mutexes and the os_fast_mutexes inside
2094
1966
        them */
2095
 
        os_aio_free();
2096
1967
        sync_close();
 
1968
 
 
1969
        /* 4. Free the os_conc_mutex and all os_events and os_mutexes */
 
1970
 
2097
1971
        srv_free();
2098
 
        fil_close();
2099
 
 
2100
 
        /* 4. Free the os_conc_mutex and all os_events and os_mutexes */
2101
 
 
2102
1972
        os_sync_free();
2103
1973
 
2104
 
        /* 5. Free all allocated memory */
2105
 
 
2106
 
        pars_lexer_close();
2107
 
        log_mem_free();
2108
 
        buf_pool_free(srv_buf_pool_instances);
2109
 
        mem_close();
2110
 
 
2111
 
        /* ut_free_all_mem() frees all allocated memory not freed yet
2112
 
        in shutdown, and it will also free the ut_list_mutex, so it
2113
 
        should be the last one for all operation */
 
1974
        /* Check that all read views are closed except read view owned
 
1975
        by a purge. */
 
1976
 
 
1977
        if (UT_LIST_GET_LEN(trx_sys->view_list) > 1) {
 
1978
                fprintf(stderr,
 
1979
                        "InnoDB: Error: all read views were not closed"
 
1980
                        " before shutdown:\n"
 
1981
                        "InnoDB: %lu read views open \n",
 
1982
                        UT_LIST_GET_LEN(trx_sys->view_list) - 1);
 
1983
        }
 
1984
 
 
1985
        /* 5. Free all allocated memory and the os_fast_mutex created in
 
1986
        ut0mem.c */
 
1987
 
 
1988
        buf_pool_free();
2114
1989
        ut_free_all_mem();
2115
1990
 
2116
1991
        if (os_thread_count != 0
2142
2017
        }
2143
2018
 
2144
2019
        srv_was_started = FALSE;
2145
 
        srv_start_has_been_called = FALSE;
2146
2020
 
2147
2021
        return((int) DB_SUCCESS);
2148
2022
}
 
2023
 
 
2024
#ifdef __NETWARE__
 
2025
void set_panic_flag_for_netware()
 
2026
{
 
2027
        extern ibool panic_shutdown;
 
2028
        panic_shutdown = TRUE;
 
2029
}
 
2030
#endif /* __NETWARE__ */
2149
2031
#endif /* !UNIV_HOTBACKUP */