~linuxjedi/drizzle/trunk-bug-667053

« back to all changes in this revision

Viewing changes to storage/innobase/include/srv0srv.h

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
The server main program
 
3
 
 
4
(c) 1995 Innobase Oy
 
5
 
 
6
Created 10/10/1995 Heikki Tuuri
 
7
*******************************************************/
 
8
 
 
9
 
 
10
#ifndef srv0srv_h
 
11
#define srv0srv_h
 
12
 
 
13
#include "univ.i"
 
14
#include "sync0sync.h"
 
15
#include "os0sync.h"
 
16
#include "que0types.h"
 
17
#include "trx0types.h"
 
18
 
 
19
extern const char*      srv_main_thread_op_info;
 
20
 
 
21
/* Prefix used by MySQL to indicate pre-5.1 table name encoding */
 
22
extern const char       srv_mysql50_table_name_prefix[9];
 
23
 
 
24
/* When this event is set the lock timeout and InnoDB monitor
 
25
thread starts running */
 
26
extern os_event_t       srv_lock_timeout_thread_event;
 
27
 
 
28
/* If the last data file is auto-extended, we add this many pages to it
 
29
at a time */
 
30
#define SRV_AUTO_EXTEND_INCREMENT       \
 
31
        (srv_auto_extend_increment * ((1024 * 1024) / UNIV_PAGE_SIZE))
 
32
 
 
33
/* This is set to TRUE if the MySQL user has set it in MySQL */
 
34
extern ibool    srv_lower_case_table_names;
 
35
 
 
36
/* Mutex for locking srv_monitor_file */
 
37
extern mutex_t  srv_monitor_file_mutex;
 
38
/* Temporary file for innodb monitor output */
 
39
extern FILE*    srv_monitor_file;
 
40
/* Mutex for locking srv_dict_tmpfile.
 
41
This mutex has a very high rank; threads reserving it should not
 
42
be holding any InnoDB latches. */
 
43
extern mutex_t  srv_dict_tmpfile_mutex;
 
44
/* Temporary file for output from the data dictionary */
 
45
extern FILE*    srv_dict_tmpfile;
 
46
/* Mutex for locking srv_misc_tmpfile.
 
47
This mutex has a very low rank; threads reserving it should not
 
48
acquire any further latches or sleep before releasing this one. */
 
49
extern mutex_t  srv_misc_tmpfile_mutex;
 
50
/* Temporary file for miscellanous diagnostic output */
 
51
extern FILE*    srv_misc_tmpfile;
 
52
 
 
53
/* Server parameters which are read from the initfile */
 
54
 
 
55
extern char*    srv_data_home;
 
56
#ifdef UNIV_LOG_ARCHIVE
 
57
extern char*    srv_arch_dir;
 
58
#endif /* UNIV_LOG_ARCHIVE */
 
59
 
 
60
extern ibool    srv_file_per_table;
 
61
extern ibool    srv_locks_unsafe_for_binlog;
 
62
 
 
63
extern ulint    srv_n_data_files;
 
64
extern char**   srv_data_file_names;
 
65
extern ulint*   srv_data_file_sizes;
 
66
extern ulint*   srv_data_file_is_raw_partition;
 
67
 
 
68
extern ibool    srv_auto_extend_last_data_file;
 
69
extern ulint    srv_last_file_size_max;
 
70
extern ulong    srv_auto_extend_increment;
 
71
 
 
72
extern ibool    srv_created_new_raw;
 
73
 
 
74
#define SRV_NEW_RAW     1
 
75
#define SRV_OLD_RAW     2
 
76
 
 
77
extern char**   srv_log_group_home_dirs;
 
78
 
 
79
extern ulint    srv_n_log_groups;
 
80
extern ulint    srv_n_log_files;
 
81
extern ulint    srv_log_file_size;
 
82
extern ulint    srv_log_buffer_size;
 
83
extern ulong    srv_flush_log_at_trx_commit;
 
84
 
 
85
extern byte     srv_latin1_ordering[256];/* The sort order table of the latin1
 
86
                                        character set */
 
87
extern ulint    srv_pool_size;
 
88
extern ulint    srv_awe_window_size;
 
