~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Lee
  • Date: 2009-01-01 17:36:53 UTC
  • mto: (758.1.3 devel)
  • mto: This revision was merged to the branch mainline in revision 759.
  • Revision ID: lbieber@lbieber-desktop-20090101173653-qo5945pnje5j3vuu
more header file cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (c) 1996, 2010, Innobase Oy. All Rights Reserved.
4
 
Copyright (c) 2008, Google Inc.
5
 
Copyright (c) 2009, Percona Inc.
6
 
 
7
 
Portions of this file contain modifications contributed and copyrighted by
8
 
Google, Inc. Those modifications are gratefully acknowledged and are described
9
 
briefly in the InnoDB documentation. The contributions by Google are
10
 
incorporated with their permission, and subject to the conditions contained in
11
 
the file COPYING.Google.
12
 
 
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
 
This program is free software; you can redistribute it and/or modify it under
21
 
the terms of the GNU General Public License as published by the Free Software
22
 
Foundation; version 2 of the License.
23
 
 
24
 
This program is distributed in the hope that it will be useful, but WITHOUT
25
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
26
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
27
 
 
28
 
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
31
 
 
32
 
*****************************************************************************/
33
 
 
34
 
/********************************************************************//**
35
 
@file srv/srv0start.c
 
1
/************************************************************************
36
2
Starts the InnoDB database server
37
3
 
 
4
(c) 1996-2000 Innobase Oy
 
5
 
38
6
Created 2/16/1996 Heikki Tuuri
39
7
*************************************************************************/
40
8
 
 
9
#include "os0proc.h"
 
10
#include "sync0sync.h"
41
11
#include "ut0mem.h"
42
12
#include "mem0mem.h"
 
13
#include "mem0pool.h"
43
14
#include "data0data.h"
44
15
#include "data0type.h"
45
16
#include "dict0dict.h"
46
17
#include "buf0buf.h"
 
18
#include "buf0flu.h"
 
19
#include "buf0rea.h"
47
20
#include "os0file.h"
48
21
#include "os0thread.h"
49
22
#include "fil0fil.h"
50
23
#include "fsp0fsp.h"
51
24
#include "rem0rec.h"
 
25
#include "rem0cmp.h"
52
26
#include "mtr0mtr.h"
53
27
#include "log0log.h"
54
28
#include "log0recv.h"
55
29
#include "page0page.h"
56
30
#include "page0cur.h"
57
31
#include "trx0trx.h"
 
32
#include "dict0boot.h"
 
33
#include "dict0load.h"
58
34
#include "trx0sys.h"
 
35
#include "dict0crea.h"
59
36
#include "btr0btr.h"
 
37
#include "btr0pcur.h"
60
38
#include "btr0cur.h"
 
39
#include "btr0sea.h"
61
40
#include "rem0rec.h"
 
41
#include "srv0srv.h"
 
42
#include "que0que.h"
 
43
#include "usr0sess.h"
 
44
#include "lock0lock.h"
 
45
#include "trx0roll.h"
 
46
#include "trx0purge.h"
 
47
#include "row0ins.h"
 
48
#include "row0sel.h"
 
49
#include "row0upd.h"
 
50
#include "row0row.h"
 
51
#include "row0mysql.h"
 
52
#include "lock0lock.h"
62
53
#include "ibuf0ibuf.h"
 
54
#include "pars0pars.h"
 
55
#include "btr0sea.h"
63
56
#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 */
 
57
#include "que0que.h"
 
58
 
 
59
/* Log sequence number immediately after startup */
96
60
UNIV_INTERN ib_uint64_t srv_start_lsn;
97
 
/** Log sequence number at shutdown */
 
61
/* Log sequence number at shutdown */
98
62
UNIV_INTERN ib_uint64_t srv_shutdown_lsn;
99
63
 
100
64
#ifdef HAVE_DARWIN_THREADS
101
65
# include <sys/utsname.h>
102
 
/** TRUE if the F_FULLFSYNC option is available */
103
66
UNIV_INTERN ibool       srv_have_fullfsync = FALSE;
104
67
#endif
105
68
 
106
 
/** TRUE if a raw partition is in use */
107
69
UNIV_INTERN ibool       srv_start_raw_disk_in_use = FALSE;
108
70
 
109
 
/** TRUE if the server is being started, before rolling back any
110
 
incomplete transactions */
111
71
UNIV_INTERN ibool       srv_startup_is_before_trx_rollback_phase = FALSE;
112
 
/** TRUE if the server is being started */
113
72
UNIV_INTERN ibool       srv_is_being_started = FALSE;
114
 
/** TRUE if the server was successfully started */
115
73
UNIV_INTERN ibool       srv_was_started = FALSE;
116
 
/** TRUE if innobase_start_or_create_for_mysql() has been called */
 
74
#ifndef UNIV_HOTBACKUP
117
75
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 */
 
76
#endif /* !UNIV_HOTBACKUP */
 
77
 
 
78
/* At a shutdown the value first climbs to SRV_SHUTDOWN_CLEANUP
 
79
and then to SRV_SHUTDOWN_LAST_PHASE */
 
80
UNIV_INTERN ulint               srv_shutdown_state = 0;
 
81
 
 
82
#ifndef UNIV_HOTBACKUP
124
83
static os_file_t        files[1000];
125
84
 
126
 
/** Mutex protecting the ios count */
127
85
static mutex_t          ios_mutex;
128
 
/** Count of I/O operations in io_handler_thread() */
129
86
static ulint            ios;
130
87
 
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];
 
88
static ulint            n[SRV_MAX_N_IO_THREADS + 5];
 
89
static os_thread_id_t   thread_ids[SRV_MAX_N_IO_THREADS + 5];
135
90
 
136
 
/** We use this mutex to test the return value of pthread_mutex_trylock
 
91
/* We use this mutex to test the return value of pthread_mutex_trylock
137
92
   on successful locking. HP-UX does NOT return 0, though Linux et al do. */
