~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-02-21 00:18:15 UTC
  • Revision ID: brian@tangent.org-20090221001815-x20e8h71e984lvs1
Completion (?) of uint conversion.

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
 
#include <drizzled/gettext.h> 
96
 
#include <drizzled/errmsg_print.h>
97
 
 
98
 
/** Log sequence number immediately after startup */
 
57
#include "que0que.h"
 
58
 
 
59
/* Log sequence number immediately after startup */
99
60
UNIV_INTERN ib_uint64_t srv_start_lsn;
100
 
/** Log sequence number at shutdown */
 
61
/* Log sequence number at shutdown */
101
62
UNIV_INTERN ib_uint64_t srv_shutdown_lsn;
102
63
 
103
64
#ifdef HAVE_DARWIN_THREADS
104
65
# include <sys/utsname.h>
105
 
/** TRUE if the F_FULLFSYNC option is available */
106
66
UNIV_INTERN ibool       srv_have_fullfsync = FALSE;
107
67
#endif
108
68
 
109
 
/** TRUE if a raw partition is in use */
110
69
UNIV_INTERN ibool       srv_start_raw_disk_in_use = FALSE;
111
70
 
112
 
/** TRUE if the server is being started, before rolling back any
113
 
incomplete transactions */
114
71
UNIV_INTERN ibool       srv_startup_is_before_trx_rollback_phase = FALSE;
115
 
/** TRUE if the server is being started */
116
72
UNIV_INTERN ibool       srv_is_being_started = FALSE;
117
 
/** TRUE if the server was successfully started */
118
73
UNIV_INTERN ibool       srv_was_started = FALSE;
119
 
/** TRUE if innobase_start_or_create_for_mysql() has been called */
 
74
#ifndef UNIV_HOTBACKUP
120
75
static ibool    srv_start_has_been_called = FALSE;
121
 
 
122
 
/** At a shutdown this value climbs from SRV_SHUTDOWN_NONE to
123
 
SRV_SHUTDOWN_CLEANUP and then to SRV_SHUTDOWN_LAST_PHASE, and so on */
124
 
UNIV_INTERN enum srv_shutdown_state     srv_shutdown_state = SRV_SHUTDOWN_NONE;
125
 
 
126
 
/** 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
127
83
static os_file_t        files[1000];
128
84
 
129
 
/** io_handler_thread parameters for thread identification */
130
 
static ulint            n[SRV_MAX_N_IO_THREADS + 6];
131
 
/** io_handler_thread identifiers */
132
 
static os_thread_id_t   thread_ids[SRV_MAX_N_IO_THREADS + 6];
133
 
 
134
 
/** We use this mutex to test the return value of pthread_mutex_trylock
 
85
static mutex_t          ios_mutex;
 
86
static ulint            ios;
 
87
 
 
88
static ulint            n[SRV_MAX_N_IO_THREADS + 5];
 
89
static os_thread_id_t   thread_ids[SRV_MAX_N_IO_THREADS + 5];
 
90
 
 
91
/* We use this mutex to test the return value of pthread_mutex_trylock
135
92
   on successful locking. HP-UX does NOT return 0, though Linux et al do. */
136
93
static os_fast_mutex_t  srv_os_test_mutex;
137
94
 
138
 
/** Name of srv_monitor_file */
 
95
/* Name of srv_monitor_file */
139
96
static char*    srv_monitor_file_name;
140
97
#endif /* !UNIV_HOTBACKUP */
141
98
 
142
 
/** */
143
99
#define SRV_N_PENDING_IOS_PER_THREAD    OS_AIO_N_PENDING_IOS_PER_THREAD
144
100
#define SRV_MAX_N_PENDING_SYNC_IOS      100
145
101
 
146
 
#ifdef UNIV_PFS_THREAD
147
 
/* Keys to register InnoDB threads with performance schema */
148
 
UNIV_INTERN mysql_pfs_key_t     io_handler_thread_key;
149
 
UNIV_INTERN mysql_pfs_key_t     srv_lock_timeout_thread_key;
150
 
UNIV_INTERN mysql_pfs_key_t     srv_error_monitor_thread_key;
151
 
UNIV_INTERN mysql_pfs_key_t     srv_monitor_thread_key;
152
 
UNIV_INTERN mysql_pfs_key_t     srv_master_thread_key;
153
 
#endif /* UNIV_PFS_THREAD */
154
102
 
155
 
/*********************************************************************//**
156
 
Convert a numeric string that optionally ends in G or M, to a number
157
 
containing megabytes.
158
 
@return next character in string */
159
103
static
160
104
char*
161
105
srv_parse_megabytes(
162
106
/*================*/
163
 
        char*   str,    /*!< in: string containing a quantity in bytes */
164
 
        ulint*  megs)   /*!< out: the number in megabytes */
 
107
                        /* out: next character in string */
 
108
        char*   str,    /* in: string containing a quantity in bytes */
 
109
        ulint*  megs)   /* out: the number in megabytes */
165
110
{
166
111
        char*   endp;
167
112
        ulint   size;
186
131
        return(str);
187
132
}
188
133
 
189
 
/*********************************************************************//**
 
134
/*************************************************************************
190
135
Reads the data files and their sizes from a character string given in
191
 
the .cnf file.
192
 
@return TRUE if ok, FALSE on parse error */
 
136
the .cnf file. */
193
137
UNIV_INTERN
194
138
ibool
195
139
srv_parse_data_file_paths_and_sizes(
196
140
/*================================*/
197
 
        char*   str)    /*!< in/out: the data file path string */
 
141
                                        /* out: TRUE if ok, FALSE if parsing
 
142
                                        error */
 
143
        char*   str,                    /* in: the data file path string */
 
144
        char*** data_file_names,        /* out, own: array of data file
 
145
                                        names */
 
146
        ulint** data_file_sizes,        /* out, own: array of data file sizes
 
147
                                        in megabytes */
 
148
        ulint** data_file_is_raw_partition,/* out, own: array of flags
 
149
                                        showing which data files are raw
 
150
                                        partitions */
 
151
        ulint*  n_data_files,           /* out: number of data files */
 
152
        ibool*  is_auto_extending,      /* out: TRUE if the last data file is
 
153
                                        auto-extending */
 
154
        ulint*  max_auto_extend_size)   /* out: max auto extend size for the
 
155
                                        last file if specified, 0 if not */
198
156
{
199
157
        char*   input_str;
200
158
        char*   path;
201
159
        ulint   size;
202
160
        ulint   i       = 0;
203
161
 
204
 
        srv_auto_extend_last_data_file = FALSE;
205
 
        srv_last_file_size_max = 0;
206
 
        srv_data_file_names = NULL;
207
 
        srv_data_file_sizes = NULL;
208
 
        srv_data_file_is_raw_partition = NULL;
 
162
        *is_auto_extending = FALSE;
 
163
        *max_auto_extend_size = 0;
209
164
 
210
165
        input_str = str;
211
166
 
282
237
                return(FALSE);
283
238
        }
284
239
 
285
 
        srv_data_file_names = static_cast<char **>(malloc(i * sizeof *srv_data_file_names));
286
 
        srv_data_file_sizes = static_cast<ulint *>(malloc(i * sizeof *srv_data_file_sizes));
287
 
        srv_data_file_is_raw_partition = static_cast<ulint *>(malloc(
288
 
                                                                     i * sizeof *srv_data_file_is_raw_partition));
 
240
        *data_file_names = (char**)ut_malloc(i * sizeof(void*));
 
241
        *data_file_sizes = (ulint*)ut_malloc(i * sizeof(ulint));
 
242
        *data_file_is_raw_partition = (ulint*)ut_malloc(i * sizeof(ulint));
289
243
 
290
 
        srv_n_data_files = i;
 
244
        *n_data_files = i;
291
245
 
292
246
        /* Then store the actual values to our arrays */
293
247
 
317
271
 
318
272
                str = srv_parse_megabytes(str, &size);
319
273
 
320
 
                srv_data_file_names[i] = path;
321
 
                srv_data_file_sizes[i] = size;
 
274
                (*data_file_names)[i] = path;
 
275
                (*data_file_sizes)[i] = size;
322
276
 
323
277
                if (0 == strncmp(str, ":autoextend",
324
278
                                 (sizeof ":autoextend") - 1)) {
325
279
 
326
 
                        srv_auto_extend_last_data_file = TRUE;
 
280
                        *is_auto_extending = TRUE;
327
281
 
328
282
                        str += (sizeof ":autoextend") - 1;
329
283
 
333
287
                                str += (sizeof ":max:") - 1;
334
288
 
335
289
                                str = srv_parse_megabytes(
336
 
                                        str, &srv_last_file_size_max);
 
290
                                        str, max_auto_extend_size);
337
291
                        }
338
292
 
339
293
                        if (*str != '\0') {
342
296
                        }
343
297
                }
344
298
 
345
 
                (srv_data_file_is_raw_partition)[i] = 0;
 
299
                (*data_file_is_raw_partition)[i] = 0;
346
300
 
347
301
                if (strlen(str) >= 6
348
302
                    && *str == 'n'
349
303
                    && *(str + 1) == 'e'
350
304
                    && *(str + 2) == 'w') {
351
305
                        str += 3;
352
 
                        (srv_data_file_is_raw_partition)[i] = SRV_NEW_RAW;
 
306
                        (*data_file_is_raw_partition)[i] = SRV_NEW_RAW;
353
307
                }
354
308
 
355
309
                if (*str == 'r' && *(str + 1) == 'a' && *(str + 2) == 'w') {
356
310
                        str += 3;
357
311
 
358
 
                        if ((srv_data_file_is_raw_partition)[i] == 0) {
359
 
                                (srv_data_file_is_raw_partition)[i] = SRV_OLD_RAW;
 
312
                        if ((*data_file_is_raw_partition)[i] == 0) {
 
313
                                (*data_file_is_raw_partition)[i] = SRV_OLD_RAW;
360
314
                        }
361
315
                }
362
316
 
370
324
        return(TRUE);
371
325
}
372
326
 
373
 
/*********************************************************************//**
 
327
/*************************************************************************
374
328
Reads log group home directories from a character string given in
375
 
the .cnf file.
376
 
@return TRUE if ok, FALSE on parse error */
 
329
the .cnf file. */
377
330
UNIV_INTERN
378
331
ibool
379
332
srv_parse_log_group_home_dirs(
380
333
/*==========================*/
381
 
        char*   str)    /*!< in/out: character string */
 
334
                                        /* out: TRUE if ok, FALSE if parsing
 
335
                                        error */
 
336
        char*   str,                    /* in: character string */
 
337
        char*** log_group_home_dirs)    /* out, own: log group home dirs */
382
338
{
383
339
        char*   input_str;
384
340
        char*   path;
385
341
        ulint   i       = 0;
386
342
 
387
 
        srv_log_group_home_dirs = NULL;
388
 
 
389
343
        input_str = str;
390
344
 
391
345
        /* First calculate the number of directories and check syntax:
415
369
                return(FALSE);
416
370
        }
417
371
 
418
 
        srv_log_group_home_dirs = static_cast<char **>(malloc(i * sizeof *srv_log_group_home_dirs));
 
372
        *log_group_home_dirs = (char**) ut_malloc(i * sizeof(void*));
419
373
 
420
374
        /* Then store the actual values to our array */
421
375
 
434
388
                        str++;
435
389
                }
436
390
 
437
 
                srv_log_group_home_dirs[i] = path;
 
391
                (*log_group_home_dirs)[i] = path;