89
extern ulint    srv_mem_pool_size;
 
90
extern ulint    srv_lock_table_size;
 
91
 
 
92
extern ulint    srv_n_file_io_threads;
 
93
 
 
94
#ifdef UNIV_LOG_ARCHIVE
 
95
extern ibool    srv_log_archive_on;
 
96
extern ibool    srv_archive_recovery;
 
97
extern dulint   srv_archive_recovery_limit_lsn;
 
98
#endif /* UNIV_LOG_ARCHIVE */
 
99
 
 
100
extern ulint    srv_lock_wait_timeout;
 
101
 
 
102
extern char*    srv_file_flush_method_str;
 
103
extern ulint    srv_unix_file_flush_method;
 
104
extern ulint    srv_win_file_flush_method;
 
105
 
 
106
extern ulint    srv_max_n_open_files;
 
107
 
 
108
extern ulint    srv_max_dirty_pages_pct;
 
109
 
 
110
extern ulint    srv_force_recovery;
 
111
extern ulong    srv_thread_concurrency;
 
112
extern ulong    srv_commit_concurrency;
 
113
 
 
114
extern ulint    srv_max_n_threads;
 
115
 
 
116
extern lint     srv_conc_n_threads;
 
117
 
 
118
extern ulint    srv_fast_shutdown;       /* If this is 1, do not do a
 
119
                                         purge and index buffer merge.
 
120
                                         If this 2, do not even flush the
 
121
                                         buffer pool to data files at the
 
122
                                         shutdown: we effectively 'crash'
 
123
                                         InnoDB (but lose no committed
 
124
                                         transactions). */
 
125
extern ibool    srv_innodb_status;
 
126
 
 
127
extern ibool    srv_stats_on_metadata;
 
128
 
 
129
extern ibool    srv_use_doublewrite_buf;
 
130
extern ibool    srv_use_checksums;
 
131
 
 
132
extern ibool    srv_set_thread_priorities;
 
133
extern int      srv_query_thread_priority;
 
134
 
 
135
extern ulong    srv_max_buf_pool_modified_pct;
 
136
extern ulong    srv_max_purge_lag;
 
137
extern ibool    srv_use_awe;
 
138
extern ibool    srv_use_adaptive_hash_indexes;
 
139
/*-------------------------------------------*/
 
140
 
 
141
extern ulint    srv_n_rows_inserted;
 
142
extern ulint    srv_n_rows_updated;
 
143
extern ulint    srv_n_rows_deleted;
 
144
extern ulint    srv_n_rows_read;
 
145
 
 
146
extern ibool    srv_print_innodb_monitor;
 
147
extern ibool    srv_print_innodb_lock_monitor;
 
148
extern ibool    srv_print_innodb_tablespace_monitor;
 
149
extern ibool    srv_print_verbose_log;
 
150
extern ibool    srv_print_innodb_table_monitor;
 
151
 
 
152
extern ibool    srv_lock_timeout_and_monitor_active;
 
153
extern ibool    srv_error_monitor_active;
 
154
 
 
155
extern ulong    srv_n_spin_wait_rounds;
 
156
extern ulong    srv_n_free_tickets_to_enter;
 
157
extern ulong    srv_thread_sleep_delay;
 
158
extern ulint    srv_spin_wait_delay;
 
159
extern ibool    srv_priority_boost;
 
160
 
 
161
extern  ulint   srv_pool_size;
 
162
extern  ulint   srv_mem_pool_size;
 
163
extern  ulint   srv_lock_table_size;
 
164
 
 
165
extern  ibool   srv_print_thread_releases;
 
166
extern  ibool   srv_print_lock_waits;
 
167
extern  ibool   srv_print_buf_io;
 
168
extern  ibool   srv_print_log_io;
 
169
extern  ibool   srv_print_latch_waits;
 
170
 
 
171
extern ulint    srv_activity_count;
 
172
extern ulint    srv_fatal_semaphore_wait_threshold;
 
173
extern ulint    srv_dml_needed_delay;
 
174
 
 
175
extern mutex_t* kernel_mutex_temp;/* mutex protecting the server, trx structs,
 
176
                                query threads, and lock table: we allocate
 
177
                                it from dynamic memory to get it to the
 
178
                                same DRAM page as other hotspot semaphores */
 