138
93
static os_fast_mutex_t  srv_os_test_mutex;
139
94
 
140
 
/** Name of srv_monitor_file */
 
95
/* Name of srv_monitor_file */
141
96
static char*    srv_monitor_file_name;
142
97
#endif /* !UNIV_HOTBACKUP */
143
98
 
144
 
/** */
145
99
#define SRV_N_PENDING_IOS_PER_THREAD    OS_AIO_N_PENDING_IOS_PER_THREAD
146
100
#define SRV_MAX_N_PENDING_SYNC_IOS      100
147
101
 
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 */
 
102
 
 
103
/* Avoid warnings when using purify */
 
104
 
 
105
#ifdef HAVE_purify
 
106
static int inno_bcmp(register const char *s1, register const char *s2,
 
107
        register uint len)
 
108
{
 
109
        while ((len-- != 0) && (*s1++ == *s2++))
 
110
                ;
 
111
 
 
112
        return(len + 1);
 
113
}
 
114
#define memcmp(A,B,C) inno_bcmp((A),(B),(C))
 
115
#endif
 
116
 
166
117
static
167
118
char*
168
119
srv_parse_megabytes(
169
120
/*================*/
170
 
        char*   str,    /*!< in: string containing a quantity in bytes */
171
 
        ulint*  megs)   /*!< out: the number in megabytes */
 
121
                        /* out: next character in string */
 
122
        char*   str,    /* in: string containing a quantity in bytes */
 
123
        ulint*  megs)   /* out: the number in megabytes */
172
124
{
173
125
        char*   endp;
174
126
        ulint   size;
193
145
        return(str);
194
146
}
195
147
 
196
 
/*********************************************************************//**
 
148
/*************************************************************************
197
149
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 */
 
150
the .cnf file. */
200
151
UNIV_INTERN
201
152
ibool
202
153
srv_parse_data_file_paths_and_sizes(
203
154
/*================================*/
204
 
        char*   str)    /*!< in/out: the data file path string */
 
155
                                        /* out: TRUE if ok, FALSE if parsing
 
156
                                        error */
 
157
        char*   str,                    /* in: the data file path string */
 
158
        char*** data_file_names,        /* out, own: array of data file
 
159
                                        names */
 
160
        ulint** data_file_sizes,        /* out, own: array of data file sizes
 
161
                                        in megabytes */
 
162
        ulint** data_file_is_raw_partition,/* out, own: array of flags
 
163
                                        showing which data files are raw
 
164
                                        partitions */
 
165
        ulint*  n_data_files,           /* out: number of data files */
 
166
        ibool*  is_auto_extending,      /* out: TRUE if the last data file is
 
167
                                        auto-extending */
 
168
        ulint*  max_auto_extend_size)   /* out: max auto extend size for the
 
169
                                        last file if specified, 0 if not */
205
170
{
206
171
        char*   input_str;
207
172
        char*   path;
208
173
        ulint   size;
209
174
        ulint   i       = 0;
210
175
 
211
 
        srv_auto_extend_last_data_file = FALSE;
212
 
        srv_last_file_size_max = 0;
213
 
        srv_data_file_names = NULL;
214
 
        srv_data_file_sizes = NULL;
215
 
        srv_data_file_is_raw_partition = NULL;
 
176
        *is_auto_extending = FALSE;
 
177
        *max_auto_extend_size = 0;
216
178
 
217
179
        input_str = str;
218
180
 
289
251
                return(FALSE);
290
252
        }
291
253
 
292
 
        srv_data_file_names = malloc(i * sizeof *srv_data_file_names);
293
 
        srv_data_file_sizes = malloc(i * sizeof *srv_data_file_sizes);
294
 
        srv_data_file_is_raw_partition = malloc(
295
 
                i * sizeof *srv_data_file_is_raw_partition);
 
254
        *data_file_names = (char**)ut_malloc(i * sizeof(void*));
 
255
        *data_file_sizes = (ulint*)ut_malloc(i * sizeof(ulint));
 
256
        *data_file_is_raw_partition = (ulint*)ut_malloc(i * sizeof(ulint));
296
257
 
297
 
        srv_n_data_files = i;
 
258
        *n_data_files = i;
298
259
 
299
260
        /* Then store the actual values to our arrays */
300
261
 
324
285
 
325
286
                str = srv_parse_megabytes(str, &size);
326
287
 
327
 
                srv_data_file_names[i] = path;
328
 
                srv_data_file_sizes[i] = size;
 
288
                (*data_file_names)[i] = path;
 
289
                (*data_file_sizes)[i] = size;
329
290
 
330
291
                if (0 == strncmp(str, ":autoextend",
331
292
                                 (sizeof ":autoextend") - 1)) {
332
293
 
333
 
                        srv_auto_extend_last_data_file = TRUE;
 
294
                        *is_auto_extending = TRUE;
334
295
 
335
296
                        str += (sizeof ":autoextend") - 1;
336
297
 
340
301
                                str += (sizeof ":max:") - 1;
341
302
 
342
303
                                str = srv_parse_megabytes(
343
 
                                        str, &srv_last_file_size_max);
 
304
                                        str, max_auto_extend_size);
344
305
                        }
345
306
 
346
307
                        if (*str != '\0') {
349
310
                        }
350
311
                }
351
312
 
352
 
                (srv_data_file_is_raw_partition)[i] = 0;
 
313
                (*data_file_is_raw_partition)[i] = 0;
353
314
 
354
315
                if (strlen(str) >= 6
355
316
                    && *str == 'n'
356
317
                    && *(str + 1) == 'e'
357
318
                    && *(str + 2) == 'w') {
358
319
                        str += 3;
359
 
                        (srv_data_file_is_raw_partition)[i] = SRV_NEW_RAW;
 
320
                        (*data_file_is_raw_partition)[i] = SRV_NEW_RAW;
360
321
                }