438
392
 
439
393
                i++;
440
394
        }
442
396
        return(TRUE);
443
397
}
444
398
 
445
 
/*********************************************************************//**
446
 
Frees the memory allocated by srv_parse_data_file_paths_and_sizes()
447
 
and srv_parse_log_group_home_dirs(). */
448
 
UNIV_INTERN
449
 
void
450
 
srv_free_paths_and_sizes(void)
451
 
/*==========================*/
452
 
{
453
 
        free(srv_data_file_names);
454
 
        srv_data_file_names = NULL;
455
 
        free(srv_data_file_sizes);
456
 
        srv_data_file_sizes = NULL;
457
 
        free(srv_data_file_is_raw_partition);
458
 
        srv_data_file_is_raw_partition = NULL;
459
 
        free(srv_log_group_home_dirs);
460
 
        srv_log_group_home_dirs = NULL;
461
 
}
462
 
 
463
399
#ifndef UNIV_HOTBACKUP
464
 
/********************************************************************//**
465
 
I/o-handler thread function.
466
 
@return OS_THREAD_DUMMY_RETURN */
467
 
extern "C"
468
 
os_thread_ret_t
469
 
io_handler_thread(void* arg);
 
400
/************************************************************************
 
401
I/o-handler thread function. */
 
402
static
470
403
 
471
 
extern "C"
472
404
os_thread_ret_t
473
405
io_handler_thread(
474
406
/*==============*/
475
 
        void*   arg)    /*!< in: pointer to the number of the segment in
476
 
                        the aio array */
 
407
        void*   arg)
477
408
{
478
409
        ulint   segment;
 
410
        ulint   i;
479
411
 
480
412
        segment = *((ulint*)arg);
481
413
 
483
415
        fprintf(stderr, "Io handler thread %lu starts, id %lu\n", segment,
484
416
                os_thread_pf(os_thread_get_curr_id()));
485
417
#endif
486
 
 
487
 
#ifdef UNIV_PFS_THREAD
488
 
        pfs_register_thread(io_handler_thread_key);
489
 
#endif /* UNIV_PFS_THREAD */
490
 
 
491
 
        while (srv_shutdown_state != SRV_SHUTDOWN_EXIT_THREADS) {
 
418
        for (i = 0;; i++) {
492
419
                fil_aio_wait(segment);
 
420
 
 
421
                mutex_enter(&ios_mutex);
 
422
                ios++;
 
423
                mutex_exit(&ios_mutex);
493
424
        }
494
425
 
495
426
        /* We count the number of threads in os_thread_exit(). A created
496
427
        thread should always use that to exit and not use return() to exit.
497
428
        The thread actually never comes here because it is exited in an
498
429
        os_event_wait(). */
 
430
#ifndef UNIV_SOLARIS
499
431
        return 0;
 
432
#endif
500
433
}
501
434
#endif /* !UNIV_HOTBACKUP */
502
435
 
506
439
#define SRV_PATH_SEPARATOR      '/'
507
440
#endif
508
441
 
509
 
/*********************************************************************//**
 
442
/*************************************************************************
510
443
Normalizes a directory path for Windows: converts slashes to backslashes. */
511
444
UNIV_INTERN
512
445
void
513
446
srv_normalize_path_for_win(
514
447
/*=======================*/
515
 
        char*   /*str __attribute__((unused))*/)        /*!< in/out: null-terminated
 
448
        char*   str __attribute__((unused)))    /* in/out: null-terminated
516
449
                                                character string */
517
450
{
518
451
#ifdef __WIN__
525
458
#endif
526
459
}
527
460
 
 
461
/*************************************************************************
 
462
Adds a slash or a backslash to the end of a string if it is missing
 
463
and the string is not empty. */
 
464
UNIV_INTERN
 
465
char*
 
466
srv_add_path_separator_if_needed(
 
467
/*=============================*/
 
468
                        /* out: string which has the separator if the
 
469
                        string is not empty */
 
470
        char*   str)    /* in: null-terminated character string */
 
471
{
 
472
        char*   out_str;
 
473
        ulint   len     = ut_strlen(str);
 
474
 
 
475
        if (len == 0 || str[len - 1] == SRV_PATH_SEPARATOR) {
 
476
 
 
477
                return(str);
 
478
        }
 
479
 
 
480
        out_str = ut_malloc(len + 2);
 
481
        memcpy(out_str, str, len);
 
482
        out_str[len] = SRV_PATH_SEPARATOR;
 
483
        out_str[len + 1] = 0;
 
484
 
 
485
        return(out_str);
 
486
}
 
487
 
528
488
#ifndef UNIV_HOTBACKUP
529
 
/*********************************************************************//**
 
489
/*************************************************************************
530
490
Calculates the low 32 bits when a file size which is given as a number
531
 
database pages is converted to the number of bytes.
532
 
@return low 32 bytes of file size when expressed in bytes */
 
491
database pages is converted to the number of bytes. */
533
492
static
534
493
ulint
535
494
srv_calc_low32(
536
495
/*===========*/
537
 
        ulint   file_size)      /*!< in: file size in database pages */
 
496
                                /* out: low 32 bytes of file size when
 
497
                                expressed in bytes */
 
498
        ulint   file_size)      /* in: file size in database pages */
538
499
{
539
500
        return(0xFFFFFFFFUL & (file_size << UNIV_PAGE_SIZE_SHIFT));
540
501
}
541
502
 
542
 
/*********************************************************************//**
 
503
/*************************************************************************
543
504
Calculates the high 32 bits when a file size which is given as a number
544
 
database pages is converted to the number of bytes.
545
 
@return high 32 bytes of file size when expressed in bytes */
 
505
database pages is converted to the number of bytes. */
546
506
static
547
507
ulint
548
508
srv_calc_high32(
549
509
/*============*/
550
 
        ulint   file_size)      /*!< in: file size in database pages */
 
510
                                /* out: high 32 bytes of file size when
 
511
                                expressed in bytes */
 
512
        ulint   file_size)      /* in: file size in database pages */
551
513
{
552
514
        return(file_size >> (32 - UNIV_PAGE_SIZE_SHIFT));
553
515
}
554
516
 
555
 
/*********************************************************************//**
556
 
Creates or opens the log files and closes them.
557
 
@return DB_SUCCESS or error code */
 
517
/*************************************************************************
 
518
Creates or opens the log files and closes them. */
558
519
static
559
520
ulint
560
521
open_or_create_log_file(
561
522
/*====================*/
562
 
        ibool   create_new_db,          /*!< in: TRUE if we should create a
 
523
                                        /* out: DB_SUCCESS or error code */
 
524
        ibool   create_new_db,          /* in: TRUE if we should create a
563
525
                                        new database */
564
 
        ibool*  log_file_created,       /*!< out: TRUE if new log file
 
526
        ibool*  log_file_created,       /* out: TRUE if new log file
565
527
                                        created */
566
 
        ibool   log_file_has_been_opened,/*!< in: TRUE if a log file has been
 
528
        ibool   log_file_has_been_opened,/* in: TRUE if a log file has been
567
529
                                        opened before: then it is an error
568
530
                                        to try to create another log file */
569
 
        ulint   k,                      /*!< in: log group number */
570
 
        ulint   i)                      /*!< in: log file number in group */
 
531
        ulint   k,                      /* in: log group number */
 
532
        ulint   i)                      /* in: log file number in group */
571
533
{
572
534
        ibool   ret;
573
535
        ulint   size;
574
536
        ulint   size_high;
575
537
        char    name[10000];
576
 
        ulint   dirnamelen;
577
538
 
578
539
        UT_NOT_USED(create_new_db);
579
540
 
580
541
        *log_file_created = FALSE;
581
542
 
582
543
        srv_normalize_path_for_win(srv_log_group_home_dirs[k]);
583
 
 
584
 
        dirnamelen = strlen(srv_log_group_home_dirs[k]);
585
 
        ut_a(dirnamelen < (sizeof name) - 10 - sizeof "ib_logfile");
586
 
        memcpy(name, srv_log_group_home_dirs[k], dirnamelen);
587
 
 
588
 
        /* Add a path separator if needed. */
589
 
        if (dirnamelen && name[dirnamelen - 1] != SRV_PATH_SEPARATOR) {
590
 
                name[dirnamelen++] = SRV_PATH_SEPARATOR;
591
 
        }
592
 
 
593
 
        sprintf(name + dirnamelen, "%s%lu", "ib_logfile", (ulong) i);
594
 
 
595
 
        files[i] = os_file_create(innodb_file_log_key, name,
596
 
                                  OS_FILE_CREATE, OS_FILE_NORMAL,
 
544
        srv_log_group_home_dirs[k] = srv_add_path_separator_if_needed(
 
545
                srv_log_group_home_dirs[k]);
 
546
 
 
547
        ut_a(strlen(srv_log_group_home_dirs[k])
 
548
             < (sizeof name) - 10 - sizeof "ib_logfile");
 
549
        sprintf(name, "%s%s%lu", srv_log_group_home_dirs[k],
 
550
                "ib_logfile", (ulong) i);
 
551
 
 
552
        files[i] = os_file_create(name, OS_FILE_CREATE, OS_FILE_NORMAL,
597
553
                                  OS_LOG_FILE, &ret);
598
554
        if (ret == FALSE) {
599
555
                if (os_file_get_last_error(FALSE) != OS_FILE_ALREADY_EXISTS
604
560
                    && os_file_get_last_error(FALSE) != 100
605
561
#endif
606
562
                    ) {
607
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
608
 
                                          "InnoDB: Error in creating or opening %s", name);
 
563
                        fprintf(stderr,
 
564
                                "InnoDB: Error in creating"
 
565
                                " or opening %s\n", name);
609
566
 
610
 
                  return(DB_ERROR);
 
567
                        return(DB_ERROR);
611
568
                }
612
569
 
613
 
                files[i] = os_file_create(innodb_file_log_key, name,
614
 
                                          OS_FILE_OPEN, OS_FILE_AIO,
 
570
                files[i] = os_file_create(name, OS_FILE_OPEN, OS_FILE_AIO,
615
571
                                          OS_LOG_FILE, &ret);
616
572
                if (!ret) {
617
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
618
 
                                          "InnoDB: Error in opening %s.", name);
 
573
                        fprintf(stderr,
 
574
                                "InnoDB: Error in opening %s\n", name);
619
575
 
620
576
                        return(DB_ERROR);
621
577
                }
626
582
                if (size != srv_calc_low32(srv_log_file_size)
627
583
                    || size_high != srv_calc_high32(srv_log_file_size)) {
628
584
 
629
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
630
 
                                          "InnoDB: Error: log file %s is of different size %lu %lu bytes than specified in the .cnf"
631
 
                                          " file %lu %lu bytes!",
632
 
                                          name, (ulong) size_high, (ulong) size,
633
 
                                          (ulong) srv_calc_high32(srv_log_file_size),
634
 
                                          (ulong) srv_calc_low32(srv_log_file_size));
 
585
                        fprintf(stderr,
 
586
                                "InnoDB: Error: log file %s is"
 
587
                                " of different size %lu %lu bytes\n"
 
588
                                "InnoDB: than specified in the .cnf"
 
589
                                " file %lu %lu bytes!\n",
 
590
                                name, (ulong) size_high, (ulong) size,
 
591
                                (ulong) srv_calc_high32(srv_log_file_size),
 
592
                                (ulong) srv_calc_low32(srv_log_file_size));
635
593
 
636
594
                        return(DB_ERROR);
637
595
                }
638
596
        } else {
639
597
                *log_file_created = TRUE;
640
598
 
641
 
                drizzled::errmsg_printf(drizzled::error::INFO,
642
 
                                        "InnoDB: Log file %s did not exist: new to be created",
643
 
                                        name);
 
599
                ut_print_timestamp(stderr);
 
600
 
 
601
                fprintf(stderr,
 
602
                        "  InnoDB: Log file %s did not exist:"
 
603
                        " new to be created\n",
 
604
                        name);
644
605
                if (log_file_has_been_opened) {
645
606
 
646
607
                        return(DB_ERROR);
647
608
                }
648
609
 
649
 
                drizzled::errmsg_printf(drizzled::error::INFO,
650
 
                                        "InnoDB: Setting log file %s size to %lu MB",
651
 
                                        name, (ulong) srv_log_file_size
652
 
                                        >> (20 - UNIV_PAGE_SIZE_SHIFT));
 
610
                fprintf(stderr, "InnoDB: Setting log file %s size to %lu MB\n",
 
611
                        name, (ulong) srv_log_file_size
 
612
                        >> (20 - UNIV_PAGE_SIZE_SHIFT));
653
613
 
654
 
                drizzled::errmsg_printf(drizzled::error::INFO,
655
 
                                        "InnoDB: Database physically writes the file full: wait...\n");
 
614
                fprintf(stderr,
 
615
                        "InnoDB: Database physically writes the file"
 
616
                        " full: wait...\n");
656
617
 
657
618
                ret = os_file_set_size(name, files[i],
658
619
                                       srv_calc_low32(srv_log_file_size),
659
620
                                       srv_calc_high32(srv_log_file_size));
660
621
                if (!ret) {
661
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
662
 
                                          "InnoDB: Error in creating %s: probably out of disk space",
663
 
                                          name);
 
622
                        fprintf(stderr,
 
623
                                "InnoDB: Error in creating %s:"
 
624
                                " probably out of disk space\n",
 
625
                                name);
664
626
 
665
627
                        return(DB_ERROR);
666
628
                }