179
#define kernel_mutex (*kernel_mutex_temp)
 
180
 
 
181
#define SRV_MAX_N_IO_THREADS    100
 
182
 
 
183
/* Array of English strings describing the current state of an
 
184
i/o handler thread */
 
185
extern const char* srv_io_thread_op_info[];
 
186
extern const char* srv_io_thread_function[];
 
187
 
 
188
/* the number of the log write requests done */
 
189
extern ulint srv_log_write_requests;
 
190
 
 
191
/* the number of physical writes to the log performed */
 
192
extern ulint srv_log_writes;
 
193
 
 
194
/* amount of data written to the log files in bytes */
 
195
extern ulint srv_os_log_written;
 
196
 
 
197
/* amount of writes being done to the log files */
 
198
extern ulint srv_os_log_pending_writes;
 
199
 
 
200
/* we increase this counter, when there we don't have enough space in the
 
201
log buffer and have to flush it */
 
202
extern ulint srv_log_waits;
 
203
 
 
204
/* variable that counts amount of data read in total (in bytes) */
 
205
extern ulint srv_data_read;
 
206
 
 
207
/* here we count the amount of data written in total (in bytes) */
 
208
extern ulint srv_data_written;
 
209
 
 
210
/* this variable counts the amount of times, when the doublewrite buffer
 
211
was flushed */
 
212
extern ulint srv_dblwr_writes;
 
213
 
 
214
/* here we store the number of pages that have been flushed to the
 
215
doublewrite buffer */
 
216
extern ulint srv_dblwr_pages_written;
 
217
 
 
218
/* in this variable we store the number of write requests issued */
 
219
extern ulint srv_buf_pool_write_requests;
 
220
 
 
221
/* here we store the number of times when we had to wait for a free page
 
222
in the buffer pool. It happens when the buffer pool is full and we need
 
223
to make a flush, in order to be able to read or create a page. */
 
224
extern ulint srv_buf_pool_wait_free;
 
225
 
 
226
/* variable to count the number of pages that were written from the
 
227
buffer pool to disk */
 
228
extern ulint srv_buf_pool_flushed;
 
229
 
 
230
/* variable to count the number of buffer pool reads that led to the
 
231
reading of a disk page */
 
232
extern ulint srv_buf_pool_reads;
 
233
 
 
234
/* variable to count the number of sequential read-aheads were done */
 
235
extern ulint srv_read_ahead_seq;
 
236
 
 
237
/* variable to count the number of random read-aheads were done */
 
238
extern ulint srv_read_ahead_rnd;
 
239
 
 
240
/* In this structure we store status variables to be passed to MySQL */
 
241
typedef struct export_var_struct export_struc;
 
242
 
 
243
extern export_struc export_vars;
 
244
 
 
245
typedef struct srv_sys_struct   srv_sys_t;
 
246
 
 
247
/* The server system */
 
248
extern srv_sys_t*       srv_sys;
 
249
 
 
250
/* Alternatives for the file flush option in Unix; see the InnoDB manual
 
251
about what these mean */
 
252
#define SRV_UNIX_FSYNC          1       /* This is the default */
 
253
#define SRV_UNIX_O_DSYNC        2
 
254
#define SRV_UNIX_LITTLESYNC     3
 
255
#define SRV_UNIX_NOSYNC         4
 
256
#define SRV_UNIX_O_DIRECT       5
 
257
 
 
258
/* Alternatives for file i/o in Windows */
 
259
#define SRV_WIN_IO_NORMAL               1
 
260
#define SRV_WIN_IO_UNBUFFERED           2       /* This is the default */
 
261
 
 
262
/* Alternatives for srv_force_recovery. Non-zero values are intended
 
263
to help the user get a damaged database up so that he can dump intact
 
264
tables and rows with SELECT INTO OUTFILE. The database must not otherwise
 
265
be used with these options! A bigger number below means that all precautions
 
266
of lower numbers are included. */
 
267
 
 
268
#define SRV_FORCE_IGNORE_CORRUPT 1      /* let the server run even if it
 
