~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/sync0sync.h

  • Committer: Lee Bieber
  • Date: 2010-11-07 19:34:48 UTC
  • mfrom: (1910.1.2 build)
  • Revision ID: kalebral@gmail.com-20101107193448-64kdu912qej354sh
Merge Stewart - including adapting and expanding the "differences from mysql" page from the wiki.
Merge Stewart - fix bug 668143: drizzleslap with --commit runs second iteration data load in a transaction

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (C) 1995, 2010, Innobase Oy. All Rights Reserved.
4
 
Copyright (C) 2008, Google Inc.
 
3
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
 
4
Copyright (c) 2008, Google Inc.
5
5
 
6
6
Portions of this file contain modifications contributed and copyrighted by
7
7
Google, Inc. Those modifications are gratefully acknowledged and are described
52
52
typedef byte lock_word_t;
53
53
#endif
54
54
 
55
 
#if defined UNIV_PFS_MUTEX || defined UNIV_PFS_RWLOCK
56
 
/* There are mutexes/rwlocks that we want to exclude from
57
 
instrumentation even if their corresponding performance schema
58
 
define is set. And this PFS_NOT_INSTRUMENTED is used
59
 
as the key value to dentify those objects that would
60
 
be excluded from instrumentation. */
61
 
# define PFS_NOT_INSTRUMENTED           ULINT32_UNDEFINED
62
 
 
63
 
# define PFS_IS_INSTRUMENTED(key)       ((key) != PFS_NOT_INSTRUMENTED)
64
 
 
65
 
/* By default, buffer mutexes and rwlocks will be excluded from
66
 
instrumentation due to their large number of instances. */
67
 
# define PFS_SKIP_BUFFER_MUTEX_RWLOCK
68
 
 
69
 
#endif /* UNIV_PFS_MUTEX || UNIV_PFS_RWLOCK */
70
 
 
71
 
#ifdef UNIV_PFS_MUTEX
72
 
/* Key defines to register InnoDB mutexes with performance schema */
73
 
extern mysql_pfs_key_t  autoinc_mutex_key;
74
 
extern mysql_pfs_key_t  btr_search_enabled_mutex_key;
75
 
extern mysql_pfs_key_t  buffer_block_mutex_key;
76
 
extern mysql_pfs_key_t  buf_pool_mutex_key;
77
 
extern mysql_pfs_key_t  buf_pool_zip_mutex_key;
78
 
extern mysql_pfs_key_t  cache_last_read_mutex_key;
79
 
extern mysql_pfs_key_t  dict_foreign_err_mutex_key;
80
 
extern mysql_pfs_key_t  dict_sys_mutex_key;
81
 
extern mysql_pfs_key_t  file_format_max_mutex_key;
82
 
extern mysql_pfs_key_t  fil_system_mutex_key;
83
 
extern mysql_pfs_key_t  flush_list_mutex_key;
84
 
extern mysql_pfs_key_t  hash_table_mutex_key;
85
 
extern mysql_pfs_key_t  ibuf_bitmap_mutex_key;
86
 
extern mysql_pfs_key_t  ibuf_mutex_key;
87
 
extern mysql_pfs_key_t  ibuf_pessimistic_insert_mutex_key;
88
 
extern mysql_pfs_key_t  log_sys_mutex_key;
89
 
extern mysql_pfs_key_t  log_flush_order_mutex_key;
90
 
extern mysql_pfs_key_t  kernel_mutex_key;
91
 
extern mysql_pfs_key_t  commit_id_mutex_key;
92
 
# ifdef UNIV_MEM_DEBUG
93
 
extern mysql_pfs_key_t  mem_hash_mutex_key;
94
 
# endif /* UNIV_MEM_DEBUG */
95
 
extern mysql_pfs_key_t  mem_pool_mutex_key;
96
 
extern mysql_pfs_key_t  mutex_list_mutex_key;
97
 
extern mysql_pfs_key_t  purge_sys_mutex_key;
98
 
extern mysql_pfs_key_t  recv_sys_mutex_key;
99
 
extern mysql_pfs_key_t  rseg_mutex_key;
100
 