705
667
        return(DB_SUCCESS);
706
668
}
707
669
 
708
 
/*********************************************************************//**
709
 
Creates or opens database data files and closes them.
710
 
@return DB_SUCCESS or error code */
 
670
/*************************************************************************
 
671
Creates or opens database data files and closes them. */
711
672
static
712
673
ulint
713
674
open_or_create_data_files(
714
675
/*======================*/
715
 
        ibool*          create_new_db,  /*!< out: TRUE if new database should be
 
676
                                        /* out: DB_SUCCESS or error code */
 
677
        ibool*          create_new_db,  /* out: TRUE if new database should be
716
678
                                        created */
717
679
#ifdef UNIV_LOG_ARCHIVE
718
 
        ulint*          min_arch_log_no,/*!< out: min of archived log
 
680
        ulint*          min_arch_log_no,/* out: min of archived log
719
681
                                        numbers in data files */
720
 
        ulint*          max_arch_log_no,/*!< out: max of archived log
 
682
        ulint*          max_arch_log_no,/* out: max of archived log
721
683
                                        numbers in data files */
722
684
#endif /* UNIV_LOG_ARCHIVE */
723
 
        ib_uint64_t*    min_flushed_lsn,/*!< out: min of flushed lsn
724
 
                                        values in data files */
725
 
        ib_uint64_t*    max_flushed_lsn,/*!< out: max of flushed lsn
726
 
                                        values in data files */
727
 
        ulint*          sum_of_new_sizes)/*!< out: sum of sizes of the
 
685
        ib_uint64_t*    min_flushed_lsn,/* out: min of flushed lsn
 
686
                                        values in data files */
 
687
        ib_uint64_t*    max_flushed_lsn,/* out: max of flushed lsn
 
688
                                        values in data files */
 
689
        ulint*          sum_of_new_sizes)/* out: sum of sizes of the
728
690
                                        new files added */
729
691
{
730
692
        ibool   ret;
737
699
        char    name[10000];
738
700
 
739
701
        if (srv_n_data_files >= 1000) {
740
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
741
 
                                  "InnoDB: can only have < 1000 data files you have defined %lu",
742
 
                                  (ulong) srv_n_data_files);
 
702
                fprintf(stderr, "InnoDB: can only have < 1000 data files\n"
 
703
                        "InnoDB: you have defined %lu\n",
 
704
                        (ulong) srv_n_data_files);
743
705
                return(DB_ERROR);
744
706
        }
745
707
 
748
710
        *create_new_db = FALSE;
749
711
 
750
712
        srv_normalize_path_for_win(srv_data_home);
 
713
        srv_data_home = srv_add_path_separator_if_needed(srv_data_home);
751
714
 