269
                                        detects a corrupt page */
 
270
#define SRV_FORCE_NO_BACKGROUND 2       /* prevent the main thread from
 
271
                                        running: if a crash would occur
 
272
                                        in purge, this prevents it */
 
273
#define SRV_FORCE_NO_TRX_UNDO   3       /* do not run trx rollback after
 
274
                                        recovery */
 
275
#define SRV_FORCE_NO_IBUF_MERGE 4       /* prevent also ibuf operations:
 
276
                                        if they would cause a crash, better
 
277
                                        not do them */
 
278
#define SRV_FORCE_NO_UNDO_LOG_SCAN 5    /* do not look at undo logs when
 
279
                                        starting the database: InnoDB will
 
280
                                        treat even incomplete transactions
 
281
                                        as committed */
 
282
#define SRV_FORCE_NO_LOG_REDO   6       /* do not do the log roll-forward
 
283
                                        in connection with recovery */
 
284
 
 
285
/*************************************************************************
 
286
Boots Innobase server. */
 
287
 
 
288
ulint
 
289
srv_boot(void);
 
290
/*==========*/
 
291
                        /* out: DB_SUCCESS or error code */
 
292
/*************************************************************************
 
293
Initializes the server. */
 
294
 
 
295
void
 
296
srv_init(void);
 
297
/*==========*/
 
298
/*************************************************************************
 
299
Frees the OS fast mutex created in srv_boot(). */
 
300
 
 
301
void
 
302
srv_free(void);
 
303
/*==========*/
 
304
/*************************************************************************
 
305
Initializes the synchronization primitives, memory system, and the thread
 
306
local storage. */
 
307
 
 
308
void
 
309
srv_general_init(void);
 
310
/*==================*/
 
311
/*************************************************************************
 
312
Gets the number of threads in the system. */
 
313
 
 
314
ulint
 
315
srv_get_n_threads(void);
 
316
/*===================*/
 
317
/*************************************************************************
 
318
Returns the calling thread type. */
 
319
 
 
320
ulint
 
321
srv_get_thread_type(void);
 
322
/*=====================*/
 
323
                        /* out: SRV_COM, ... */
 
324
/*************************************************************************
 
325
Sets the info describing an i/o thread current state. */
 
326
 
 
327
void
 
328
srv_set_io_thread_op_info(
 
329
/*======================*/
 
330
        ulint           i,      /* in: the 'segment' of the i/o thread */
 
331
        const char*     str);   /* in: constant char string describing the
 
332
                                state */
 
333
/*************************************************************************
 
334
Releases threads of the type given from suspension in the thread table.
 
335
NOTE! The server mutex has to be reserved by the caller! */
 
336
 
 
337
ulint
 
338
srv_release_threads(
 
339
/*================*/
 
340
                        /* out: number of threads released: this may be
 
341
                        < n if not enough threads were suspended at the
 
342
                        moment */
 
343
        ulint   type,   /* in: thread type */
 
344
        ulint   n);     /* in: number of threads to release */
 
345
/*************************************************************************
 
346
The master thread controlling the server. */
 
347
 
 
348
os_thread_ret_t
 
349
srv_master_thread(
 
350
/*==============*/
 
351
                        /* out: a dummy parameter */
 
352
        void*   arg);   /* in: a dummy parameter required by
 
353
                        os_thread_create */
 
354
/***********************************************************************
 
355
Tells the Innobase server that there has been activity in the database
 
356
and wakes up the master thread if it is suspended (not sleeping). Used
 
357
in the MySQL interface. Note that there is a small chance that the master
 
358
thread stays suspended (we do not protect our operation with the kernel
 
359
mutex, for performace reasons). */
 
360
 
 
361
void
 
362
srv_active_wake_master_thread(void);
 
363
/*===============================*/
 
364
/***********************************************************************
 
365
Wakes up the master thread if it is suspended or being suspended. */
 
366
 
 
367
void
 
368
srv_wake_master_thread(void);
 
369
/*========================*/
 
370
/*************************************************************************
 
371
Puts an OS thread to wait if there are too many concurrent threads
 
372
(>= srv_thread_concurrency) inside InnoDB. The threads wait in a FIFO queue. */
 
