~drizzle-trunk/drizzle/development

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