752
715
        for (i = 0; i < srv_n_data_files; i++) {
753
 
                ulint   dirnamelen;
754
 
 
755
716
                srv_normalize_path_for_win(srv_data_file_names[i]);
756
 
                dirnamelen = strlen(srv_data_home);
757
717
 
758
 
                ut_a(dirnamelen + strlen(srv_data_file_names[i])
 
718
                ut_a(strlen(srv_data_home) + strlen(srv_data_file_names[i])
759
719
                     < (sizeof name) - 1);
760
 
                memcpy(name, srv_data_home, dirnamelen);
761
 
                /* Add a path separator if needed. */
762
 
                if (dirnamelen && name[dirnamelen - 1] != SRV_PATH_SEPARATOR) {
763
 
                        name[dirnamelen++] = SRV_PATH_SEPARATOR;
764
 
                }
765
 
 
766
 
                strcpy(name + dirnamelen, srv_data_file_names[i]);
 
720
                sprintf(name, "%s%s", srv_data_home, srv_data_file_names[i]);
767
721
 
768
722
                if (srv_data_file_is_raw_partition[i] == 0) {
769
723
 
770
724
                        /* First we try to create the file: if it already
771
725
                        exists, ret will get value FALSE */
772
726
 
773
 
                        files[i] = os_file_create(innodb_file_data_key,
774
 
                                                  name, OS_FILE_CREATE,
 
727
                        files[i] = os_file_create(name, OS_FILE_CREATE,
775
728
                                                  OS_FILE_NORMAL,
776
729
                                                  OS_DATA_FILE, &ret);
777
730
 
784
737
                            && os_file_get_last_error(FALSE) != 100
785
738
#endif
786
739
                            ) {
787
 
                          drizzled::errmsg_printf(drizzled::error::ERROR,
788
 
                                                  "InnoDB: Error in creating or opening %s",
789
 
                                                  name);
 
740
                                fprintf(stderr,
 
741
                                        "InnoDB: Error in creating"
 
742
                                        " or opening %s\n",
 
743
                                        name);
790
744
 
791
745
                                return(DB_ERROR);
792
746
                        }
797
751
                        srv_start_raw_disk_in_use = TRUE;
798
752
                        srv_created_new_raw = TRUE;
799
753
 
800
 
                        files[i] = os_file_create(innodb_file_data_key,
801
 
                                                  name, OS_FILE_OPEN_RAW,
 
754
                        files[i] = os_file_create(name, OS_FILE_OPEN_RAW,
802
755
                                                  OS_FILE_NORMAL,
803
756
                                                  OS_DATA_FILE, &ret);
804
757
                        if (!ret) {
805
 
                          drizzled::errmsg_printf(drizzled::error::ERROR,
806
 
                                                  "InnoDB: Error in opening %s", name);
 
758
                                fprintf(stderr,
 
759
                                        "InnoDB: Error in opening %s\n", name);
807
760
 
808
761
                                return(DB_ERROR);
809
762
                        }
819
772
                        /* We open the data file */
820
773
 
821
774
                        if (one_created) {
822
 
                          drizzled::errmsg_printf(drizzled::error::ERROR,
823
 
                                        "InnoDB: Error: data files can only be added at the end of a tablespace, but"
824
 
                                        " data file %s existed beforehand.",
825
 
                                        name);
 
775
                                fprintf(stderr,
 
776
                                        "InnoDB: Error: data files can only"
 
777
                                        " be added at the end\n");
 
778
                                fprintf(stderr,
 
779
                                        "InnoDB: of a tablespace, but"
 
780
                                        " data file %s existed beforehand.\n",
 
781
                                        name);
826
782
                                return(DB_ERROR);
827
783
                        }
828
784
 
829
785
                        if (srv_data_file_is_raw_partition[i] == SRV_OLD_RAW) {
830
786
                                files[i] = os_file_create(
831
 
                                        innodb_file_data_key,
832
787
                                        name, OS_FILE_OPEN_RAW,
833
788
                                        OS_FILE_NORMAL, OS_DATA_FILE, &ret);
834
789
                        } else if (i == 0) {
835
790
                                files[i] = os_file_create(
836
 
                                        innodb_file_data_key,
837
791
                                        name, OS_FILE_OPEN_RETRY,
838
792
                                        OS_FILE_NORMAL, OS_DATA_FILE, &ret);
839
793
                        } else {
840
794
                                files[i] = os_file_create(
841
 
                                        innodb_file_data_key,
842
795
                                        name, OS_FILE_OPEN, OS_FILE_NORMAL,
843
796
                                        OS_DATA_FILE, &ret);
844
797
                        }
845
798
 
846
799
                        if (!ret) {
847
 
                          drizzled::errmsg_printf(drizzled::error::ERROR,
848
 
                                                  "InnoDB: Error in opening %s", name);
 
800
                                fprintf(stderr,
 
801
                                        "InnoDB: Error in opening %s\n", name);
849
802
                                os_file_get_last_error(TRUE);
850
803
 
851
804
                                return(DB_ERROR);
872
825
                                        && srv_last_file_size_max
873
826
                                        < rounded_size_pages)) {
874
827
 
875
 
                                  drizzled::errmsg_printf(drizzled::error::ERROR,
876
 
                                                          "InnoDB: Error: auto-extending data file %s is of a different size. "
877
 
                                                          "%lu pages (rounded down to MB) than specified in the .cnf file: "
878
 
                                                          "initial %lu pages, max %lu (relevant if non-zero) pages!",
879
 
                                                          name,
880
 
                                                          (ulong) rounded_size_pages,
881
 
                                                          (ulong) srv_data_file_sizes[i],
882
 
                                                          (ulong)
883
 
                                                          srv_last_file_size_max);
 
828
                                        fprintf(stderr,
 
829
                                                "InnoDB: Error: auto-extending"
 
830
                                                " data file %s is"
 
831
                                                " of a different size\n"
 
832
                                                "InnoDB: %lu pages (rounded"
 
833
                                                " down to MB) than specified"
 
834
                                                " in the .cnf file:\n"
 
835
                                                "InnoDB: initial %lu pages,"
 
836
                                                " max %lu (relevant if"
 
837
                                                " non-zero) pages!\n",
 
838
                                                name,
 
839
                                                (ulong) rounded_size_pages,
 
840
                                                (ulong) srv_data_file_sizes[i],
 
841
                                                (ulong)
 
842
                                                srv_last_file_size_max);
884
843
 
885
844
                                        return(DB_ERROR);
886
845
                                }
890
849
 
891
850
                        if (rounded_size_pages != srv_data_file_sizes[i]) {
892
851
 
893
 
                          drizzled::errmsg_printf(drizzled::error::ERROR,
894
 
                                        "InnoDB: Error: data file %s is of a different size. "
895
 
                                        "%lu pages (rounded down to MB). "
896
 
                                        "Than specified in the .cnf file %lu pages!",
 
852
                                fprintf(stderr,
 
853
                                        "InnoDB: Error: data file %s"
 
854
                                        " is of a different size\n"
 
855
                                        "InnoDB: %lu pages"
 
856
                                        " (rounded down to MB)\n"
 
857
                                        "InnoDB: than specified"
 
858
                                        " in the .cnf file %lu pages!\n",
897
859
                                        name,
898
860
                                        (ulong) rounded_size_pages,
899
861
                                        (ulong) srv_data_file_sizes[i]);
915
877
                        one_created = TRUE;
916
878
 
917
879
                        if (i > 0) {
918
 
                                drizzled::errmsg_printf(drizzled::error::INFO,
919
 
                                        "  InnoDB: Data file %s did not exist: new to be created",
 
880
                                ut_print_timestamp(stderr);
 
881
                                fprintf(stderr,
 
882
                                        "  InnoDB: Data file %s did not"
 
883
                                        " exist: new to be created\n",
920
884
                                        name);
921
885
                        } else {
922
 
                          drizzled::errmsg_printf(drizzled::error::INFO,
923
 
                                        "InnoDB: The first specified data file %s did not exist. A new database to be created!", name);
 
886
                                fprintf(stderr,
 
887
                                        "InnoDB: The first specified"
 
888
                                        " data file %s did not exist:\n"
 
889
                                        "InnoDB: a new database"
 
890
                                        " to be created!\n", name);
924
891
                                *create_new_db = TRUE;
925
892
                        }
926
893
 
927
 
                        drizzled::errmsg_printf(drizzled::error::INFO,
928
 
                                                "  InnoDB: Setting file %s size to %lu MB",
929
 
                                                name, (ulong) (srv_data_file_sizes[i]
930
 
                                                         >> (20 - UNIV_PAGE_SIZE_SHIFT)));
 
894
                        ut_print_timestamp(stderr);
 
895
                        fprintf(stderr,
 
896
                                "  InnoDB: Setting file %s size to %lu MB\n",
 
897
                                name,
 
898
                                (ulong) (srv_data_file_sizes[i]
 
899
                                         >> (20 - UNIV_PAGE_SIZE_SHIFT)));
931
900
 
932
 
                        drizzled::errmsg_printf(drizzled::error::INFO,
933
 
                                "InnoDB: Database physically writes the file full: wait...");
 
901
                        fprintf(stderr,
 
902
                                "InnoDB: Database physically writes the"
 
903
                                " file full: wait...\n");
934
904
 
935
905
                        ret = os_file_set_size(
936
906
                                name, files[i],
938
908
                                srv_calc_high32(srv_data_file_sizes[i]));
939
909
 
940
910
                        if (!ret) {
941
 
                          drizzled::errmsg_printf(drizzled::error::ERROR,
942
 
                                                  "InnoDB: Error in creating %s: probably out of disk space", name);
 
911
                                fprintf(stderr,
 
912
                                        "InnoDB: Error in creating %s:"
 
913
                                        " probably out of disk space\n", name);
943
914
 
944
915
                                return(DB_ERROR);
945
916
                        }
961
932
                                srv_data_file_is_raw_partition[i] != 0);
962
933
        }
963
934
 
 
935
        ios = 0;
 
936
 
 
937
        mutex_create(&ios_mutex, SYNC_NO_ORDER_CHECK);
 
938
 
964
939
        return(DB_SUCCESS);
965
940
}
966
941
 
967
942
/********************************************************************
968
943
Starts InnoDB and creates a new database if database files
969
 
are not found and the user wants.
970
 
@return DB_SUCCESS or error code */
 
944
are not found and the user wants. Server parameters are
 
945
read from a file of name "srv_init" in the ib_home directory. */
971
946
UNIV_INTERN
972
947
int
973
948
innobase_start_or_create_for_mysql(void)
974
949
/*====================================*/
 
950
                                /* out: DB_SUCCESS or error code */
975
951
{
 
952
        buf_pool_t*     ret;
976
953
        ibool           create_new_db;
977
954
        ibool           log_file_created;
978
955
        ibool           log_created     = FALSE;
988
965
        ulint           tablespace_size_in_header;
989
966
        ulint           err;
990
967
        ulint           i;
991
 
        ulint           io_limit;
992
968
        my_bool         srv_file_per_table_original_value
993
969
                = srv_file_per_table;
994
970
        mtr_t           mtr;
1003
979
        on Mac OS X 10.3 or later. */
1004
980
        struct utsname utsname;
1005
981
        if (uname(&utsname)) {
1006
 
                fputs(_("InnoDB: cannot determine Mac OS X version!\n"), stderr);
 
982
                fputs("InnoDB: cannot determine Mac OS X version!\n", stderr);
1007
983
        } else {
1008
984
                srv_have_fullfsync = strcmp(utsname.release, "7.") >= 0;
1009
985
        }
1010
986
        if (!srv_have_fullfsync) {
1011
 
                fputs(_("InnoDB: On Mac OS X, fsync() may be"
1012
 
                        " broken on internal drives,\n"
1013
 
                        "InnoDB: making transactions unsafe!\n"), stderr);
 
987
                fputs("InnoDB: On Mac OS X, fsync() may be"
 
988
                      " broken on internal drives,\n"
 
989
                      "InnoDB: making transactions unsafe!\n", stderr);
1014
990
        }
1015
991
# endif /* F_FULLFSYNC */
1016
992
#endif /* HAVE_DARWIN_THREADS */
1017
993
 
1018
994
        if (sizeof(ulint) != sizeof(void*)) {
1019
 
          drizzled::errmsg_printf(drizzled::error::WARN,
1020
 
                        _("InnoDB: Error: size of InnoDB's ulint is %lu, but size of void* is %lu. "
1021
 
                          "The sizes should be the same so that on a 64-bit platform you can. Allocate more than 4 GB of memory."),
 
995
                fprintf(stderr,
 
996
                        "InnoDB: Error: size of InnoDB's ulint is %lu,"
 
997
                        " but size of void* is %lu.\n"
 
998
                        "InnoDB: The sizes should be the same"
 
999
                        " so that on a 64-bit platform you can\n"
 
1000
                        "InnoDB: allocate more than 4 GB of memory.",
1022
1001
                        (ulong)sizeof(ulint), (ulong)sizeof(void*));
1023
1002
        }
1024
1003
 
1028
1007
        innodb_file_per_table) until this function has returned. */
1029
1008
        srv_file_per_table = FALSE;
1030
1009
#ifdef UNIV_DEBUG
1031
 
        drizzled::errmsg_printf(drizzled::error::INFO,
1032
 
                                _("InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!\n"));
 
1010
        fprintf(stderr,
 
1011
                "InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!\n");
1033
1012
#endif
1034
1013
 
1035
1014
#ifdef UNIV_IBUF_DEBUG
1036
 
        drizzled::errmsg_printf(drizzled::error::INFO,
1037
 
                _("InnoDB: !!!!!!!! UNIV_IBUF_DEBUG switched on !!!!!!!!!\n"
1038
 
# ifdef UNIV_IBUF_COUNT_DEBUG
1039
 
                  "InnoDB: !!!!!!!! UNIV_IBUF_COUNT_DEBUG switched on !!!!!!!!!\n"
1040
 
                  "InnoDB: Crash recovery will fail with UNIV_IBUF_COUNT_DEBUG\n"
1041
 
# endif
1042
 
                ));
 
1015
        fprintf(stderr,
 
1016
                "InnoDB: !!!!!!!! UNIV_IBUF_DEBUG switched on !!!!!!!!!\n"
 
1017
                "InnoDB: Crash recovery will fail with UNIV_IBUF_DEBUG\n");
1043
1018
#endif
1044
1019
 
1045
1020
#ifdef UNIV_SYNC_DEBUG
1046
 
        drizzled::errmsg_printf(drizzled::error::INFO,
1047
 
                                _("InnoDB: !!!!!!!! UNIV_SYNC_DEBUG switched on !!!!!!!!!\n"));
 
1021
        fprintf(stderr,
 
1022
                "InnoDB: !!!!!!!! UNIV_SYNC_DEBUG switched on !!!!!!!!!\n");
1048
1023
#endif
1049
1024
 
1050
1025
#ifdef UNIV_SEARCH_DEBUG
1051
 
        drizzled::errmsg_printf(drizzled::error::INFO,
1052
 
                                _("InnoDB: !!!!!!!! UNIV_SEARCH_DEBUG switched on !!!!!!!!!\n"));
 
1026
        fprintf(stderr,
 
1027
                "InnoDB: !!!!!!!! UNIV_SEARCH_DEBUG switched on !!!!!!!!!\n");
1053
1028
#endif
1054
1029
 
1055
 
#ifdef UNIV_LOG_LSN_DEBUG
1056
 
        drizzled::errmsg_printf(drizzled::error::INFO,
1057
 
                                _("InnoDB: !!!!!!!! UNIV_LOG_LSN_DEBUG switched on !!!!!!!!!\n"));
1058
 
#endif /* UNIV_LOG_LSN_DEBUG */
1059
1030
#ifdef UNIV_MEM_DEBUG
1060
 
        drizzled::errmsg_printf(drizzled::error::INFO,
1061
 
                                _("InnoDB: !!!!!!!! UNIV_MEM_DEBUG switched on !!!!!!!!!\n"));
 
1031
        fprintf(stderr,
 
1032
                "InnoDB: !!!!!!!! UNIV_MEM_DEBUG switched on !!!!!!!!!\n");
1062
1033
#endif
1063
1034
 
1064
 
        if (UNIV_LIKELY(srv_use_sys_malloc))
1065
 
        {
1066
 
          drizzled::errmsg_printf(drizzled::error::ERROR, _("InnoDB: The InnoDB memory heap is disabled\n"));
1067
 
        }
1068
 
 
1069
 
        fputs("InnoDB: " IB_ATOMICS_STARTUP_MSG
1070
 
                "\nInnoDB: Compressed tables use zlib " ZLIB_VERSION
1071
 
#ifdef UNIV_ZIP_DEBUG
1072
 
              " with validation"
1073
 
#endif /* UNIV_ZIP_DEBUG */
1074
 
#ifdef UNIV_ZIP_COPY
1075
 
              " and extra copying"
1076
 
#endif /* UNIV_ZIP_COPY */
1077
 
              "\n" , stderr);
1078
 
 
1079
 
 
1080
1035
        /* Since InnoDB does not currently clean up all its internal data
1081
1036
        structures in MySQL Embedded Server Library server_end(), we
1082
1037
        print an error message if someone tries to start up InnoDB a
1083
1038
        second time during the process lifetime. */
1084
1039
 
1085
1040
        if (srv_start_has_been_called) {
1086
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
1087
 
                        "InnoDB: Error: startup called second time during the process lifetime.\n");
 
1041
                fprintf(stderr,
 
1042
                        "InnoDB: Error:startup called second time"
 
1043
                        " during the process lifetime.\n"
 
1044
                        "InnoDB: In the MySQL Embedded Server Library"
 
1045
                        " you cannot call server_init()\n"
 
1046
                        "InnoDB: more than once during"
 
1047
                        " the process lifetime.\n");
1088
1048
        }
1089
1049
 
1090
1050
        srv_start_has_been_called = TRUE;
1096
1056
 
1097
1057
        srv_is_being_started = TRUE;
1098
1058
        srv_startup_is_before_trx_rollback_phase = TRUE;
 
1059
        os_aio_use_native_aio = FALSE;
1099
1060
 
1100
1061
#ifdef __WIN__
1101
 
        switch (os_get_os_version()) {
1102
 
        case OS_WIN95:
1103
 
        case OS_WIN31:
1104
 
        case OS_WINNT:
 
1062
        if (os_get_os_version() == OS_WIN95
 
1063
            || os_get_os_version() == OS_WIN31
 
1064
            || os_get_os_version() == OS_WINNT) {
 
1065
 
1105
1066
                /* On Win 95, 98, ME, Win32 subsystem for Windows 3.1,
1106
1067
                and NT use simulated aio. In NT Windows provides async i/o,
1107
1068
                but when run in conjunction with InnoDB Hot Backup, it seemed
1108
1069
                to corrupt the data files. */
1109
1070
 
1110
 
                srv_use_native_aio = FALSE;
1111
 
                break;
1112
 
 
1113
 
        case OS_WIN2000:
1114
 
        case OS_WINXP:
1115
 
                /* On 2000 and XP, async IO is available. */
1116
 
                srv_use_native_aio = TRUE;
1117
 
                break;
1118
 
 
1119
 
        default:
1120
 
                /* Vista and later have both async IO and condition variables */
1121
 
                srv_use_native_aio = TRUE;
1122
 
                srv_use_native_conditions = TRUE;
1123
 
                break;
1124
 
        }
1125
 
 
1126
 
#elif defined(LINUX_NATIVE_AIO)
1127
 
 
1128
 
        if (srv_use_native_aio) {
1129
 
                drizzled::errmsg_printf(drizzled::error::INFO,
1130
 
                                        _("InnoDB: Using Linux native AIO"));
1131
 
        }
1132
 
#else
1133
 
        /* Currently native AIO is supported only on windows and linux
1134
 
        and that also when the support is compiled in. In all other
1135
 
        cases, we ignore the setting of innodb_use_native_aio. */
1136
 
        srv_use_native_aio = FALSE;
1137
 
 
 
1071
                os_aio_use_native_aio = FALSE;
 
1072
        } else {
 
1073
                /* On Win 2000 and XP use async i/o */
 
1074
                os_aio_use_native_aio = TRUE;
 
1075
        }
1138
1076
#endif
1139
 
 
1140
1077
        if (srv_file_flush_method_str == NULL) {
1141
1078
                /* These are the default options */
1142
1079
 
1161
1098
#else
1162
1099
        } else if (0 == ut_strcmp(srv_file_flush_method_str, "normal")) {
1163
1100
                srv_win_file_flush_method = SRV_WIN_IO_NORMAL;
1164
 
                srv_use_native_aio = FALSE;
 
1101
                os_aio_use_native_aio = FALSE;
1165
1102
 
1166
1103
        } else if (0 == ut_strcmp(srv_file_flush_method_str, "unbuffered")) {
1167
1104
                srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
1168
 
                srv_use_native_aio = FALSE;
 
1105
                os_aio_use_native_aio = FALSE;
1169
1106
 
1170
1107
        } else if (0 == ut_strcmp(srv_file_flush_method_str,
1171
1108
                                  "async_unbuffered")) {
1172
1109
                srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
1173
1110
#endif
1174
1111
        } else {
1175
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
1176
 
                                  "InnoDB: Unrecognized value %s for innodb_flush_method",
1177
 
                                  srv_file_flush_method_str);
 
1112
                fprintf(stderr,
 
1113
                        "InnoDB: Unrecognized value %s for"
 
1114
                        " innodb_flush_method\n",
 
1115
                        srv_file_flush_method_str);
1178
1116
                return(DB_ERROR);
1179
1117
        }
1180
1118
 
1186
1124
        maximum number of threads that can wait in the 'srv_conc array' for
1187
1125
        their time to enter InnoDB. */
1188
1126
 
 
1127
#if defined(__NETWARE__)
 
1128
 
 
1129
        /* Create less event semaphores because Win 98/ME had
 
1130
        difficulty creating 40000 event semaphores.  Comment from
 
1131
        Novell, Inc.: also, these just take a lot of memory on
 
1132
        NetWare. */
 
1133
        srv_max_n_threads = 1000;
 
1134
#else
1189
1135
        if (srv_buf_pool_size >= 1000 * 1024 * 1024) {
1190
1136
                /* If buffer pool is less than 1000 MB,
1191
 
                assume fewer threads. Also use only one
1192
 
                buffer pool instance */
 
1137
                assume fewer threads. */
1193
1138
                srv_max_n_threads = 50000;
1194
1139
 
1195
1140
        } else if (srv_buf_pool_size >= 8 * 1024 * 1024) {
1196
1141
 
1197
 
                srv_buf_pool_instances = 1;
1198
1142
                srv_max_n_threads = 10000;
1199
1143
        } else {
1200
 
                srv_buf_pool_instances = 1;
1201
1144
                srv_max_n_threads = 1000;       /* saves several MB of memory,
1202
1145
                                                especially in 64-bit
1203
1146
                                                computers */
1204
1147
        }
1205
 
 
 
1148
#endif
1206
1149
        err = srv_boot();
1207
1150
 
1208
1151
        if (err != DB_SUCCESS) {
1210
1153
                return((int) err);
1211
1154
        }
1212
1155
 
1213
 
        mutex_create(srv_monitor_file_mutex_key,
1214
 
                     &srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK);
 
1156
        mutex_create(&srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK);
1215
1157
 
1216
1158
        if (srv_innodb_status) {
1217
 
          srv_monitor_file_name = static_cast<char *>(mem_alloc(
 
1159
                srv_monitor_file_name = mem_alloc(
1218
1160
                        strlen(fil_path_to_mysql_datadir)
1219
 
                        + 20 + sizeof "/innodb_status."));
 
1161
                        + 20 + sizeof "/innodb_status.");
1220
1162
                sprintf(srv_monitor_file_name, "%s/innodb_status.%lu",
1221
1163
                        fil_path_to_mysql_datadir, os_proc_get_number());
1222
1164
                srv_monitor_file = fopen(srv_monitor_file_name, "w+");
1223
1165
                if (!srv_monitor_file) {
1224
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
1225
 
                                          "InnoDB: unable to create %s: %s\n", srv_monitor_file_name, strerror(errno));
 
1166
                        fprintf(stderr, "InnoDB: unable to create %s: %s\n",
 
1167
                                srv_monitor_file_name, strerror(errno));
1226
1168
                        return(DB_ERROR);
1227
1169
                }
1228
1170
        } else {
1233
1175
                }
1234
1176
        }