373
 
 
374
void
 
375
srv_conc_enter_innodb(
 
376
/*==================*/
 
377
        trx_t*  trx);   /* in: transaction object associated with the
 
378
                        thread */
 
379
/*************************************************************************
 
380
This lets a thread enter InnoDB regardless of the number of threads inside
 
381
InnoDB. This must be called when a thread ends a lock wait. */
 
382
 
 
383
void
 
384
srv_conc_force_enter_innodb(
 
385
/*========================*/
 
386
        trx_t*  trx);   /* in: transaction object associated with the
 
387
                        thread */
 
388
/*************************************************************************
 
389
This must be called when a thread exits InnoDB in a lock wait or at the
 
390
end of an SQL statement. */
 
391
 
 
392
void
 
393
srv_conc_force_exit_innodb(
 
394
/*=======================*/
 
395
        trx_t*  trx);   /* in: transaction object associated with the
 
396
                        thread */
 
397
/*************************************************************************
 
398
This must be called when a thread exits InnoDB. */
 
399
 
 
400
void
 
401
srv_conc_exit_innodb(
 
402
/*=================*/
 
403
        trx_t*  trx);   /* in: transaction object associated with the
 
404
                        thread */
 
405
/*******************************************************************
 
406
Puts a MySQL OS thread to wait for a lock to be released. If an error
 
407
occurs during the wait trx->error_state associated with thr is
 
408
!= DB_SUCCESS when we return. DB_LOCK_WAIT_TIMEOUT and DB_DEADLOCK
 
409
are possible errors. DB_DEADLOCK is returned if selective deadlock
 
410
resolution chose this transaction as a victim. */
 
411
 
 
412
void
 
413
srv_suspend_mysql_thread(
 
414
/*=====================*/
 
415
        que_thr_t*      thr);   /* in: query thread associated with the MySQL
 
416
                                OS thread */
 
417
/************************************************************************
 
418
Releases a MySQL OS thread waiting for a lock to be released, if the
 
419
thread is already suspended. */
 
420
 
 
421
void
 
422
srv_release_mysql_thread_if_suspended(
 
423
/*==================================*/
 
424
        que_thr_t*      thr);   /* in: query thread associated with the
 
425
                                MySQL OS thread  */
 
426
/*************************************************************************
 
427
A thread which wakes up threads whose lock wait may have lasted too long.
 
428
This also prints the info output by various InnoDB monitors. */
 
429
 
 
430
os_thread_ret_t
 
431
srv_lock_timeout_and_monitor_thread(
 
432
/*================================*/
 
433
                        /* out: a dummy parameter */
 
434
        void*   arg);   /* in: a dummy parameter required by
 
435
                        os_thread_create */
 
436
/*************************************************************************
 
437
A thread which prints warnings about semaphore waits which have lasted
 
438
too long. These can be used to track bugs which cause hangs. */
 
439
 
 
440
os_thread_ret_t
 
441
srv_error_monitor_thread(
 
442
/*=====================*/
 
443
                        /* out: a dummy parameter */
 
444
        void*   arg);   /* in: a dummy parameter required by
 
445
                        os_thread_create */
 
446
/**********************************************************************
 
447
Outputs to a file the output of the InnoDB Monitor. */
 
448
 
 
449
void
 
450
srv_printf_innodb_monitor(
 
451
/*======================*/
 
452
        FILE*   file,           /* in: output stream */
 
453
        ulint*  trx_start,      /* out: file position of the start of
 
454
                                the list of active transactions */
 
455
        ulint*  trx_end);       /* out: file position of the end of
 
456
                                the list of active transactions */
 
457
 
 
458
/**********************************************************************
 
459
Function to pass InnoDB status variables to MySQL */
 
460
 
 
461
void
 
462
srv_export_innodb_status(void);
 
463
/*=====================*/
 
464
 
 
465
/* Types for the threads existing in the system. Threads of types 4 - 9
 
466
are called utility threads. Note that utility threads are mainly disk
 
467
bound, except that version threads 6 - 7 may also be CPU bound, if
 
468
cleaning versions from the buffer pool. */
 