361
322
 
362
323
                if (*str == 'r' && *(str + 1) == 'a' && *(str + 2) == 'w') {
363
324
                        str += 3;
364
325
 
365
 
                        if ((srv_data_file_is_raw_partition)[i] == 0) {
366
 
                                (srv_data_file_is_raw_partition)[i] = SRV_OLD_RAW;
 
326
                        if ((*data_file_is_raw_partition)[i] == 0) {
 
327
                                (*data_file_is_raw_partition)[i] = SRV_OLD_RAW;
367
328
                        }
368
329
                }
369
330
 
377
338
        return(TRUE);
378
339
}
379
340
 
380
 
/*********************************************************************//**
 
341
/*************************************************************************
381
342
Reads log group home directories from a character string given in
382
 
the .cnf file.
383
 
@return TRUE if ok, FALSE on parse error */
 
343
the .cnf file. */
384
344
UNIV_INTERN
385
345
ibool
386
346
srv_parse_log_group_home_dirs(
387
347
/*==========================*/
388
 
        char*   str)    /*!< in/out: character string */
 
348
                                        /* out: TRUE if ok, FALSE if parsing
 
349
                                        error */
 
350
        char*   str,                    /* in: character string */
 
351
        char*** log_group_home_dirs)    /* out, own: log group home dirs */
389
352
{
390
353
        char*   input_str;
391
354
        char*   path;
392
355
        ulint   i       = 0;
393
356
 
394
 
        srv_log_group_home_dirs = NULL;
395
 
 
396
357
        input_str = str;
397
358
 
398
359
        /* First calculate the number of directories and check syntax:
422
383
                return(FALSE);
423
384
        }
424
385
 
425
 
        srv_log_group_home_dirs = malloc(i * sizeof *srv_log_group_home_dirs);
 
386
        *log_group_home_dirs = (char**) ut_malloc(i * sizeof(void*));
426
387
 
427
388
        /* Then store the actual values to our array */
428
389
 
441
402
                        str++;
442
403
                }
443
404
 
444
 
                srv_log_group_home_dirs[i] = path;
 
405
                (*log_group_home_dirs)[i] = path;
445
406
 
446
407
                i++;
447
408
        }
449
410
        return(TRUE);
450
411
}
451
412
 
452
 
/*********************************************************************//**
453
 
Frees the memory allocated by srv_parse_data_file_paths_and_sizes()
454
 
and srv_parse_log_group_home_dirs(). */
455
 
UNIV_INTERN
456
 
void
457
 
srv_free_paths_and_sizes(void)
458
 
/*==========================*/
459
 
{
460
 
        free(srv_data_file_names);
461
 
        srv_data_file_names = NULL;
462
 
        free(srv_data_file_sizes);
463
 
        srv_data_file_sizes = NULL;
464
 
        free(srv_data_file_is_raw_partition);
465
 
        srv_data_file_is_raw_partition = NULL;
466
 
        free(srv_log_group_home_dirs);
467
 
        srv_log_group_home_dirs = NULL;
468
 
}
469
 
 
470
413
#ifndef UNIV_HOTBACKUP
471
 
/********************************************************************//**
472
 
I/o-handler thread function.
473
 
@return OS_THREAD_DUMMY_RETURN */
 
414
/************************************************************************
 
415
I/o-handler thread function. */
474
416
static
 
417
 
475
418
os_thread_ret_t
476
419
io_handler_thread(
477
420
/*==============*/
478
 
        void*   arg)    /*!< in: pointer to the number of the segment in
479
 
                        the aio array */
 
421
        void*   arg)
480
422
{
481
423
        ulint   segment;
 
424
        ulint   i;
482
425
 
483
426
        segment = *((ulint*)arg);
484
427
 
486
429
        fprintf(stderr, "Io handler thread %lu starts, id %lu\n", segment,
487
430
                os_thread_pf(os_thread_get_curr_id()));
488
431
#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) {
 
432
        for (i = 0;; i++) {
495
433
                fil_aio_wait(segment);
496
434
 
497
435
                mutex_enter(&ios_mutex);
499
437
                mutex_exit(&ios_mutex);
500
438
        }
501
439
 
502
 
        thr_local_free(os_thread_get_curr_id());
503
 
 
504
440
        /* We count the number of threads in os_thread_exit(). A created
505
441
        thread should always use that to exit and not use return() to exit.
506
442
        The thread actually never comes here because it is exited in an
507
443
        os_event_wait(). */
508
 
        return 0;
 
444
 
 
445
        os_thread_exit(NULL);
 
446
 
 
447
        OS_THREAD_DUMMY_RETURN;
509
448
}
510
449
#endif /* !UNIV_HOTBACKUP */
511
450
 
515
454
#define SRV_PATH_SEPARATOR      '/'
516
455
#endif
517
456
 
518
 
/*********************************************************************//**
 
457
/*************************************************************************
519
458
Normalizes a directory path for Windows: converts slashes to backslashes. */
520
459
UNIV_INTERN
521
460
void
522
461
srv_normalize_path_for_win(
523
462
/*=======================*/
524
 
        char*   str __attribute__((unused)))    /*!< in/out: null-terminated
 
463
        char*   str __attribute__((unused)))    /* in/out: null-terminated
525
464
                                                character string */
526
465
{
527
466
#ifdef __WIN__
534
473
#endif
535
474
}
536
475
 
 
476
/*************************************************************************
 
477
Adds a slash or a backslash to the end of a string if it is missing
 
478
and the string is not empty. */
 
479
UNIV_INTERN
 
480
char*
 
481
srv_add_path_separator_if_needed(
 
482
/*=============================*/
 
483
                        /* out: string which has the separator if the
 
484
                        string is not empty */
 
485
        char*   str)    /* in: null-terminated character string */
 