1235
1177
 
1236
 
        mutex_create(srv_dict_tmpfile_mutex_key,
1237
 
                     &srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION);
 
1178
        mutex_create(&srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION);
1238
1179
 
1239
1180
        srv_dict_tmpfile = os_file_create_tmpfile();
1240
1181
        if (!srv_dict_tmpfile) {
1241
1182
                return(DB_ERROR);
1242
1183
        }
1243
1184
 
1244
 
        mutex_create(srv_misc_tmpfile_mutex_key,
1245
 
                     &srv_misc_tmpfile_mutex, SYNC_ANY_LATCH);
 
1185
        mutex_create(&srv_misc_tmpfile_mutex, SYNC_ANY_LATCH);
1246
1186
 
1247
1187
        srv_misc_tmpfile = os_file_create_tmpfile();
1248
1188
        if (!srv_misc_tmpfile) {
1249
1189
                return(DB_ERROR);
1250
1190
        }
1251
1191
 
1252
 
        /* innodb_file_io_threads used to be user settable.
1253
 
           It is now just a combination of read_io_threads and
1254
 
           write_io_threads that is set by innodb internally. */
1255
 
 
1256
 
        /* Now overwrite the value on srv_n_file_io_threads */
1257
 
        srv_n_file_io_threads = 2 + srv_n_read_io_threads
1258
 
                                + srv_n_write_io_threads;
1259
 
 
1260
 
        ut_a(srv_n_file_io_threads <= SRV_MAX_N_IO_THREADS);
1261
 
 
1262
 
        /* TODO: Investigate if SRV_N_PENDING_IOS_PER_THREAD (32) limit
1263
 
        still applies to windows. */
1264
 
        if (!srv_use_native_aio) {
1265
 
                io_limit = 8 * SRV_N_PENDING_IOS_PER_THREAD;
1266
 
        } else {
1267
 
                io_limit = SRV_N_PENDING_IOS_PER_THREAD;
1268
 
        }
1269
 
 
1270
 
        os_aio_init(io_limit,
1271
 
                    srv_n_read_io_threads,
1272
 
                    srv_n_write_io_threads,
1273
 
                    SRV_MAX_N_PENDING_SYNC_IOS);
1274
 
 
1275
 
        fil_init(srv_file_per_table ? 50000 : 5000,
1276
 
                 srv_max_n_open_files);
1277
 
 
1278
 
        /* Print time to initialize the buffer pool */
1279
 
 
1280
 
        if (srv_buf_pool_size >= 1024 * 1024 * 1024) {
1281
 
          drizzled::errmsg_printf(drizzled::error::INFO, "InnoDB: Initializing buffer pool, size = %.1fG",
1282
 
                                  ((double) srv_buf_pool_size) / (1024 * 1024 * 1024));
1283
 
        } else {
1284
 
          drizzled::errmsg_printf(drizzled::error::INFO, "InnoDB: Initializing buffer pool, size = %.1fM",
1285
 
                                  ((double) srv_buf_pool_size) / (1024 * 1024));
1286
 
        }
1287
 
 
1288
 
        err = buf_pool_init(srv_buf_pool_size, srv_buf_pool_instances);
1289
 
 
1290
 
        drizzled::errmsg_printf(drizzled::error::INFO, "InnoDB: Completed initialization of buffer pool");
1291
 
 
1292
 
        if (err != DB_SUCCESS) {
1293
 
          drizzled::errmsg_printf(drizzled::error::ERROR, "InnoDB: Fatal error: cannot allocate the memory for the buffer pool");
1294
 
 
1295
 
          return(DB_ERROR);
 
1192
        /* Restrict the maximum number of file i/o threads */
 
1193
        if (srv_n_file_io_threads > SRV_MAX_N_IO_THREADS) {
 
1194
 
 
1195
                srv_n_file_io_threads = SRV_MAX_N_IO_THREADS;
 
1196
        }
 
1197
 
 
1198
        if (!os_aio_use_native_aio) {
 
1199
                /* In simulated aio we currently have use only for 4 threads */
 
1200
                srv_n_file_io_threads = 4;
 
1201
 
 
1202
                os_aio_init(8 * SRV_N_PENDING_IOS_PER_THREAD
 
1203
                            * srv_n_file_io_threads,
 
1204
                            srv_n_file_io_threads,
 
1205
                            SRV_MAX_N_PENDING_SYNC_IOS);
 
1206
        } else {
 
1207
                os_aio_init(SRV_N_PENDING_IOS_PER_THREAD
 
1208
                            * srv_n_file_io_threads,
 
1209
                            srv_n_file_io_threads,
 
1210
                            SRV_MAX_N_PENDING_SYNC_IOS);
 
1211
        }
 
1212
 
 
1213
        fil_init(srv_max_n_open_files);
 
1214
 
 
1215
        ret = buf_pool_init();
 
1216
 
 
1217
        if (ret == NULL) {
 
1218
                fprintf(stderr,
 
1219
                        "InnoDB: Fatal error: cannot allocate the memory"
 
1220
                        " for the buffer pool\n");
 
1221
 
 
1222
                return(DB_ERROR);
1296
1223
        }
1297
1224
 
1298
1225
#ifdef UNIV_DEBUG
1301
1228
 
1302
1229
        if (srv_buf_pool_size <= 5 * 1024 * 1024) {
1303
1230
 
1304
 
          drizzled::errmsg_printf(drizzled::error::WARN, "InnoDB: Warning: Small buffer pool size "
1305
 
                                  "(%luM), the flst_validate() debug function "
1306
 
                                  "can cause a deadlock if the buffer pool fills up.\n",
1307
 
                                  srv_buf_pool_size / 1024 / 1024);
 
1231
                fprintf(stderr, "InnoDB: Warning: Small buffer pool size "
 
1232
                        "(%luM), the flst_validate() debug function "
 
1233
                        "can cause a deadlock if the buffer pool fills up.\n",
 
1234
                        srv_buf_pool_size / 1024 / 1024);
1308
1235
        }
1309
1236
#endif
1310
1237
 
1323
1250
 
1324
1251
#ifdef UNIV_LOG_ARCHIVE
1325
1252
        if (0 != ut_strcmp(srv_log_group_home_dirs[0], srv_arch_dir)) {
1326
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
1327
 
                                  "InnoDB: Error: you must set the log group home dir in my.cnf the same as log arch dir.");
 
1253
                fprintf(stderr,
 
1254
                        "InnoDB: Error: you must set the log group"
 
1255
                        " home dir in my.cnf the\n"
 
1256
                        "InnoDB: same as log arch dir.\n");
1328
1257
 
1329
1258
                return(DB_ERROR);
1330
1259
        }
