srv0srv.h 13.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/******************************************************
The server main program

(c) 1995 Innobase Oy

Created 10/10/1995 Heikki Tuuri
*******************************************************/


#ifndef srv0srv_h
#define srv0srv_h

#include "univ.i"
#include "sync0sync.h"
#include "os0sync.h"
#include "com0com.h"
#include "que0types.h"
unknown's avatar
Merge  
unknown committed
18
#include "trx0types.h"
19

unknown's avatar
unknown committed
20 21
/* Buffer which can be used in printing fatal error messages */
extern char	srv_fatal_errbuf[];
22 23 24 25 26

/* When this event is set the lock timeout and InnoDB monitor
thread starts running */
extern os_event_t	srv_lock_timeout_thread_event;

unknown's avatar
unknown committed
27 28 29 30
/* If the last data file is auto-extended, we add this many pages to it
at a time */
#define SRV_AUTO_EXTEND_INCREMENT   (8 * ((1024 * 1024) / UNIV_PAGE_SIZE))

unknown's avatar
unknown committed
31 32 33
/* This is set to TRUE if the MySQL user has set it in MySQL */
extern ibool	srv_lower_case_table_names;

34 35 36 37 38 39 40 41
/* Server parameters which are read from the initfile */

extern char*	srv_data_home;
extern char*	srv_arch_dir;

extern ulint	srv_n_data_files;
extern char**	srv_data_file_names;
extern ulint*	srv_data_file_sizes;
42
extern ulint*   srv_data_file_is_raw_partition;
43

unknown's avatar
unknown committed
44 45 46
extern ibool	srv_auto_extend_last_data_file;
extern ulint	srv_last_file_size_max;

47 48
extern ibool	srv_created_new_raw;

49 50 51
#define SRV_NEW_RAW    1
#define SRV_OLD_RAW    2

52 53 54 55 56 57 58
extern char**	srv_log_group_home_dirs;

extern ulint	srv_n_log_groups;
extern ulint	srv_n_log_files;
extern ulint	srv_log_file_size;
extern ibool	srv_log_archive_on;
extern ulint	srv_log_buffer_size;
unknown's avatar
unknown committed
59
extern ulint	srv_flush_log_at_trx_commit;
60

61 62
extern byte	srv_latin1_ordering[256];/* The sort order table of the latin1
					character set */
63 64 65 66 67 68 69 70 71 72 73
extern ulint	srv_pool_size;
extern ulint	srv_mem_pool_size;
extern ulint	srv_lock_table_size;

extern ulint	srv_n_file_io_threads;

extern ibool	srv_archive_recovery;
extern dulint	srv_archive_recovery_limit_lsn;

extern ulint	srv_lock_wait_timeout;

unknown's avatar
unknown committed
74
extern char*    srv_file_flush_method_str;
75
extern ulint    srv_unix_file_flush_method;
unknown's avatar
unknown committed
76
extern ulint   	srv_win_file_flush_method;
77
extern ulint	srv_force_recovery;
unknown's avatar
Merge  
unknown committed
78
extern ulint	srv_thread_concurrency;
unknown's avatar
unknown committed
79 80 81

extern lint	srv_conc_n_threads;

unknown's avatar
Merge  
unknown committed
82
extern ibool	srv_fast_shutdown;
83

84 85
extern ibool	srv_use_doublewrite_buf;

unknown's avatar
unknown committed
86 87 88
extern ibool    srv_set_thread_priorities;
extern int      srv_query_thread_priority;

89
/*-------------------------------------------*/
90

91 92 93 94 95
extern ulint	srv_n_rows_inserted;
extern ulint	srv_n_rows_updated;
extern ulint	srv_n_rows_deleted;
extern ulint	srv_n_rows_read;

96
extern ibool	srv_print_innodb_monitor;
97 98
extern ibool    srv_print_innodb_lock_monitor;
extern ibool    srv_print_innodb_tablespace_monitor;
99
extern ibool    srv_print_verbose_log;
100
extern ibool    srv_print_innodb_table_monitor;
101