486
{
 
487
        char*   out_str;
 
488
        ulint   len     = ut_strlen(str);
 
489
 
 
490
        if (len == 0 || str[len - 1] == SRV_PATH_SEPARATOR) {
 
491
 
 
492
                return(str);
 
493
        }
 
494
 
 
495
        out_str = ut_malloc(len + 2);
 
496
        memcpy(out_str, str, len);
 
497
        out_str[len] = SRV_PATH_SEPARATOR;
 
498
        out_str[len + 1] = 0;
 
499
 
 
500
        return(out_str);
 
501
}
 
502
 
537
503
#ifndef UNIV_HOTBACKUP
538
 
/*********************************************************************//**
 
504
/*************************************************************************
539
505
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 */
 
506
database pages is converted to the number of bytes. */
542
507
static
543
508
ulint
544
509
srv_calc_low32(
545
510
/*===========*/
546
 
        ulint   file_size)      /*!< in: file size in database pages */
 
511
                                /* out: low 32 bytes of file size when
 
512
                                expressed in bytes */
 
513
        ulint   file_size)      /* in: file size in database pages */
547
514
{
548
515
        return(0xFFFFFFFFUL & (file_size << UNIV_PAGE_SIZE_SHIFT));
549
516
}
550
517
 
551
 
/*********************************************************************//**
 
518
/*************************************************************************
552
519
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 */
 
520
database pages is converted to the number of bytes. */
555
521
static
556
522
ulint
557
523
srv_calc_high32(
558
524
/*============*/
559
 
        ulint   file_size)      /*!< in: file size in database pages */
 
525
                                /* out: high 32 bytes of file size when
 
526
                                expressed in bytes */
 
527
        ulint   file_size)      /* in: file size in database pages */
560
528
{
561
529
        return(file_size >> (32 - UNIV_PAGE_SIZE_SHIFT));
562
530
}
563
531
 
564
 
/*********************************************************************//**
565
 
Creates or opens the log files and closes them.
566
 
@return DB_SUCCESS or error code */
 
532
/*************************************************************************
 
533
Creates or opens the log files and closes them. */
567
534
static
568
535
ulint
569
536
open_or_create_log_file(
570
537
/*====================*/
571
 
        ibool   create_new_db,          /*!< in: TRUE if we should create a
 
538
                                        /* out: DB_SUCCESS or error code */
 
539
        ibool   create_new_db,          /* in: TRUE if we should create a
572
540
                                        new database */
573
 
        ibool*  log_file_created,       /*!< out: TRUE if new log file
 
541
        ibool*  log_file_created,       /* out: TRUE if new log file
574
542
                                        created */
575
 
        ibool   log_file_has_been_opened,/*!< in: TRUE if a log file has been
 
543
        ibool   log_file_has_been_opened,/* in: TRUE if a log file has been
576
544
                                        opened before: then it is an error
577
545
                                        to try to create another log file */
578
 
        ulint   k,                      /*!< in: log group number */
579
 
        ulint   i)                      /*!< in: log file number in group */
 
546
        ulint   k,                      /* in: log group number */
 
547
        ulint   i)                      /* in: log file number in group */