1331
1260
#endif /* UNIV_LOG_ARCHIVE */
1332
1261
 
1333
1262
        if (srv_n_log_files * srv_log_file_size >= 262144) {
1334
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
1335
 
                                  "InnoDB: Error: combined size of log files must be < 4 GB");
 
1263
                fprintf(stderr,
 
1264
                        "InnoDB: Error: combined size of log files"
 
1265
                        " must be < 4 GB\n");
1336
1266
 
1337
1267
                return(DB_ERROR);
1338
1268
        }
1342
1272
        for (i = 0; i < srv_n_data_files; i++) {
1343
1273
#ifndef __WIN__
1344
1274
                if (sizeof(off_t) < 5 && srv_data_file_sizes[i] >= 262144) {
1345
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
1346
 
                                          "InnoDB: Error: file size must be < 4 GB with this MySQL binary and operating system combination,"
1347
 
                                          " in some OS's < 2 GB\n");
 
1275
                        fprintf(stderr,
 
1276
                                "InnoDB: Error: file size must be < 4 GB"
 
1277
                                " with this MySQL binary\n"
 
1278
                                "InnoDB: and operating system combination,"
 
1279
                                " in some OS's < 2 GB\n");
1348
1280
 
1349
1281
                        return(DB_ERROR);
1350
1282
                }
1352
1284
                sum_of_new_sizes += srv_data_file_sizes[i];
1353
1285
        }
1354
1286
 
1355
 
        if (sum_of_new_sizes < 10485760 / UNIV_PAGE_SIZE) {
1356
 
          drizzled::errmsg_printf(drizzled::error::ERROR, "InnoDB: Error: tablespace size must be at least 10 MB");
 
1287
        if (sum_of_new_sizes < 640) {
 
1288
                fprintf(stderr,
 
1289
                        "InnoDB: Error: tablespace size must be"
 
1290
                        " at least 10 MB\n");
1357
1291
 
1358
1292
                return(DB_ERROR);
1359
1293
        }
1365
1299
                                        &min_flushed_lsn, &max_flushed_lsn,
1366
1300
                                        &sum_of_new_sizes);
1367
1301
        if (err != DB_SUCCESS) {
1368
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
1369
 
                                  "InnoDB: Could not open or create data files.\n"
1370
 
                                  "InnoDB: If you tried to add new data files, and it failed here,\n"
1371
 
                                  "InnoDB: you should now edit innodb_data_file_path in my.cnf back\n"
1372
 
                                  "InnoDB: to what it was, and remove the new ibdata files InnoDB created\n"
1373
 
                                  "InnoDB: in this failed attempt. InnoDB only wrote those files full of\n"
1374
 
                                  "InnoDB: zeros, but did not yet use them in any way. But be careful: do not\n"
1375
 
                                  "InnoDB: remove old data files which contain your precious data!\n");
 
1302
                fprintf(stderr,
 
1303
                        "InnoDB: Could not open or create data files.\n"
 
1304
                        "InnoDB: If you tried to add new data files,"
 
1305
                        " and it failed here,\n"
 
1306
                        "InnoDB: you should now edit innodb_data_file_path"
 
1307
                        " in my.cnf back\n"
 
1308
                        "InnoDB: to what it was, and remove the"
 
1309
                        " new ibdata files InnoDB created\n"
 
1310
                        "InnoDB: in this failed attempt. InnoDB only wrote"
 
1311
                        " those files full of\n"
 
1312
                        "InnoDB: zeros, but did not yet use them in any way."
 
1313
                        " But be careful: do not\n"
 
1314
                        "InnoDB: remove old data files"
 
1315
                        " which contain your precious data!\n");
1376
1316
 
1377
1317
                return((int) err);
1378
1318
        }
1397
1337
                }
1398
1338
                if ((log_opened && create_new_db)
1399
1339
                    || (log_opened && log_created)) {
1400
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
1401
 
                                "InnoDB: Error: all log files must be created at the same time.\n"
1402
 
                                "InnoDB: All log files must be created also in database creation.\n"
1403
 
                                "InnoDB: If you want bigger or smaller log files, shut down the\n"
1404
 
                                "InnoDB: database and make sure there were no errors in shutdown.\n"
1405
 
                                "InnoDB: Then delete the existing log files. Edit the .cnf file\n"
 
1340
                        fprintf(stderr,
 
1341
                                "InnoDB: Error: all log files must be"
 
1342
                                " created at the same time.\n"
 
1343
                                "InnoDB: All log files must be"
 
1344
                                " created also in database creation.\n"
 
1345
                                "InnoDB: If you want bigger or smaller"
 
1346
                                " log files, shut down the\n"
 
1347
                                "InnoDB: database and make sure there"
 
1348
                                " were no errors in shutdown.\n"
 
1349
                                "InnoDB: Then delete the existing log files."
 
1350
                                " Edit the .cnf file\n"
1406
1351
                                "InnoDB: and start the database again.\n");
1407
1352
 
1408
1353
                        return(DB_ERROR);
1424
1369
                    || max_arch_log_no != min_arch_log_no
1425
1370
#endif /* UNIV_LOG_ARCHIVE */
1426
1371
                    ) {
1427
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
1428
 
                                "InnoDB: Cannot initialize created log files because\n"
1429
 
                                "InnoDB: data files were not in sync with each other\n"
 
1372
                        fprintf(stderr,
 
1373
                                "InnoDB: Cannot initialize created"
 
1374
                                " log files because\n"
 
1375
                                "InnoDB: data files were not in sync"
 
1376
                                " with each other\n"
1430
1377
                                "InnoDB: or the data files are corrupt.\n");
1431
1378
 
1432
1379
                        return(DB_ERROR);
1433
1380
                }
1434
1381
 
1435
1382
                if (max_flushed_lsn < (ib_uint64_t) 1000) {
1436
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
1437
 
                                "InnoDB: Cannot initialize created log files because\n"
1438
 
                                "InnoDB: data files are corrupt, or new data files were\n"
1439
 
                                "InnoDB: created when the database was started previous\n"
1440
 
                                "InnoDB: time but the database was not shut down\n"
1441
 
                                "InnoDB: normally after that.\n");
 
1383
                        fprintf(stderr,
 
1384
                                "InnoDB: Cannot initialize created"
 
1385
                                " log files because\n"
 
1386
                                "InnoDB: data files are corrupt,"
 
1387
                                " or new data files were\n"
 
1388
                                "InnoDB: created when the database"
 
1389
                                " was started previous\n"
 
1390
                                "InnoDB: time but the database"
 
1391
                                " was not shut down\n"
 
1392
                                "InnoDB: normally after that.\n");
1442
1393
 
1443
1394
                        return(DB_ERROR);
1444
1395
                }
1460
1411
 
1461
1412
        if (create_new_db) {
1462
1413
                mtr_start(&mtr);
1463
 
 
1464
1414
                fsp_header_init(0, sum_of_new_sizes, &mtr);
1465
1415
 
1466
1416
                mtr_commit(&mtr);
1467
1417
 
1468
 
                /* To maintain backward compatibility we create only
1469
 
                the first rollback segment before the double write buffer.
1470
 
                All the remaining rollback segments will be created later,
1471
 
                after the double write buffer has been created. */
1472
1418
                trx_sys_create();
1473
 
 
1474
1419
                dict_create();
1475
 
 
1476
1420
                srv_startup_is_before_trx_rollback_phase = FALSE;
1477
1421
 
1478
1422
#ifdef UNIV_LOG_ARCHIVE
1479
1423
        } else if (srv_archive_recovery) {
1480
 
          drizzled::errmsg_printf(drizzled::error::INFO,
1481
 
                                  "InnoDB: Starting archive recovery from a backup...");
 
1424
                fprintf(stderr,
 
1425
                        "InnoDB: Starting archive"
 
1426
                        " recovery from a backup...\n");
1482
1427
                err = recv_recovery_from_archive_start(
1483
1428
                        min_flushed_lsn, srv_archive_recovery_limit_lsn,
1484
1429
                        min_arch_log_no);
1490
1435
                in any disk i/o, first call dict_boot */
1491
1436
 
1492
1437
                dict_boot();
1493
 
 
1494
1438
                trx_sys_init_at_db_start();
1495
 
 
1496
1439
                srv_startup_is_before_trx_rollback_phase = FALSE;
1497
1440
 
1498
1441
                /* Initialize the fsp free limit global variable in the log
1516
1459
                consistent state, this is REQUIRED for the recovery
1517
1460
                process to work. */
1518
1461
                err = trx_sys_file_format_max_check(
1519
 
                        srv_max_file_format_at_startup);
 
1462
                        srv_check_file_format_at_startup);
1520
1463
 