469
 
 
470
#define SRV_COM         1       /* threads serving communication and queries */
 
471
#define SRV_CONSOLE     2       /* thread serving console */
 
472
#define SRV_WORKER      3       /* threads serving parallelized queries and
 
473
                                queries released from lock wait */
 
474
#define SRV_BUFFER      4       /* thread flushing dirty buffer blocks,
 
475
                                not currently in use */
 
476
#define SRV_RECOVERY    5       /* threads finishing a recovery,
 
477
                                not currently in use */
 
478
#define SRV_INSERT      6       /* thread flushing the insert buffer to disk,
 
479
                                not currently in use */
 
480
#define SRV_MASTER      7       /* the master thread, (whose type number must
 
481
                                be biggest) */
 
482
 
 
483
/* Thread slot in the thread table */
 
484
typedef struct srv_slot_struct  srv_slot_t;
 
485
 
 
486
/* Thread table is an array of slots */
 
487
typedef srv_slot_t      srv_table_t;
 
488
 
 
489
/* In this structure we store status variables to be passed to MySQL */
 
490
struct export_var_struct{
 
491
        ulint innodb_data_pending_reads;
 
492
        ulint innodb_data_pending_writes;
 
493
        ulint innodb_data_pending_fsyncs;
 
494
        ulint innodb_data_fsyncs;
 
495
        ulint innodb_data_read;
 
496
        ulint innodb_data_writes;
 
497
        ulint innodb_data_written;
 
498
        ulint innodb_data_reads;
 
499
        ulint innodb_buffer_pool_pages_total;
 
500
        ulint innodb_buffer_pool_pages_data;
 
501
        ulint innodb_buffer_pool_pages_dirty;
 
502
        ulint innodb_buffer_pool_pages_misc;
 
503
        ulint innodb_buffer_pool_pages_free;
 
504
        ulint innodb_buffer_pool_pages_latched;
 
505
        ulint innodb_buffer_pool_read_requests;
 
506
        ulint innodb_buffer_pool_reads;
 
507
        ulint innodb_buffer_pool_wait_free;
 
508
        ulint innodb_buffer_pool_pages_flushed;
 
509
        ulint innodb_buffer_pool_write_requests;
 
510
        ulint innodb_buffer_pool_read_ahead_seq;
 
511
        ulint innodb_buffer_pool_read_ahead_rnd;
 
512
        ulint innodb_dblwr_pages_written;
 
513
        ulint innodb_dblwr_writes;
 
514
        ulint innodb_log_waits;
 
515
        ulint innodb_log_write_requests;
 
516
        ulint innodb_log_writes;
 
517
        ulint innodb_os_log_written;
 
518
        ulint innodb_os_log_fsyncs;
 
519
        ulint innodb_os_log_pending_writes;
 
520
        ulint innodb_os_log_pending_fsyncs;
 
521
        ulint innodb_page_size;
 
522
        ulint innodb_pages_created;
 
523
        ulint innodb_pages_read;
 
524
        ulint innodb_pages_written;
 
525
        ulint innodb_row_lock_waits;
 
526
        ulint innodb_row_lock_current_waits;
 
527
        ib_longlong innodb_row_lock_time;
 
528
        ulint innodb_row_lock_time_avg;
 
529
        ulint innodb_row_lock_time_max;
 
530
        ulint innodb_rows_read;
 
531
        ulint innodb_rows_inserted;
 
532
        ulint innodb_rows_updated;
 
533
        ulint innodb_rows_deleted;
 
534
};
 
535
 
 
536
/* The server system struct */
 
537
struct srv_sys_struct{
 
538
        srv_table_t*    threads;        /* server thread table */
 
539
        UT_LIST_BASE_NODE_T(que_thr_t)
 
540
                        tasks;          /* task queue */
 
541
        dict_index_t*   dummy_ind1;     /* dummy index for old-style
 
542
                                        supremum and infimum records */
 
543
        dict_index_t*   dummy_ind2;     /* dummy index for new-style
 
544
                                        supremum and infimum records */
 
545
};
 
546
 
 
547
extern ulint    srv_n_threads_active[];
 
548
 
 
549
#endif
 
550