580
548
{
581
549
        ibool   ret;
582
550
        ulint   size;
583
551
        ulint   size_high;
584
552
        char    name[10000];
585
 
        ulint   dirnamelen;
586
553
 
587
554
        UT_NOT_USED(create_new_db);
588
555
 
589
556
        *log_file_created = FALSE;
590
557
 
591
558
        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,
 
559
        srv_log_group_home_dirs[k] = srv_add_path_separator_if_needed(
 
560
                srv_log_group_home_dirs[k]);
 
561
 
 
562
        ut_a(strlen(srv_log_group_home_dirs[k])
 
563
             < (sizeof name) - 10 - sizeof "ib_logfile");
 
564
        sprintf(name, "%s%s%lu", srv_log_group_home_dirs[k],
 
565
                "ib_logfile", (ulong) i);
 
566
 
 
567
        files[i] = os_file_create(name, OS_FILE_CREATE, OS_FILE_NORMAL,
606
568
                                  OS_LOG_FILE, &ret);
607
569
        if (ret == FALSE) {
608
570
                if (os_file_get_last_error(FALSE) != OS_FILE_ALREADY_EXISTS
620
582
                        return(DB_ERROR);
621
583
                }
622
584
 
623
 
                files[i] = os_file_create(innodb_file_log_key, name,
624
 
                                          OS_FILE_OPEN, OS_FILE_AIO,
 
585
                files[i] = os_file_create(name, OS_FILE_OPEN, OS_FILE_AIO,
625
586
                                          OS_LOG_FILE, &ret);
626
587
                if (!ret) {
627
588
                        fprintf(stderr,
721
682
        return(DB_SUCCESS);
722
683
}
723
684
 
724
 
/*********************************************************************//**
725
 
Creates or opens database data files and closes them.
726
 
@return DB_SUCCESS or error code */
 
685
/*************************************************************************
 
686
Creates or opens database data files and closes them. */
727
687
static
728
688
ulint
729
689
open_or_create_data_files(
730
690
/*======================*/
731
 
        ibool*          create_new_db,  /*!< out: TRUE if new database should be
 
691
                                        /* out: DB_SUCCESS or error code */
 
692
        ibool*          create_new_db,  /* out: TRUE if new database should be
732
693
                                        created */
733
694
#ifdef UNIV_LOG_ARCHIVE
734
 
        ulint*          min_arch_log_no,/*!< out: min of archived log
 
695
        ulint*          min_arch_log_no,/* out: min of archived log
735
696
                                        numbers in data files */
736
 
        ulint*          max_arch_log_no,/*!< out: max of archived log
 
697
        ulint*          max_arch_log_no,/* out: max of archived log
737
698
                                        numbers in data files */
738
699
#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
 
700
        ib_uint64_t*    min_flushed_lsn,/* out: min of flushed lsn
 
701
                                        values in data files */
 
702
        ib_uint64_t*    max_flushed_lsn,/* out: max of flushed lsn
 
703
                                        values in data files */
 
704
        ulint*          sum_of_new_sizes)/* out: sum of sizes of the
744
705
                                        new files added */
745
706
{
746
707
        ibool   ret;
764
725
        *create_new_db = FALSE;
765
726
 
766
727
        srv_normalize_path_for_win(srv_data_home);
 
728
        srv_data_home = srv_add_path_separator_if_needed(srv_data_home);
767
729
 
768
730
        for (i = 0; i < srv_n_data_files; i++) {
769
 
                ulint   dirnamelen;
770
 
 
771
731
                srv_normalize_path_for_win(srv_data_file_names[i]);
772
 
                dirnamelen = strlen(srv_data_home);
773
732
 
774
 
                ut_a(dirnamelen + strlen(srv_data_file_names[i])
 
733
                ut_a(strlen(srv_data_home) + strlen(srv_data_file_names[i])
775
734
                     < (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]);
 
735
                sprintf(name, "%s%s", srv_data_home, srv_data_file_names[i]);
783
736
 
784
737
                if (srv_data_file_is_raw_partition[i] == 0) {
785
738
 
786
739
                        /* First we try to create the file: if it already
787
740
                        exists, ret will get value FALSE */
788
741
 
789
 
                        files[i] = os_file_create(innodb_file_data_key,
790
 
                                                  name, OS_FILE_CREATE,
 
742
                        files[i] = os_file_create(name, OS_FILE_CREATE,
791
743
                                                  OS_FILE_NORMAL,
792
744
                                                  OS_DATA_FILE, &ret);
793
745
 
814
766
                        srv_start_raw_disk_in_use = TRUE;
815
767
                        srv_created_new_raw = TRUE;
816
768
 
817
 
                        files[i] = os_file_create(innodb_file_data_key,
818
 
                                                  name, OS_FILE_OPEN_RAW,
 
769
                        files[i] = os_file_create(name, OS_FILE_OPEN_RAW,
819
770
                                                  OS_FILE_NORMAL,
820
771
                                                  OS_DATA_FILE, &ret);
821
772
                        if (!ret) {
848
799
 
849
800
                        if (srv_data_file_is_raw_partition[i] == SRV_OLD_RAW) {
850
801
                                files[i] = os_file_create(
851
 
                                        innodb_file_data_key,
852
802
                                        name, OS_FILE_OPEN_RAW,
853
803
                                        OS_FILE_NORMAL, OS_DATA_FILE, &ret);
854
804
                        } else if (i == 0) {
855
805
                                files[i] = os_file_create(
856
 
                                        innodb_file_data_key,
857
806
                                        name, OS_FILE_OPEN_RETRY,
858
807
                                        OS_FILE_NORMAL, OS_DATA_FILE, &ret);
859
808
                        } else {
860
809
                                files[i] = os_file_create(
861
 
                                        innodb_file_data_key,
862
810
                                        name, OS_FILE_OPEN, OS_FILE_NORMAL,
863
811
                                        OS_DATA_FILE, &ret);
864
812
                        }
1001
949
 
1002
950
        ios = 0;
1003
951
 
1004
 
        mutex_create(ios_mutex_key, &ios_mutex, SYNC_NO_ORDER_CHECK);
 
952
        mutex_create(&ios_mutex, SYNC_NO_ORDER_CHECK);
1005
953
 
1006
954
        return(DB_SUCCESS);
1007
955
}
1008
956
 
1009
957
/********************************************************************
1010
958
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 */
 
959
are not found and the user wants. Server parameters are
 
960
read from a file of name "srv_init" in the ib_home directory. */
1013
961
UNIV_INTERN
1014
962
int
1015
963
innobase_start_or_create_for_mysql(void)
1016
964
/*====================================*/
 
965
                                /* out: DB_SUCCESS or error code */
1017
966
{
 
967
        buf_pool_t*     ret;
1018
968
        ibool           create_new_db;
1019
969
        ibool           log_file_created;
1020
970
        ibool           log_created     = FALSE;
1030
980
        ulint           tablespace_size_in_header;
1031
981
        ulint           err;
1032
982
        ulint           i;
1033
 
        ulint           io_limit;
1034
983
        my_bool         srv_file_per_table_original_value
1035
984
                = srv_file_per_table;
1036
985
        mtr_t           mtr;
1080
1029
#ifdef UNIV_IBUF_DEBUG
1081
1030
        fprintf(stderr,
1082
1031
                "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
 
                );
 
1032
                "InnoDB: Crash recovery will fail with UNIV_IBUF_DEBUG\n");
1088
1033
#endif
1089
1034
 
1090
1035
#ifdef UNIV_SYNC_DEBUG
1097
1042
                "InnoDB: !!!!!!!! UNIV_SEARCH_DEBUG switched on !!!!!!!!!\n");
1098
1043
#endif
1099
1044
 
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
1045
#ifdef UNIV_MEM_DEBUG
1105
1046
        fprintf(stderr,
1106
1047
                "InnoDB: !!!!!!!! UNIV_MEM_DEBUG switched on !!!!!!!!!\n");
1107
1048
#endif
1108
1049
 
1109
 
        if (UNIV_LIKELY(srv_use_sys_malloc)) {
1110
 
                fprintf(stderr,
1111
 
                        "InnoDB: The InnoDB memory heap is disabled\n");
1112
 
        }
1113
 
 
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
 
 
1124
 
 
1125
1050
        /* Since InnoDB does not currently clean up all its internal data
1126
1051
        structures in MySQL Embedded Server Library server_end(), we
1127
1052
        print an error message if someone tries to start up InnoDB a
1129
1054
 
1130
1055
        if (srv_start_has_been_called) {
1131
1056
                fprintf(stderr,
1132
 
                        "InnoDB: Error: startup called second time"
 
1057
                        "InnoDB: Error:startup called second time"
1133
1058
                        " during the process lifetime.\n"
1134
1059
                        "InnoDB: In the MySQL Embedded Server Library"
1135
1060
                        " you cannot call server_init()\n"
1146
1071
 
1147
1072
        srv_is_being_started = TRUE;
1148
1073
        srv_startup_is_before_trx_rollback_phase = TRUE;
 
1074
        os_aio_use_native_aio = FALSE;
1149
1075
 
1150
1076
#ifdef __WIN__
1151
 
        switch (os_get_os_version()) {
1152
 
        case OS_WIN95:
1153
 
        case OS_WIN31:
1154
 
        case OS_WINNT:
 
1077
        if (os_get_os_version() == OS_WIN95
 
1078
            || os_get_os_version() == OS_WIN31
 
1079
            || os_get_os_version() == OS_WINNT) {
 
1080
 
1155
1081
                /* On Win 95, 98, ME, Win32 subsystem for Windows 3.1,
1156
1082
                and NT use simulated aio. In NT Windows provides async i/o,
1157
1083
                but when run in conjunction with InnoDB Hot Backup, it seemed
1158
1084
                to corrupt the data files. */
1159
1085
 
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
 
 
 
1086
                os_aio_use_native_aio = FALSE;
 
1087
        } else {
 
1088
                /* On Win 2000 and XP use async i/o */
 
1089
                os_aio_use_native_aio = TRUE;
 
1090
        }
1189
1091
#endif
1190
 
 
1191
1092
        if (srv_file_flush_method_str == NULL) {
1192
1093
                /* These are the default options */
1193
1094
 
1212
1113
#else
1213
1114
        } else if (0 == ut_strcmp(srv_file_flush_method_str, "normal")) {
1214
1115
                srv_win_file_flush_method = SRV_WIN_IO_NORMAL;
1215
 
                srv_use_native_aio = FALSE;
 
1116
                os_aio_use_native_aio = FALSE;
1216
1117
 
1217
1118
        } else if (0 == ut_strcmp(srv_file_flush_method_str, "unbuffered")) {
1218
1119
                srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
1219
 
                srv_use_native_aio = FALSE;
 
1120
                os_aio_use_native_aio = FALSE;
1220
1121
 
1221
1122
        } else if (0 == ut_strcmp(srv_file_flush_method_str,
1222
1123
                                  "async_unbuffered")) {
1238
1139
        maximum number of threads that can wait in the 'srv_conc array' for
1239
1140
        their time to enter InnoDB. */
1240
1141
 
 
1142
#if defined(__NETWARE__)
 
1143
 
 
1144
        /* Create less event semaphores because Win 98/ME had
 
1145
        difficulty creating 40000 event semaphores.  Comment from
 
1146
        Novell, Inc.: also, these just take a lot of memory on
 
1147
        NetWare. */
 
1148
        srv_max_n_threads = 1000;
 
1149
#else
1241
1150
        if (srv_buf_pool_size >= 1000 * 1024 * 1024) {
1242
1151
                /* If buffer pool is less than 1000 MB,
1243
 
                assume fewer threads. Also use only one
1244
 
                buffer pool instance */
 
1152
                assume fewer threads. */
1245
1153
                srv_max_n_threads = 50000;
1246
1154
 
1247
1155
        } else if (srv_buf_pool_size >= 8 * 1024 * 1024) {
1248
1156
 
1249
 
                srv_buf_pool_instances = 1;
1250
1157
                srv_max_n_threads = 10000;
1251
1158
        } else {
1252
 
                srv_buf_pool_instances = 1;
1253
1159
                srv_max_n_threads = 1000;       /* saves several MB of memory,
1254
1160
                                                especially in 64-bit
1255
1161
                                                computers */
1256
1162
        }
1257
 
 
 
1163
#endif
1258
1164
        err = srv_boot();
1259
1165
 
1260
1166
        if (err != DB_SUCCESS) {
1262
1168
                return((int) err);
1263
1169
        }
1264
1170
 
1265
 
        mutex_create(srv_monitor_file_mutex_key,
1266
 
                     &srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK);
 
1171
        mutex_create(&srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK);
1267
1172
 
1268
1173
        if (srv_innodb_status) {
1269
1174
                srv_monitor_file_name = mem_alloc(
1285
1190
                }
1286
1191
        }
1287
1192
 
1288
 
        mutex_create(srv_dict_tmpfile_mutex_key,
1289
 
                     &srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION);
 
1193
        mutex_create(&srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION);
1290
1194
 
1291
1195
        srv_dict_tmpfile = os_file_create_tmpfile();
1292
1196
        if (!srv_dict_tmpfile) {
1293
1197
                return(DB_ERROR);
1294
1198
        }
1295
1199
 
1296
 
        mutex_create(srv_misc_tmpfile_mutex_key,
1297
 
                     &srv_misc_tmpfile_mutex, SYNC_ANY_LATCH);
 
1200
        mutex_create(&srv_misc_tmpfile_mutex, SYNC_ANY_LATCH);
1298
1201
 
1299
1202
        srv_misc_tmpfile = os_file_create_tmpfile();
1300
1203
        if (!srv_misc_tmpfile) {
1301
1204
                return(DB_ERROR);
1302
1205
        }
1303
1206
 
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) {
 
1207
        /* Restrict the maximum number of file i/o threads */
 
1208
        if (srv_n_file_io_threads > SRV_MAX_N_IO_THREADS) {
 
1209
 
 
1210
                srv_n_file_io_threads = SRV_MAX_N_IO_THREADS;
 
1211
        }
 
1212
 
 
1213
        if (!os_aio_use_native_aio) {
 
1214
                /* In simulated aio we currently have use only for 4 threads */
 
1215
                srv_n_file_io_threads = 4;
 
1216
 
 
1217
                os_aio_init(8 * SRV_N_PENDING_IOS_PER_THREAD
 
1218
                            * srv_n_file_io_threads,
 
1219
                            srv_n_file_io_threads,
 
1220
                            SRV_MAX_N_PENDING_SYNC_IOS);
 
1221
        } else {
 
1222
                os_aio_init(SRV_N_PENDING_IOS_PER_THREAD
 
1223
                            * srv_n_file_io_threads,
 
1224
                            srv_n_file_io_threads,
 
1225
                            SRV_MAX_N_PENDING_SYNC_IOS);
 
1226
        }
 
1227
 
 
1228
        fil_init(srv_max_n_open_files);
 
1229
 
 
1230
        ret = buf_pool_init();
 
1231
 
 
1232
        if (ret == NULL) {
1352
1233
                fprintf(stderr,
1353
1234
                        "InnoDB: Fatal error: cannot allocate the memory"
1354
1235
                        " for the buffer pool\n");
1418
1299
                sum_of_new_sizes += srv_data_file_sizes[i];
1419
1300
        }
1420
1301
 
1421
 
        if (sum_of_new_sizes < 10485760 / UNIV_PAGE_SIZE) {
 
1302
        if (sum_of_new_sizes < 640) {
1422
1303
                fprintf(stderr,
1423
1304
                        "InnoDB: Error: tablespace size must be"
1424
1305
                        " at least 10 MB\n");
1545
1426
 
1546
1427
        if (create_new_db) {
1547
1428
                mtr_start(&mtr);
1548
 
 
1549
1429
                fsp_header_init(0, sum_of_new_sizes, &mtr);
1550
1430
 
1551
1431
                mtr_commit(&mtr);
1552
1432
 
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
1433
                trx_sys_create();
1558
 
 
1559
1434
                dict_create();
1560
 
 
1561
1435
                srv_startup_is_before_trx_rollback_phase = FALSE;
1562
1436
 
1563
1437
#ifdef UNIV_LOG_ARCHIVE
1576
1450
                in any disk i/o, first call dict_boot */
1577
1451
 
1578
1452
                dict_boot();
1579
 
 
1580
1453
                trx_sys_init_at_db_start();
1581
 
 
1582
1454
                srv_startup_is_before_trx_rollback_phase = FALSE;
1583
1455
 
1584
1456
                /* Initialize the fsp free limit global variable in the log
1602
1474
                consistent state, this is REQUIRED for the recovery
1603
1475
                process to work. */
1604
1476
                err = trx_sys_file_format_max_check(
1605
 
                        srv_max_file_format_at_startup);
 
1477
                        srv_check_file_format_at_startup);
1606
1478
 
1607
1479
                if (err != DB_SUCCESS) {
1608
1480
                        return(err);
1636
1508
                dict_boot();
1637
1509
                trx_sys_init_at_db_start();
1638
1510
 
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
1511
                if (srv_force_recovery < SRV_FORCE_NO_IBUF_MERGE) {
1648
1512
                        /* The following call is necessary for the insert
1649
1513
                        buffer to work with multiple tablespaces. We must
1659
1523
                        every table in the InnoDB data dictionary that has
1660
1524
                        an .ibd file.
1661
1525
 
1662
 
                        We also determine the maximum tablespace id used. */
 
1526
                        We also determine the maximum tablespace id used.
 
1527
 
 
1528
                        TODO: We may have incomplete transactions in the
 
1529
                        data dictionary tables. Does that harm the scanning of
 
1530
                        the data dictionary below? */
1663
1531
 
1664
1532
                        dict_check_tablespaces_and_store_max_id(
1665
1533
                                recv_needed_recovery);
1666
1534
                }
1667
1535
 
1668
1536
                srv_startup_is_before_trx_rollback_phase = FALSE;
1669
 
                recv_recovery_rollback_active();
 
1537
 
 
1538
                /* Initialize the fsp free limit global variable in the log
 
1539
                system */
 
1540
                fsp_header_get_free_limit();
 
1541
 
 
1542
                /* recv_recovery_from_checkpoint_finish needs trx lists which
 
1543
                are initialized in trx_sys_init_at_db_start(). */
 
1544
 
 
1545
                recv_recovery_from_checkpoint_finish();
1670
1546
 
1671
1547
                /* It is possible that file_format tag has never
1672
1548
                been set. In this case we initialize it to minimum
1715
1591
        /* fprintf(stderr, "Max allowed record size %lu\n",
1716
1592
        page_get_free_space_of_empty() / 2); */
1717
1593
 
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,
 
1594
        /* Create the thread which watches the timeouts for lock waits
 
1595
        and prints InnoDB monitor info */
 
1596
 
 
1597
        os_thread_create(&srv_lock_timeout_and_monitor_thread, NULL,
1741
1598
                         thread_ids + 2 + SRV_MAX_N_IO_THREADS);
1742
1599
 
1743
1600
        /* Create the thread which warns of long semaphore waits */
1744
1601
        os_thread_create(&srv_error_monitor_thread, NULL,
1745
1602
                         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
1603
        srv_is_being_started = FALSE;
1752
1604
 
 
1605
        if (trx_doublewrite == NULL) {
 
1606
                /* Create the doublewrite buffer to a new tablespace */
 
1607
 
 
1608
                trx_sys_create_doublewrite_buf();
 
1609
        }
 
1610
 
1753
1611
        err = dict_create_or_check_foreign_constraint_tables();
1754
1612
 
1755
1613
        if (err != DB_SUCCESS) {
1761
1619
 
1762
1620
        os_thread_create(&srv_master_thread, NULL, thread_ids
1763
1621
                         + (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
1622
#ifdef UNIV_DEBUG
1775
1623
        /* buf_debug_prints = TRUE; */
1776
1624
#endif /* UNIV_DEBUG */
1864
1712
        if (srv_print_verbose_log) {
1865
1713
                ut_print_timestamp(stderr);
1866
1714
                fprintf(stderr,
1867
 
                        "  InnoDB %s started; "
 
1715
                        " InnoDB Plugin %s started; "
1868
1716
                        "log sequence number %"PRIu64"\n",
1869
1717
                        INNODB_VERSION_STR, srv_start_lsn);
1870
1718
        }
1922
1770
                        " to an earlier version of\n"
1923
1771
                        "InnoDB: InnoDB! But if you absolutely need to"
1924
1772
                        " downgrade, see\n"
1925
 
                        "InnoDB: " REFMAN "multiple-tablespaces.html\n"
 
1773
                        "InnoDB: http://dev.mysql.com/doc/refman/5.1/en/"
 
1774
                        "multiple-tablespaces.html\n"
1926
1775
                        "InnoDB: for instructions.\n");
1927
1776
        }
1928
1777
 
1942
1791
        return((int) DB_SUCCESS);
1943
1792
}
1944
1793
 
1945
 
/****************************************************************//**
1946
 
Shuts down the InnoDB database.
1947
 
@return DB_SUCCESS or error code */
 
1794
/********************************************************************
 
1795
Shuts down the InnoDB database. */
1948
1796
UNIV_INTERN
1949
1797
int
1950
1798
innobase_shutdown_for_mysql(void)
1951
1799
/*=============================*/
 
1800
                                /* out: DB_SUCCESS or error code */
1952
1801
{
1953
1802
        ulint   i;
 
1803
#ifdef __NETWARE__
 
1804
        extern ibool panic_shutdown;
 
1805
#endif
1954
1806
        if (!srv_was_started) {
1955
1807
                if (srv_is_being_started) {
1956
1808
                        ut_print_timestamp(stderr);
1979
1831
                        "InnoDB will do a crash recovery!\n");
1980
1832
        }
1981
1833
 
1982
 
        logs_empty_and_mark_files_at_shutdown();
 
1834
#ifdef __NETWARE__
 
1835
        if(!panic_shutdown)
 
1836
#endif
 
1837
                logs_empty_and_mark_files_at_shutdown();
1983
1838
 
1984
1839
        if (srv_conc_n_threads != 0) {
1985
1840
                fprintf(stderr,
2018
1873
                /* c. We wake the master thread so that it exits */
2019
1874
                srv_wake_master_thread();
2020
1875
 
2021
 
                /* d. We wake the purge thread so that it exits */
2022
 
                srv_wake_purge_thread();
2023
 
 
2024
 
                /* e. Exit the i/o threads */
 
1876
                /* d. Exit the i/o threads */
2025
1877
 
2026
1878
                os_aio_wake_all_threads_at_shutdown();
2027
1879
 
2031
1883
                        /* All the threads have exited or are just exiting;
2032
1884
                        NOTE that the threads may not have completed their
2033
1885
                        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! */
 
1886
                        they have exited? Now we just sleep 0.1 seconds and
 
1887
                        hope that is enough! */
2038
1888
 
2039
1889
                        os_mutex_exit(os_sync_mutex);
2040
1890
 
2073
1923
                srv_misc_tmpfile = 0;
2074
1924
        }
2075
1925
 
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
1926
        trx_sys_file_format_close();
2085
 
        trx_sys_close();
2086
1927
 
2087
1928
        mutex_free(&srv_monitor_file_mutex);
2088
1929
        mutex_free(&srv_dict_tmpfile_mutex);
2089
1930
        mutex_free(&srv_misc_tmpfile_mutex);
2090
 
        dict_close();
2091
 
        btr_search_sys_free();
2092
1931
 
2093
1932
        /* 3. Free all InnoDB's own mutexes and the os_fast_mutexes inside
2094
1933
        them */
2095
 
        os_aio_free();
2096
1934
        sync_close();
 
1935
 
 
1936
        /* 4. Free the os_conc_mutex and all os_events and os_mutexes */
 
1937
 
2097
1938
        srv_free();
2098
 
        fil_close();
2099
 
 
2100
 
        /* 4. Free the os_conc_mutex and all os_events and os_mutexes */
2101
 
 
2102
1939
        os_sync_free();
2103
1940
 
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 */
 
1941
        /* Check that all read views are closed except read view owned
 
1942
        by a purge. */
 
1943
 
 
1944
        if (UT_LIST_GET_LEN(trx_sys->view_list) > 1) {
 
1945
                fprintf(stderr,
 
1946
                        "InnoDB: Error: all read views were not closed"
 
1947
                        " before shutdown:\n"
 
1948
                        "InnoDB: %lu read views open \n",
 
1949
                        UT_LIST_GET_LEN(trx_sys->view_list) - 1);
 
1950
        }
 
1951
 
 
1952
        /* 5. Free all allocated memory and the os_fast_mutex created in
 
1953
        ut0mem.c */
 
1954
 
 
1955
        buf_pool_free();
2114
1956
        ut_free_all_mem();
2115
1957
 
2116
1958
        if (os_thread_count != 0
2142
1984
        }
2143
1985
 
2144
1986
        srv_was_started = FALSE;
2145
 
        srv_start_has_been_called = FALSE;
2146
1987
 
2147
1988
        return((int) DB_SUCCESS);
2148
1989
}
 
1990
 
 
1991
#ifdef __NETWARE__
 
1992
void set_panic_flag_for_netware()
 
1993
{
 
1994
        extern ibool panic_shutdown;
 
1995
        panic_shutdown = TRUE;
 
1996
}
 
1997
#endif /* __NETWARE__ */
2149
1998
#endif /* !UNIV_HOTBACKUP */