1521
1464
                if (err != DB_SUCCESS) {
1522
1465
                        return(err);
1550
1493
                dict_boot();
1551
1494
                trx_sys_init_at_db_start();
1552
1495
 
1553
 
                /* Initialize the fsp free limit global variable in the log
1554
 
                system */
1555
 
                fsp_header_get_free_limit();
1556
 
 
1557
 
                /* recv_recovery_from_checkpoint_finish needs trx lists which
1558
 
                are initialized in trx_sys_init_at_db_start(). */
1559
 
 
1560
 
                recv_recovery_from_checkpoint_finish();
1561
1496
                if (srv_force_recovery < SRV_FORCE_NO_IBUF_MERGE) {
1562
1497
                        /* The following call is necessary for the insert
1563
1498
                        buffer to work with multiple tablespaces. We must
1573
1508
                        every table in the InnoDB data dictionary that has
1574
1509
                        an .ibd file.
1575
1510
 
1576
 
                        We also determine the maximum tablespace id used. */
 
1511
                        We also determine the maximum tablespace id used.
 
1512
 
 
1513
                        TODO: We may have incomplete transactions in the
 
1514
                        data dictionary tables. Does that harm the scanning of
 
1515
                        the data dictionary below? */
1577
1516
 
1578
1517
                        dict_check_tablespaces_and_store_max_id(
1579
1518
                                recv_needed_recovery);
1580
1519
                }
1581
1520
 
1582
1521
                srv_startup_is_before_trx_rollback_phase = FALSE;
1583
 
                recv_recovery_rollback_active();
 
1522
 
 
1523
                /* Initialize the fsp free limit global variable in the log
 
1524
                system */
 
1525
                fsp_header_get_free_limit();
 
1526
 
 
1527
                /* recv_recovery_from_checkpoint_finish needs trx lists which
 
1528
                are initialized in trx_sys_init_at_db_start(). */
 
1529
 
 
1530
                recv_recovery_from_checkpoint_finish();
1584
1531
 
1585
1532
                /* It is possible that file_format tag has never
1586
1533
                been set. In this case we initialize it to minimum
1629
1576
        /* fprintf(stderr, "Max allowed record size %lu\n",
1630
1577
        page_get_free_space_of_empty() / 2); */
1631
1578
 
1632
 
        if (trx_doublewrite == NULL) {
1633
 
                /* Create the doublewrite buffer to a new tablespace */
1634
 
 
1635
 
                trx_sys_create_doublewrite_buf();
1636
 
        }
1637
 
 
1638
 
        /* Here the double write buffer has already been created and so
1639
 
        any new rollback segments will be allocated after the double
1640
 
        write buffer. The default segment should already exist.
1641
 
        We create the new segments only if it's a new database or
1642
 
        the database was shutdown cleanly. */
1643
 
 
1644
 
        /* Note: When creating the extra rollback segments during an upgrade
1645
 
        we violate the latching order, even if the change buffer is empty.
1646
 
        We make an exception in sync0sync.c and check srv_is_being_started
1647
 
        for that violation. It cannot create a deadlock because we are still
1648
 
        running in single threaded mode essentially. Only the IO threads
1649
 
        should be running at this stage. */
1650
 
 
1651
 
        trx_sys_create_rsegs(TRX_SYS_N_RSEGS - 1);
1652
 
 
1653
 
        /* Create the thread which watches the timeouts for lock waits */
1654
 
        os_thread_create(&srv_lock_timeout_thread, NULL,
 
1579
        /* Create the thread which watches the timeouts for lock waits
 
1580
        and prints InnoDB monitor info */
 
1581
 
 
1582
        os_thread_create(&srv_lock_timeout_and_monitor_thread, NULL,
1655
1583
                         thread_ids + 2 + SRV_MAX_N_IO_THREADS);
1656
1584
 
1657
1585
        /* Create the thread which warns of long semaphore waits */
1658
1586
        os_thread_create(&srv_error_monitor_thread, NULL,
1659
1587
                         thread_ids + 3 + SRV_MAX_N_IO_THREADS);
1660
 
 
1661
 
        /* Create the thread which prints InnoDB monitor info */
1662
 
        os_thread_create(&srv_monitor_thread, NULL,
1663
 
                         thread_ids + 4 + SRV_MAX_N_IO_THREADS);
1664
 
 
1665
1588
        srv_is_being_started = FALSE;
1666
1589
 
 
1590
        if (trx_doublewrite == NULL) {
 
1591
                /* Create the doublewrite buffer to a new tablespace */
 
1592
 
 
1593
                trx_sys_create_doublewrite_buf();
 
1594
        }
 
1595
 
1667
1596
        err = dict_create_or_check_foreign_constraint_tables();
1668
1597
 
1669
1598
        if (err != DB_SUCCESS) {
1675
1604
 
1676
1605
        os_thread_create(&srv_master_thread, NULL, thread_ids
1677
1606
                         + (1 + SRV_MAX_N_IO_THREADS));
1678
 
 
1679
 
        /* Currently we allow only a single purge thread. */
1680
 
        ut_a(srv_n_purge_threads == 0 || srv_n_purge_threads == 1);
1681
 
 
1682
 
        /* If the user has requested a separate purge thread then
1683
 
        start the purge thread. */
1684
 
        if (srv_n_purge_threads == 1) {
1685
 
                os_thread_create(&srv_purge_thread, NULL, NULL);
1686
 
        }
1687
 
 
1688
1607
#ifdef UNIV_DEBUG
1689
1608
        /* buf_debug_prints = TRUE; */
1690
1609
#endif /* UNIV_DEBUG */
1699
1618
        if (!srv_auto_extend_last_data_file
1700
1619
            && sum_of_data_file_sizes != tablespace_size_in_header) {
1701
1620
 
1702
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
1703
 
                                  "InnoDB: Error: tablespace size stored in header is %lu pages, but the sum of data file sizes is %lu pages.",
1704
 
                                  (ulong) tablespace_size_in_header,
1705
 
                                  (ulong) sum_of_data_file_sizes);
 
1621
                fprintf(stderr,
 
1622
                        "InnoDB: Error: tablespace size"
 
1623
                        " stored in header is %lu pages, but\n"
 
1624
                        "InnoDB: the sum of data file sizes is %lu pages\n",
 
1625
                        (ulong) tablespace_size_in_header,
 
1626
                        (ulong) sum_of_data_file_sizes);
1706
1627
 
1707
1628
                if (srv_force_recovery == 0
1708
1629
                    && sum_of_data_file_sizes < tablespace_size_in_header) {
1709
1630
                        /* This is a fatal error, the tail of a tablespace is
1710
1631
                        missing */
1711
1632
 
1712
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
1713
 
                                          "InnoDB: Cannot start InnoDB. The tail of the system tablespace is "
1714
 
                                          "missing. Have you edited innodb_data_file_path in my.cnf in an "
1715
 
                                          "inappropriate way, removing ibdata files from there? "
1716
 
                                          "You can set innodb_force_recovery=1 in my.cnf to force "
1717
 
                                          "a startup if you are trying to recover a badly corrupt database.");
 
1633
                        fprintf(stderr,
 
1634
                                "InnoDB: Cannot start InnoDB."
 
1635
                                " The tail of the system tablespace is\n"
 
1636
                                "InnoDB: missing. Have you edited"
 
1637
                                " innodb_data_file_path in my.cnf in an\n"
 
1638
                                "InnoDB: inappropriate way, removing"
 
1639
                                " ibdata files from there?\n"
 
1640
                                "InnoDB: You can set innodb_force_recovery=1"
 
1641
                                " in my.cnf to force\n"
 
1642
                                "InnoDB: a startup if you are trying"
 
1643
                                " to recover a badly corrupt database.\n");
1718
1644
 
1719
1645
                        return(DB_ERROR);
1720
1646
                }
1723
1649
        if (srv_auto_extend_last_data_file
1724
1650
            && sum_of_data_file_sizes < tablespace_size_in_header) {
1725
1651
 
1726
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
1727
 
                                  "InnoDB: Error: tablespace size stored in header is %lu pages, but the sum of data file sizes"
1728
 
                                  " is only %lu pages\n",
1729
 
                                  (ulong) tablespace_size_in_header,
1730
 
                                  (ulong) sum_of_data_file_sizes);
 
1652
                fprintf(stderr,
 
1653
                        "InnoDB: Error: tablespace size stored in header"
 
1654
                        " is %lu pages, but\n"
 
1655
                        "InnoDB: the sum of data file sizes"
 
1656
                        " is only %lu pages\n",
 
1657
                        (ulong) tablespace_size_in_header,
 
1658
                        (ulong) sum_of_data_file_sizes);
1731
1659
 
1732
1660
                if (srv_force_recovery == 0) {
1733
1661
 
1734
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
1735
 
                                "InnoDB: Cannot start InnoDB. The tail of the system tablespace is "
1736
 
                                "missing. Have you edited innodb_data_file_path in my.cnf in an "
1737
 
                                "inappropriate way, removing ibdata files from there? "
1738
 
                                "You can set innodb_force_recovery=1 in my.cnf to force "
1739
 
                                "a startup if you are trying to recover a badly corrupt database.\n");
 
1662
                        fprintf(stderr,
 
1663
                                "InnoDB: Cannot start InnoDB. The tail of"
 
1664
                                " the system tablespace is\n"
 
1665
                                "InnoDB: missing. Have you edited"
 
1666
                                " innodb_data_file_path in my.cnf in an\n"
 
1667
                                "InnoDB: inappropriate way, removing"
 
1668
                                " ibdata files from there?\n"
 
1669
                                "InnoDB: You can set innodb_force_recovery=1"
 
1670
                                " in my.cnf to force\n"
 
1671
                                "InnoDB: a startup if you are trying to"
 
1672
                                " recover a badly corrupt database.\n");
1740
1673
 
1741
1674
                        return(DB_ERROR);
1742
1675
                }
1746
1679
        os_fast_mutex_init(&srv_os_test_mutex);
1747
1680
 
1748
1681
        if (0 != os_fast_mutex_trylock(&srv_os_test_mutex)) {
1749
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
1750
 
                        "InnoDB: Error: pthread_mutex_trylock returns an unexpected value on success! Cannot continue.\n");
 
1682
                fprintf(stderr,
 
1683
                        "InnoDB: Error: pthread_mutex_trylock returns"
 
1684
                        " an unexpected value on\n"
 
1685
                        "InnoDB: success! Cannot continue.\n");
1751
1686
                exit(1);
1752
1687
        }
1753
1688
 
1760
1695
        os_fast_mutex_free(&srv_os_test_mutex);
1761
1696
 
1762
1697
        if (srv_print_verbose_log) {
1763
 
                drizzled::errmsg_printf(drizzled::error::ERROR,
1764
 
                                        "InnoDB %s started; log sequence number %"PRIu64"\n",
1765
 
                                        INNODB_VERSION_STR, srv_start_lsn);
 
1698
                ut_print_timestamp(stderr);
 
1699
                fprintf(stderr,
 
1700
                        " InnoDB Plugin %s started; "
 
1701
                        "log sequence number %"PRIu64"\n",
 
1702
                        INNODB_VERSION_STR, srv_start_lsn);
1766
1703
        }
1767
1704
 
1768
1705
        if (srv_force_recovery > 0) {
1769
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
1770
 
                                  "InnoDB: !!! innodb_force_recovery is set to %lu !!!\n",
1771
 
                                  (ulong) srv_force_recovery);
 
1706
                fprintf(stderr,
 
1707
                        "InnoDB: !!! innodb_force_recovery"
 
1708
                        " is set to %lu !!!\n",
 
1709
                        (ulong) srv_force_recovery);
1772
1710
        }
1773
1711
 
 
1712
        fflush(stderr);
 
1713
 
1774
1714
        if (trx_doublewrite_must_reset_space_ids) {
1775
1715
                /* Actually, we did not change the undo log format between
1776
1716
                4.0 and 4.1.1, and we would not need to run purge to
1785
1725
                4.1.1. It is essential that the insert buffer is emptied
1786
1726
                here! */
1787
1727
 
1788
 
          drizzled::errmsg_printf(drizzled::error::INFO,
1789
 
                                  "InnoDB: You are upgrading to an InnoDB version which allows multiple. "
1790
 
                                  "tablespaces. Wait that purge and insert buffer merge run to completion...");
 
1728
                fprintf(stderr,
 
1729
                        "InnoDB: You are upgrading to an"
 
1730
                        " InnoDB version which allows multiple\n"
 
1731
                        "InnoDB: tablespaces. Wait that purge"
 
1732
                        " and insert buffer merge run to\n"
 
1733
                        "InnoDB: completion...\n");
1791
1734
                for (;;) {
1792
1735
                        os_thread_sleep(1000000);
1793
1736
 
1799
1742
                                break;
1800
1743
                        }
1801
1744
                }