unknown's avatar
Merge  
unknown committed
102 103 104
extern ibool	srv_lock_timeout_and_monitor_active;
extern ibool	srv_error_monitor_active; 

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
extern ulint	srv_n_spin_wait_rounds;
extern ulint	srv_spin_wait_delay;
extern ibool	srv_priority_boost;
		
extern	ulint	srv_pool_size;
extern	ulint	srv_mem_pool_size;
extern	ulint	srv_lock_table_size;

extern	ulint	srv_sim_disk_wait_pct;
extern	ulint	srv_sim_disk_wait_len;
extern	ibool	srv_sim_disk_wait_by_yield;
extern	ibool	srv_sim_disk_wait_by_wait;

extern	ibool	srv_measure_contention;
extern	ibool	srv_measure_by_spin;
	
extern	ibool	srv_print_thread_releases;
extern	ibool	srv_print_lock_waits;
extern	ibool	srv_print_buf_io;
extern	ibool	srv_print_log_io;
extern	ibool	srv_print_parsed_sql;
extern	ibool	srv_print_latch_waits;

extern	ibool	srv_test_nocache;
extern	ibool	srv_test_cache_evict;

extern	ibool	srv_test_extra_mutexes;
extern	ibool	srv_test_sync;
extern	ulint	srv_test_n_threads;
extern	ulint	srv_test_n_loops;
extern	ulint	srv_test_n_free_rnds;
extern	ulint	srv_test_n_reserved_rnds;
extern	ulint	srv_test_n_mutexes;
extern	ulint	srv_test_array_size;

extern ulint	srv_activity_count;

extern mutex_t*	kernel_mutex_temp;/* mutex protecting the server, trx structs,
				query threads, and lock table: we allocate
				it from dynamic memory to get it to the
				same DRAM page as other hotspot semaphores */
#define kernel_mutex (*kernel_mutex_temp)
147 148

#define SRV_MAX_N_IO_THREADS	100
149
				
150 151 152 153
/* Array of English strings describing the current state of an
i/o handler thread */
extern char* srv_io_thread_op_info[];

154 155 156 157 158
typedef struct srv_sys_struct	srv_sys_t;

/* The server system */
extern srv_sys_t*	srv_sys;

unknown's avatar
unknown committed
159
/* Alternatives for the file flush option in Unix; see the InnoDB manual about
160
what these mean */
unknown's avatar
unknown committed
161 162 163
#define SRV_UNIX_FDATASYNC   1	/* This is the default; it is currently mapped
				to a call of fsync() because fdatasync()
				seemed to corrupt files in Linux and Solaris */
164 165 166 167
#define SRV_UNIX_O_DSYNC     2
#define SRV_UNIX_LITTLESYNC  3
#define SRV_UNIX_NOSYNC      4

unknown's avatar
unknown committed
168 169 170 171
/* Alternatives for file i/o in Windows */
#define SRV_WIN_IO_NORMAL		1
#define SRV_WIN_IO_UNBUFFERED		2	/* This is the default */

172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
/* Alternatives for srv_force_recovery. Non-zero values are intended
to help the user get a damaged database up so that he can dump intact
tables and rows with SELECT INTO OUTFILE. The database must not otherwise
be used with these options! A bigger number below means that all precautions
of lower numbers are included. */

#define SRV_FORCE_IGNORE_CORRUPT 1	/* let the server run even if it
					detects a corrupt page */
#define SRV_FORCE_NO_BACKGROUND	2 	/* prevent the main thread from
					running: if a crash would occur
					in purge, this prevents it */
#define SRV_FORCE_NO_TRX_UNDO	3	/* do not run trx rollback after
					recovery */
#define SRV_FORCE_NO_IBUF_MERGE	4	/* prevent also ibuf operations:
					if they would cause a crash, better
					not do them */
unknown's avatar
Merge  
unknown committed
188 189 190 191 192
#define	SRV_FORCE_NO_UNDO_LOG_SCAN 5	/* do not look at undo logs when
					starting the database: InnoDB will
					treat even incomplete transactions
					as committed */
