226
226
/****************************************************************************
227
The following functions are called by thr_lock() in threaded applications
228
****************************************************************************/
231
Create a copy of the current status for the table
235
param Pointer to Myisam handler
236
concurrent_insert Set to 1 if we are going to do concurrent inserts
237
(THR_WRITE_CONCURRENT_INSERT was used)
240
void mi_get_status(void* param, int concurrent_insert)
242
MI_INFO *info=(MI_INFO*) param;
244
info->save_state=info->s->state.state;
245
info->state= &info->save_state;
246
info->append_insert_at_end= concurrent_insert;
251
void mi_update_status(void* param)
253
MI_INFO *info=(MI_INFO*) param;
255
Because someone may have closed the table we point at, we only
256
update the state if its our own state. This isn't a problem as
257
we are always pointing at our own lock or at a read lock.
258
(This is enforced by thr_multi_lock.c)
260
if (info->state == &info->save_state)
262
info->s->state.state= *info->state;
263
info->state= &info->s->state.state;
265
info->append_insert_at_end= 0;
268
We have to flush the write cache here as other threads may start
269
reading the table before mi_lock_database() is called
271
if (info->opt_flag & WRITE_CACHE_USED)
273
if (end_io_cache(&info->rec_cache))
275
mi_print_error(info->s, HA_ERR_CRASHED);
276
mi_mark_crashed(info);
278
info->opt_flag&= ~WRITE_CACHE_USED;
283
void mi_restore_status(void *param)
285
MI_INFO *info= (MI_INFO*) param;
286
info->state= &info->s->state.state;
287
info->append_insert_at_end= 0;
291
void mi_copy_status(void* to,void *from)
293
((MI_INFO*) to)->state= &((MI_INFO*) from)->save_state;
298
Check if should allow concurrent inserts
301
Allow concurrent inserts if we don't have a hole in the table or
302
if there is no active write lock and there is active read locks and
303
myisam_concurrent_insert == 2. In this last case the new
304
row('s) are inserted at end of file instead of filling up the hole.
306
The last case is to allow one to inserts into a heavily read-used table
307
even if there is holes.
310
If there is a an rtree indexes in the table, concurrent inserts are
311
disabled in mi_open()
314
0 ok to use concurrent inserts
318
bool mi_check_status(void *param)
320
MI_INFO *info=(MI_INFO*) param;
322
The test for w_locks == 1 is here because this thread has already done an
323
external lock (in other words: w_locks == 1 means no other threads has
326
return (bool) !(info->s->state.dellink == HA_OFFSET_ERROR ||
327
(myisam_concurrent_insert == 2 && info->s->r_locks &&
328
info->s->w_locks == 1));
332
/****************************************************************************
333
227
** functions to read / write the state
334
228
****************************************************************************/