~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Merged in latest plugin-slot-reorg.

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