#define SRV_FORCE_NO_LOG_REDO	6	/* do not do the log roll-forward
193 194
					in connection with recovery */
					
195 196 197 198 199 200 201 202
/*************************************************************************
Boots Innobase server. */

ulint
srv_boot(void);
/*==========*/
			/* out: DB_SUCCESS or error code */
/*************************************************************************
unknown's avatar
unknown committed
203 204 205 206 207 208 209 210 211 212 213 214 215
Initializes the server. */

void
srv_init(void);
/*==========*/
/*************************************************************************
Initializes the synchronization primitives, memory system, and the thread
local storage. */

void
srv_general_init(void);
/*==================*/
/*************************************************************************
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
Gets the number of threads in the system. */

ulint
srv_get_n_threads(void);
/*===================*/
/*************************************************************************
Returns the calling thread type. */

ulint
srv_get_thread_type(void);
/*=====================*/
			/* out: SRV_COM, ... */
/*************************************************************************
Releases threads of the type given from suspension in the thread table.
NOTE! The server mutex has to be reserved by the caller! */

ulint
srv_release_threads(
/*================*/
			/* out: number of threads released: this may be
			< n if not enough threads were suspended at the
			moment */
	ulint	type,	/* in: thread type */
	ulint	n);	/* in: number of threads to release */
/*************************************************************************
The master thread controlling the server. */

243 244 245
#ifndef __WIN__
void*
#else
246
ulint
247
#endif
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
srv_master_thread(
/*==============*/
			/* out: a dummy parameter */
	void*	arg);	/* in: a dummy parameter required by
			os_thread_create */
/*************************************************************************
Reads a keyword and a value from a file. */

ulint
srv_read_init_val(
/*==============*/
				/* out: DB_SUCCESS or error code */
	FILE*	initfile,	/* in: file pointer */
	char*	keyword,	/* in: keyword before value(s), or NULL if
				no keyword read */
	char*	str_buf,	/* in/out: buffer for a string value to read,
				buffer size must be 10000 bytes, if NULL
				then not read */
	ulint*	num_val,	/* out:	numerical value to read, if NULL
				then not read */
	ibool	print_not_err);	/* in: if TRUE, then we will not print
				error messages to console */
/***********************************************************************
Tells the Innobase server that there has been activity in the database
and wakes up the master thread if it is suspended (not sleeping). Used
in the MySQL interface. Note that there is a small chance that the master
thread stays suspended (we do not protect our operation with the kernel
mutex, for performace reasons). */

void
srv_active_wake_master_thread(void);
/*===============================*/
unknown's avatar
unknown committed
280 281 282 283 284 285
/***********************************************************************
Wakes up the master thread if it is suspended or being suspended. */

void
srv_wake_master_thread(void);
/*========================*/
unknown's avatar
Merge  
unknown committed
286 287 288 289 290 291 292 293 294 295 296 297 298 299
/*************************************************************************
Puts an OS thread to wait if there are too many concurrent threads
(>= srv_thread_concurrency) inside InnoDB. The threads wait in a FIFO queue. */

void
srv_conc_enter_innodb(
/*==================*/
	trx_t*	trx);	/* in: transaction object associated with the
			thread */
/*************************************************************************
This lets a thread enter InnoDB regardless of the number of threads inside
InnoDB. This must be called when a thread ends a lock wait. */

void
unknown's avatar
unknown committed
300 301 302 303
srv_conc_force_enter_innodb(
/*========================*/
	trx_t*	trx);	/* in: transaction object associated with the
			thread */
unknown's avatar
Merge  
unknown committed
304
/*************************************************************************
unknown's avatar
unknown committed
305 306
This must be called when a thread exits InnoDB in a lock wait or at the
end of an SQL statement. */
unknown's avatar
Merge  
unknown committed
307 308