1802
 
                drizzled::errmsg_printf(drizzled::error::INFO,
1803
 
                                        "InnoDB: Full purge and insert buffer merge completed.");
 
1745
                fprintf(stderr,
 
1746
                        "InnoDB: Full purge and insert buffer merge"
 
1747
                        " completed.\n");
1804
1748
 
1805
1749
                trx_sys_mark_upgraded_to_multiple_tablespaces();
1806
1750
 
1807
 
                drizzled::errmsg_printf(drizzled::error::INFO,
1808
 
                                        "InnoDB: You have now successfully upgraded"
1809
 
                                        " to the multiple tablespaces\n"
1810
 
                                        "InnoDB: format. You should NOT DOWNGRADE"
1811
 
                                        " to an earlier version of\n"
1812
 
                                        "InnoDB: InnoDB! But if you absolutely need to"
1813
 
                                        " downgrade, see\n"
1814
 
                                        "InnoDB: " REFMAN "multiple-tablespaces.html\n"
1815
 
                                        "InnoDB: for instructions.\n");
 
1751
                fprintf(stderr,
 
1752
                        "InnoDB: You have now successfully upgraded"
 
1753
                        " to the multiple tablespaces\n"
 
1754
                        "InnoDB: format. You should NOT DOWNGRADE"
 
1755
                        " to an earlier version of\n"
 
1756
                        "InnoDB: InnoDB! But if you absolutely need to"
 
1757
                        " downgrade, see\n"
 
1758
                        "InnoDB: http://dev.mysql.com/doc/refman/5.1/en/"
 
1759
                        "multiple-tablespaces.html\n"
 
1760
                        "InnoDB: for instructions.\n");
1816
1761
        }
1817
1762
 
1818
1763
        if (srv_force_recovery == 0) {
1831
1776
        return((int) DB_SUCCESS);
1832
1777
}
1833
1778
 
1834
 
/****************************************************************//**
1835
 
Shuts down the InnoDB database.
1836
 
@return DB_SUCCESS or error code */
 
1779
/********************************************************************
 
1780
Shuts down the InnoDB database. */
1837
1781
UNIV_INTERN
1838
1782
int
1839
1783
innobase_shutdown_for_mysql(void)
1840
1784
/*=============================*/
 
1785
                                /* out: DB_SUCCESS or error code */
1841
1786
{
1842
1787
        ulint   i;
 
1788
#ifdef __NETWARE__
 
1789
        extern ibool panic_shutdown;
 
1790
#endif
1843
1791
        if (!srv_was_started) {
1844
1792
                if (srv_is_being_started) {
1845
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
1846
 
                                "InnoDB: Warning: shutting down a not properly started or created database!");
 
1793
                        ut_print_timestamp(stderr);
 
1794
                        fprintf(stderr,
 
1795
                                "  InnoDB: Warning: shutting down"
 
1796
                                " a not properly started\n"
 
1797
                                "InnoDB: or created database!\n");
1847
1798
                }
1848
1799
 
1849
1800
                return(DB_SUCCESS);
1856
1807
 
1857
1808
 
1858
1809
        if (srv_fast_shutdown == 2) {
1859
 
                drizzled::errmsg_printf(drizzled::error::INFO,
1860
 
                                        "InnoDB: MySQL has requested a very fast shutdown without flushing "
1861
 
                                        "the InnoDB buffer pool to data files. At the next mysqld startup "
1862
 
                                        "InnoDB will do a crash recovery!");
 
1810
                ut_print_timestamp(stderr);
 
1811
                fprintf(stderr,
 
1812
                        "  InnoDB: MySQL has requested a very fast shutdown"
 
1813
                        " without flushing "
 
1814
                        "the InnoDB buffer pool to data files."
 
1815
                        " At the next mysqld startup "
 
1816
                        "InnoDB will do a crash recovery!\n");
1863
1817
        }
1864
1818
 
1865
 
        logs_empty_and_mark_files_at_shutdown();
 
1819
#ifdef __NETWARE__
 
1820
        if(!panic_shutdown)
 
1821
#endif
 
1822
                logs_empty_and_mark_files_at_shutdown();
1866
1823
 
1867
1824
        if (srv_conc_n_threads != 0) {
1868
 
          drizzled::errmsg_printf(drizzled::error::WARN,
1869
 
                                  "InnoDB: Warning: query counter shows %ld queries still InnoDB: inside InnoDB at shutdown.",
1870
 
                                  srv_conc_n_threads);
 
1825
                fprintf(stderr,
 
1826
                        "InnoDB: Warning: query counter shows %ld queries"
 
1827
                        " still\n"
 
1828
                        "InnoDB: inside InnoDB at shutdown\n",
 
1829
                        srv_conc_n_threads);
1871
1830
        }
1872
1831
 
1873
1832
        /* 2. Make all threads created by InnoDB to exit */
1899
1858
                /* c. We wake the master thread so that it exits */
1900
1859
                srv_wake_master_thread();
1901
1860
 
1902
 
                /* d. We wake the purge thread so that it exits */
1903
 
                srv_wake_purge_thread();
1904
 
 
1905
 
                /* e. Exit the i/o threads */
 
1861
                /* d. Exit the i/o threads */
1906
1862
 
1907
1863
                os_aio_wake_all_threads_at_shutdown();
1908
1864
 
1912
1868
                        /* All the threads have exited or are just exiting;
1913
1869
                        NOTE that the threads may not have completed their
1914
1870
                        exit yet. Should we use pthread_join() to make sure
1915
 
                        they have exited? If we did, we would have to
1916
 
                        remove the pthread_detach() from
1917
 
                        os_thread_exit().  Now we just sleep 0.1
1918
 
                        seconds and hope that is enough! */
 
1871
                        they have exited? Now we just sleep 0.1 seconds and
 
1872
                        hope that is enough! */
1919
1873
 
1920
1874
                        os_mutex_exit(os_sync_mutex);
1921
1875
 
1930
1884
        }
1931
1885
 
1932
1886
        if (i == 1000) {
1933
 
          drizzled::errmsg_printf(drizzled::error::WARN,
1934
 
                        "InnoDB: Warning: %lu threads created by InnoDB had not exited at shutdown!",
 
1887
                fprintf(stderr,
 
1888
                        "InnoDB: Warning: %lu threads created by InnoDB"
 
1889
                        " had not exited at shutdown!\n",
1935
1890
                        (ulong) os_thread_count);
1936
1891
        }
1937
1892
 
1953
1908
                srv_misc_tmpfile = 0;
1954
1909
        }
1955
1910
 
1956
 
        /* This must be disabled before closing the buffer pool
1957
 
        and closing the data dictionary.  */
1958
 
        btr_search_disable();
1959
 
 
1960
 
        ibuf_close();
1961
 
        log_shutdown();
1962
 
        lock_sys_close();
1963
 
        thr_local_close();
1964
1911
        trx_sys_file_format_close();
1965
 
        trx_sys_close();
1966
1912
 
1967
1913
        mutex_free(&srv_monitor_file_mutex);
1968
1914
        mutex_free(&srv_dict_tmpfile_mutex);
1969
1915
        mutex_free(&srv_misc_tmpfile_mutex);
1970
 
        dict_close();
1971
 
        btr_search_sys_free();
1972
1916
 
1973
1917
        /* 3. Free all InnoDB's own mutexes and the os_fast_mutexes inside
1974
1918
        them */
1975
 
        os_aio_free();
1976
1919
        sync_close();
 
1920
 
 
1921
        /* 4. Free the os_conc_mutex and all os_events and os_mutexes */
 
1922
 
1977
1923
        srv_free();
1978
 
        fil_close();
1979
 
 
1980
 
        /* 4. Free the os_conc_mutex and all os_events and os_mutexes */
1981
 
 
1982
1924
        os_sync_free();
1983
1925
 
1984
 
        /* 5. Free all allocated memory */
1985
 
 
1986
 
        pars_lexer_close();
1987
 
        log_mem_free();
1988
 
        buf_pool_free(srv_buf_pool_instances);
1989
 
        mem_close();
1990
 
 
1991
 
        /* ut_free_all_mem() frees all allocated memory not freed yet
1992
 
        in shutdown, and it will also free the ut_list_mutex, so it
1993
 
        should be the last one for all operation */
 
1926
        /* Check that all read views are closed except read view owned
 
1927
        by a purge. */
 
1928
 
 
1929
        if (UT_LIST_GET_LEN(trx_sys->view_list) > 1) {
 
1930
                fprintf(stderr,
 
1931
                        "InnoDB: Error: all read views were not closed"
 
1932
                        " before shutdown:\n"
 
1933
                        "InnoDB: %lu read views open \n",
 
1934
                        UT_LIST_GET_LEN(trx_sys->view_list) - 1);
 
1935
        }
 
1936
 
 
1937
        /* 5. Free all allocated memory and the os_fast_mutex created in
 
1938
        ut0mem.c */
 
1939
 
 
1940
        buf_pool_free();
1994
1941
        ut_free_all_mem();
1995
1942
 
1996
1943
        if (os_thread_count != 0
1997
1944
            || os_event_count != 0
1998
1945
            || os_mutex_count != 0
1999
1946
            || os_fast_mutex_count != 0) {
2000
 
          drizzled::errmsg_printf(drizzled::error::WARN,
2001
 
                                  "InnoDB: Warning: some resources were not cleaned up in shutdown:\n"
2002
 
                                  "InnoDB: threads %lu, events %lu, os_mutexes %lu, os_fast_mutexes %lu\n",
2003
 
                                  (ulong) os_thread_count, (ulong) os_event_count,
2004
 
                                  (ulong) os_mutex_count, (ulong) os_fast_mutex_count);
 
1947
                fprintf(stderr,
 
1948
                        "InnoDB: Warning: some resources were not"
 
1949
                        " cleaned up in shutdown:\n"
 
1950
                        "InnoDB: threads %lu, events %lu,"
 
1951
                        " os_mutexes %lu, os_fast_mutexes %lu\n",
 
1952
                        (ulong) os_thread_count, (ulong) os_event_count,
 
1953
                        (ulong) os_mutex_count, (ulong) os_fast_mutex_count);
2005
1954
        }
2006
1955
 
2007
1956
        if (dict_foreign_err_file) {
2012
1961
        }
2013
1962
 
2014
1963
        if (srv_print_verbose_log) {
2015
 
                drizzled::errmsg_printf(drizzled::error::INFO,
2016
 
                                        "InnoDB: Shutdown completed log sequence number %"PRIu64,
2017
 
                                        srv_shutdown_lsn);
 
1964
                ut_print_timestamp(stderr);
 
1965
                fprintf(stderr,
 
1966
                        "  InnoDB: Shutdown completed;"
 
1967
                        " log sequence number %"PRIu64"\n",
 
1968
                        srv_shutdown_lsn);
2018
1969
        }
2019
1970
 
2020
1971
        srv_was_started = FALSE;
2021
 
        srv_start_has_been_called = FALSE;
2022
1972
 
2023
1973
        return((int) DB_SUCCESS);
2024
1974
}
 
1975
 
 
1976
#ifdef __NETWARE__
 
1977
void set_panic_flag_for_netware()
 
1978
{
 
1979
        extern ibool panic_shutdown;
 
1980
        panic_shutdown = TRUE;
 
1981
}
 
1982
#endif /* __NETWARE__ */
2025
1983
#endif /* !UNIV_HOTBACKUP */