# ifdef UNIV_SYNC_DEBUG
101
 
extern mysql_pfs_key_t  rw_lock_debug_mutex_key;
102
 
# endif /* UNIV_SYNC_DEBUG */
103
 
extern mysql_pfs_key_t  rw_lock_list_mutex_key;
104
 
extern mysql_pfs_key_t  rw_lock_mutex_key;
105
 
extern mysql_pfs_key_t  srv_dict_tmpfile_mutex_key;
106
 
extern mysql_pfs_key_t  srv_innodb_monitor_mutex_key;
107
 
extern mysql_pfs_key_t  srv_misc_tmpfile_mutex_key;
108
 
extern mysql_pfs_key_t  srv_monitor_file_mutex_key;
109
 
extern mysql_pfs_key_t  syn_arr_mutex_key;
110
 
# ifdef UNIV_SYNC_DEBUG
111
 
extern mysql_pfs_key_t  sync_thread_mutex_key;
112
 
# endif /* UNIV_SYNC_DEBUG */
113
 
extern mysql_pfs_key_t  trx_doublewrite_mutex_key;
114
 
extern mysql_pfs_key_t  thr_local_mutex_key;
115
 
extern mysql_pfs_key_t  trx_undo_mutex_key;
116
 
#endif /* UNIV_PFS_MUTEX */
117
 
 
118
55
/******************************************************************//**
119
56
Initializes the synchronization data structures. */
120
57
UNIV_INTERN
127
64
void
128
65
sync_close(void);
129
66
/*===========*/
130
 
 
131
 
#undef mutex_free                       /* Fix for MacOS X */
132
 
 
133
 
#ifdef UNIV_PFS_MUTEX
134
 
/**********************************************************************
135
 
Following mutex APIs would be performance schema instrumented
136
 
if "UNIV_PFS_MUTEX" is defined:
137
 
 
138
 
mutex_create
139
 
mutex_enter
140
 
mutex_exit
141
 
mutex_enter_nowait
142
 
mutex_free
143
 
 
144
 
These mutex APIs will point to corresponding wrapper functions that contain
145
 
the performance schema instrumentation if "UNIV_PFS_MUTEX" is defined.
146
 
The instrumented wrapper functions have the prefix of "innodb_".
147
 
 
148
 
NOTE! The following macro should be used in mutex operation, not the
149
 
corresponding function. */
150
 
 
151
67
/******************************************************************//**
152
68
Creates, or rather, initializes a mutex object to a specified memory
153
69
location (which must be appropriately aligned). The mutex is initialized
154
70
in the reset state. Explicit freeing of the mutex with mutex_free is
155
71
necessary only if the memory block containing it is freed. */
156
 
# ifdef UNIV_DEBUG
157
 
#  ifdef UNIV_SYNC_DEBUG
158
 