void
unknown's avatar
unknown committed
309 310 311 312 313 314 315 316 317 318 319 320
srv_conc_force_exit_innodb(
/*=======================*/
	trx_t*	trx);	/* in: transaction object associated with the
			thread */
/*************************************************************************
This must be called when a thread exits InnoDB. */

void
srv_conc_exit_innodb(
/*=================*/
	trx_t*	trx);	/* in: transaction object associated with the
			thread */
321
/*******************************************************************
unknown's avatar
unknown committed
322 323 324 325 326
Puts a MySQL OS thread to wait for a lock to be released. If an error
occurs during the wait trx->error_state associated with thr is
!= DB_SUCCESS when we return. DB_LOCK_WAIT_TIMEOUT and DB_DEADLOCK
are possible errors. DB_DEADLOCK is returned if selective deadlock
resolution chose this transaction as a victim. */
327

unknown's avatar
unknown committed
328
void
329 330
srv_suspend_mysql_thread(
/*=====================*/
unknown's avatar
unknown committed
331 332
	que_thr_t*	thr);	/* in: query thread associated with the MySQL
				OS thread */
333 334 335 336 337 338 339 340 341 342
/************************************************************************
Releases a MySQL OS thread waiting for a lock to be released, if the
thread is already suspended. */

void
srv_release_mysql_thread_if_suspended(
/*==================================*/
	que_thr_t*	thr);	/* in: query thread associated with the
				MySQL OS thread  */
/*************************************************************************
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
A thread which wakes up threads whose lock wait may have lasted too long.
This also prints the info output by various InnoDB monitors. */

#ifndef __WIN__
void*
#else
ulint
#endif
srv_lock_timeout_and_monitor_thread(
/*================================*/
			/* out: a dummy parameter */
	void*	arg);	/* in: a dummy parameter required by
			os_thread_create */
/*************************************************************************
A thread which prints warnings about semaphore waits which have lasted
too long. These can be used to track bugs which cause hangs. */
359

360 361 362
#ifndef __WIN__
void*
#else
363
ulint
364
#endif
365 366
srv_error_monitor_thread(
/*=====================*/
367 368 369
			/* out: a dummy parameter */
	void*	arg);	/* in: a dummy parameter required by
			os_thread_create */
unknown's avatar
unknown committed
370 371 372 373 374 375 376 377
/**********************************************************************
Sprintfs to a buffer the output of the InnoDB Monitor. */

void
srv_sprintf_innodb_monitor(
/*=======================*/
	char*	buf,	/* in/out: buffer which must be at least 4 kB */
	ulint	len);	/* in: length of the buffer */
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419


/* Types for the threads existing in the system. Threads of types 4 - 9
are called utility threads. Note that utility threads are mainly disk
bound, except that version threads 6 - 7 may also be CPU bound, if
cleaning versions from the buffer pool. */

#define	SRV_COM		1	/* threads serving communication and queries */
#define	SRV_CONSOLE	2	/* thread serving console */
#define	SRV_WORKER	3	/* threads serving parallelized queries and
				queries released from lock wait */
#define SRV_BUFFER	4	/* thread flushing dirty buffer blocks,
				not currently in use */
#define SRV_RECOVERY	5	/* threads finishing a recovery,
				not currently in use */
#define SRV_INSERT	6	/* thread flushing the insert buffer to disk,
				not currently in use */
#define SRV_MASTER	7      	/* the master thread, (whose type number must
				be biggest) */

/* Thread slot in the thread table */
typedef struct srv_slot_struct	srv_slot_t;

/* Thread table is an array of slots */
typedef srv_slot_t	srv_table_t;

/* The server system struct */
struct srv_sys_struct{
	os_event_t	operational;	/* created threads must wait for the
					server to become operational by
					waiting for this event */
	com_endpoint_t*	endpoint;	/* the communication endpoint of the
					server */

	srv_table_t*	threads;	/* server thread table */
	UT_LIST_BASE_NODE_T(que_thr_t)
			tasks;		/* task queue */
};

extern ulint	srv_n_threads_active[];

#endif
unknown's avatar
unknown committed
420