#   define mutex_create(K, M, level)                            \
159
 
        pfs_mutex_create_func((K), (M), #M, (level), __FILE__, __LINE__)
160
 
#  else
161
 
#   define mutex_create(K, M, level)                            \
162
 
        pfs_mutex_create_func((K), (M), #M, __FILE__, __LINE__)
163
 
#  endif/* UNIV_SYNC_DEBUG */
 
72
 
 
73
#ifdef UNIV_DEBUG
 
74
# ifdef UNIV_SYNC_DEBUG
 
75
#  define mutex_create(M, level)                                        \
 
76
        mutex_create_func((M), #M, (level), __FILE__, __LINE__)
164
77
# else
165
 
#  define mutex_create(K, M, level)                             \
166
 
        pfs_mutex_create_func((K), (M), __FILE__, __LINE__)
167
 
# endif /* UNIV_DEBUG */
168
 
 
169
 
# define mutex_enter(M)                                         \
170
 
        pfs_mutex_enter_func((M), __FILE__, __LINE__)
171
 
 
172
 
# define mutex_enter_nowait(M)                                  \
173
 
        pfs_mutex_enter_nowait_func((M), __FILE__, __LINE__)
174
 
 
175
 
# define mutex_exit(M)  pfs_mutex_exit_func(M)
176
 
 
177
 
# define mutex_free(M)  pfs_mutex_free_func(M)
178
 
 
179
 
#else   /* UNIV_PFS_MUTEX */
180
 
 
181
 
/* If "UNIV_PFS_MUTEX" is not defined, the mutex APIs point to
182
 
original non-instrumented functions */
183
 
# ifdef UNIV_DEBUG
184
 
#  ifdef UNIV_SYNC_DEBUG
185
 
#   define mutex_create(K, M, level)                    \
186
 
        mutex_create_func((M), #M, (level), __FILE__, __LINE__)
187
 
#  else /* UNIV_SYNC_DEBUG */
188
 
#   define mutex_create(K, M, level)                            \
 
78
#  define mutex_create(M, level)                                        \
189
79
        mutex_create_func((M), #M, __FILE__, __LINE__)
190
 
#  endif /* UNIV_SYNC_DEBUG */
191
 
# else /* UNIV_DEBUG */
192
 
#  define mutex_create(K, M, level)                             \
 
80
# endif
 
81
#else
 
82
# define mutex_create(M, level)                                 \
193
83
        mutex_create_func((M), __FILE__, __LINE__)
194
 
# endif /* UNIV_DEBUG */
195
 
 
196
 
# define mutex_enter(M) mutex_enter_func((M), __FILE__, __LINE__)
197
 
 
198
 
# define mutex_enter_nowait(M)  \
199
 
        mutex_enter_nowait_func((M), __FILE__, __LINE__)
200
 
 
201
 
# define mutex_exit(M)  mutex_exit_func(M)
202
 
 
203
 
# define mutex_free(M)  mutex_free_func(M)
204
 
 
205
 
#endif  /* UNIV_PFS_MUTEX */
 
84
#endif
206
85
 
207
86
/******************************************************************//**
208
87
Creates, or rather, initializes a mutex object in a specified memory
223
102
        const char*     cfile_name,     /*!< in: file name where created */
224
103
        ulint           cline);         /*!< in: file line where created */
225
104
 
 
105
#undef mutex_free                       /* Fix for MacOS X */
 
106
 
226
107
/******************************************************************//**
227
 
NOTE! Use the corresponding macro mutex_free(), not directly this function!
228
108
Calling this function is obligatory only if the memory buffer containing
229
109
the mutex is freed. Removes a mutex object from the mutex list. The mutex
230
110
is checked to be in the reset state. */
231
111
UNIV_INTERN
232
112
void
233
 
mutex_free_func(
234
 
/*============*/
 
113
mutex_free(
 
114
/*=======*/
235
115
        mutex_t*        mutex); /*!< in: mutex */
236
116
/**************************************************************//**
237
117
NOTE! The following macro should be used in mutex locking, not the
238
118
corresponding function. */
239
119
 
 
120
#define mutex_enter(M)    mutex_enter_func((M), __FILE__, __LINE__)
 
121
/**************************************************************//**
 
122
NOTE! The following macro should be used in mutex locking, not the
 
123
corresponding function. */
 
124
 
240
125
/* NOTE! currently same as mutex_enter! */
241
126
 
242
127
#define mutex_enter_fast(M)     mutex_enter_func((M), __FILE__, __LINE__)
252
137
        mutex_t*        mutex,          /*!< in: pointer to mutex */
253
138
        const char*     file_name,      /*!< in: file name where locked */
254
139
        ulint           line);          /*!< in: line where locked */
 
140
/**************************************************************//**
 
141
NOTE! The following macro should be used in mutex locking, not the
 
142
corresponding function. */
 
143
 
 
144
#define mutex_enter_nowait(M)   \
 
145
        mutex_enter_nowait_func((M), __FILE__, __LINE__)
255
146
/********************************************************************//**
256
147
NOTE! Use the corresponding macro in the header file, not this function
257
148
directly. Tries to lock the mutex for the current thread. If the lock is not
266
157
                                        requested */
267
158
        ulint           line);          /*!< in: line where requested */
268
159
/******************************************************************//**
269
 
NOTE! Use the corresponding macro mutex_exit(), not directly this function!
270
 
Unlocks a mutex owned by the current thread. */
271
 
UNIV_INLINE
272
 
void
273
 
mutex_exit_func(
274
 
/*============*/
275
 
        mutex_t*        mutex); /*!< in: pointer to mutex */
276
 
 
277
 
 
278
 
#ifdef UNIV_PFS_MUTEX
279
 
/******************************************************************//**
280
 
NOTE! Please use the corresponding macro mutex_create(), not directly
281
 
this function!
282
 
A wrapper function for mutex_create_func(), registers the mutex
283
 
with peformance schema if "UNIV_PFS_MUTEX" is defined when
284
 
creating the mutex */
285
 
UNIV_INLINE
286
 
void
287
 
pfs_mutex_create_func(
288
 
/*==================*/
289
 
        PSI_mutex_key   key,            /*!< in: Performance Schema key */
290
 
        mutex_t*        mutex,          /*!< in: pointer to memory */
291
 
# ifdef UNIV_DEBUG
292
 
        const char*     cmutex_name,    /*!< in: mutex name */
293
 
#  ifdef UNIV_SYNC_DEBUG
294
 
        ulint           level,          /*!< in: level */
295
 
#  endif /* UNIV_SYNC_DEBUG */
296
 
# endif /* UNIV_DEBUG */
297
 
        const char*     cfile_name,     /*!< in: file name where created */
298
 
        ulint           cline);         /*!< in: file line where created */
299
 
/******************************************************************//**
300
 
NOTE! Please use the corresponding macro mutex_enter(), not directly
301
 
this function!
302
 
This is a performance schema instrumented wrapper function for
303
 
mutex_enter_func(). */
304
 
UNIV_INLINE
305
 
void
306
 
pfs_mutex_enter_func(
307
 
/*=================*/
308
 
        mutex_t*        mutex,          /*!< in: pointer to mutex */
309
 
        const char*     file_name,      /*!< in: file name where locked */
310
 
        ulint           line);          /*!< in: line where locked */
311
 
/********************************************************************//**
312
 
NOTE! Please use the corresponding macro mutex_enter_nowait(), not directly
313
 
this function!
314
 
This is a performance schema instrumented wrapper function for
315
 
mutex_enter_nowait_func.
316
 
@return 0 if succeed, 1 if not */
317
 
UNIV_INLINE
318
 
ulint
319
 
pfs_mutex_enter_nowait_func(
320
 
/*========================*/
321
 
        mutex_t*        mutex,          /*!< in: pointer to mutex */
322
 
        const char*     file_name,      /*!< in: file name where mutex
323
 
                                        requested */
324
 
        ulint           line);          /*!< in: line where requested */
325
 
/******************************************************************//**
326
 
NOTE! Please use the corresponding macro mutex_exit(), not directly
327
 
this function!
328
 
A wrap function of mutex_exit_func() with peformance schema instrumentation.
329
 
Unlocks a mutex owned by the current thread. */
330
 
UNIV_INLINE
331
 
void
332
 
pfs_mutex_exit_func(
333
 
/*================*/
334
 
        mutex_t*        mutex); /*!< in: pointer to mutex */
335
 
 
336
 
/******************************************************************//**
337
 
NOTE! Please use the corresponding macro mutex_free(), not directly
338
 
this function!
339
 
Wrapper function for mutex_free_func(). Also destroys the performance
340
 
schema probes when freeing the mutex */
341
 
UNIV_INLINE
342
 
void
343
 
pfs_mutex_free_func(
344
 
/*================*/
345
 
        mutex_t*        mutex); /*!< in: mutex */
346
 
 
347
 
#endif /* UNIV_PFS_MUTEX */
348
 
 
 
160
Unlocks a mutex owned by the current thread. */
 
161
UNIV_INLINE
 
162
void
 
163
mutex_exit(
 
164
/*=======*/
 
165
        mutex_t*        mutex); /*!< in: pointer to mutex */
349
166
#ifdef UNIV_SYNC_DEBUG
350
167
/******************************************************************//**
351
168
Returns TRUE if no mutex or rw-lock is currently locked.
389
206
ibool
390
207
mutex_own(
391
208
/*======*/
392
 
        const mutex_t*  mutex)  /*!< in: mutex */
393
 
        __attribute__((warn_unused_result));
 
209
        const mutex_t*  mutex); /*!< in: mutex */
394
210
#endif /* UNIV_DEBUG */
395
211
#ifdef UNIV_SYNC_DEBUG
396
212
/******************************************************************//**
422
238
sync_thread_levels_empty(void);
423
239
/*==========================*/
424
240
/******************************************************************//**
425
 
Checks if the level array for the current thread contains a
426
 
mutex or rw-latch at the specified level.
427
 
@return a matching latch, or NULL if not found */
428
 
UNIV_INTERN
429
 
void*
430
 
sync_thread_levels_contains(
431
 
/*========================*/
432
 
        ulint   level);                 /*!< in: latching order level
433
 
                                        (SYNC_DICT, ...)*/
434
 
/******************************************************************//**
435
 
Checks if the level array for the current thread is empty.
436
 
@return a latch, or NULL if empty except the exceptions specified below */
437
 
UNIV_INTERN
438
 
void*
439
 
sync_thread_levels_nonempty_gen(
440
 
/*============================*/
 
241
Checks that the level array for the current thread is empty.
 
242
@return TRUE if empty except the exceptions specified below */
 
243
UNIV_INTERN
 
244
ibool
 
245
sync_thread_levels_empty_gen(
 
246
/*=========================*/
441
247
        ibool   dict_mutex_allowed);    /*!< in: TRUE if dictionary mutex is
442
248
                                        allowed to be owned by the thread,
443
249
                                        also purge_is_running mutex is
444
250
                                        allowed */
445
 
#define sync_thread_levels_empty_gen(d) (!sync_thread_levels_nonempty_gen(d))
446
251
/******************************************************************//**
447
252
Gets the debug information for a reserved mutex. */
448
253
UNIV_INTERN
621
426
#define SYNC_FILE_FORMAT_TAG    1200    /* Used to serialize access to the
622
427
                                        file format tag */
623
428
#define SYNC_DICT_OPERATION     1001    /* table create, drop, etc. reserve
624
 
                                        this in X-mode; implicit or backround
 
429
                                        this in X-mode, implicit or backround
625
430
                                        operations purge, rollback, foreign
626
431
                                        key checks reserve this in S-mode */
627
432
#define SYNC_DICT               1000
661
466
#define SYNC_TRX_LOCK_HEAP      298
662
467
#define SYNC_TRX_SYS_HEADER     290
663
468
#define SYNC_LOG                170
664
 
#define SYNC_LOG_FLUSH_ORDER    147
665
469
#define SYNC_RECV               168
666
470
#define SYNC_WORK_QUEUE         162
667
471
#define SYNC_SEARCH_SYS_CONF    161     /* for assigning btr_search_enabled */
671
475
                                        SYNC_SEARCH_SYS, as memory allocation
672
476
                                        can call routines there! Otherwise
673
477
                                        the level is SYNC_MEM_HASH. */
674
 
#define SYNC_COMMIT_ID_LOCK     159     
675
 
#define SYNC_BUF_POOL           150     /* Buffer pool mutex */
676
 
#define SYNC_BUF_BLOCK          146     /* Block mutex */
677
 
#define SYNC_BUF_FLUSH_LIST     145     /* Buffer flush list mutex */
 
478
#define SYNC_BUF_POOL           150
 
479
#define SYNC_BUF_BLOCK          149
678
480
#define SYNC_DOUBLEWRITE        140
679
481
#define SYNC_ANY_LATCH          135
680
482
#define SYNC_THR_LOCAL          133
736
538
        const char*     cmutex_name;    /*!< mutex name */
737
539
        ulint           mutex_type;     /*!< 0=usual mutex, 1=rw_lock mutex */
738
540
#endif /* UNIV_DEBUG */
739
 
#ifdef UNIV_PFS_MUTEX
740
 
        struct PSI_mutex* pfs_psi;      /*!< The performance schema
741
 
                                        instrumentation hook */
742
 
#endif
743
541
};
744
542
 
745
543
/** The global array of wait cells for implementation of the databases own