12
12
You should have received a copy of the GNU General Public License
13
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
17
locking of isam-tables.
59
61
count= --share->w_locks;
60
62
--share->tot_locks;
61
63
if (info->lock_type == F_WRLCK && !share->w_locks &&
62
!share->delay_key_write && flush_key_blocks(share->getKeyCache(),
64
!share->delay_key_write && flush_key_blocks(share->key_cache,
63
65
share->kfile,FLUSH_KEEP))
66
68
mi_print_error(info->s, HA_ERR_CRASHED);
67
69
mi_mark_crashed(info); /* Mark that table must be checked */
69
71
if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
71
if (info->rec_cache.end_io_cache())
73
if (end_io_cache(&info->rec_cache))
74
76
mi_print_error(info->s, HA_ERR_CRASHED);
75
77
mi_mark_crashed(info);
80
82
if (share->changed && !share->w_locks)
82
85
if ((info->s->mmaped_length != info->s->state.state.data_file_length) &&
83
86
(info->s->nonmmaped_inserts > MAX_NONMAPPED_INSERTS))
88
if (info->s->concurrent_insert)
89
pthread_rwlock_wrlock(&info->s->mmap_lock);
85
90
mi_remap_file(info, info->s->state.state.data_file_length);
86
91
info->s->nonmmaped_inserts= 0;
92
if (info->s->concurrent_insert)
93
pthread_rwlock_unlock(&info->s->mmap_lock);
88
96
share->state.process= share->last_process=share->this_process;
89
97
share->state.unique= info->last_unique= info->this_unique;
90
98
share->state.update_count= info->last_loop= ++info->this_loop;
91
99
if (mi_state_info_write(share->kfile, &share->state, 1))
94
102
share->not_flushed=1;
219
228
/****************************************************************************
229
The following functions are called by thr_lock() in threaded applications
230
****************************************************************************/
233
Create a copy of the current status for the table
237
param Pointer to Myisam handler
238
concurrent_insert Set to 1 if we are going to do concurrent inserts
239
(THR_WRITE_CONCURRENT_INSERT was used)
242
void mi_get_status(void* param, int concurrent_insert)
244
MI_INFO *info=(MI_INFO*) param;
246
info->save_state=info->s->state.state;
247
info->state= &info->save_state;
248
info->append_insert_at_end= concurrent_insert;
253
void mi_update_status(void* param)
255
MI_INFO *info=(MI_INFO*) param;
257
Because someone may have closed the table we point at, we only
258
update the state if its our own state. This isn't a problem as
259
we are always pointing at our own lock or at a read lock.
260
(This is enforced by thr_multi_lock.c)
262
if (info->state == &info->save_state)
264
info->s->state.state= *info->state;
265
info->state= &info->s->state.state;
267
info->append_insert_at_end= 0;
270
We have to flush the write cache here as other threads may start
271
reading the table before mi_lock_database() is called
273
if (info->opt_flag & WRITE_CACHE_USED)
275
if (end_io_cache(&info->rec_cache))
277
mi_print_error(info->s, HA_ERR_CRASHED);
278
mi_mark_crashed(info);
280
info->opt_flag&= ~WRITE_CACHE_USED;
285
void mi_restore_status(void *param)
287
MI_INFO *info= (MI_INFO*) param;
288
info->state= &info->s->state.state;
289
info->append_insert_at_end= 0;
293
void mi_copy_status(void* to,void *from)
295
((MI_INFO*) to)->state= &((MI_INFO*) from)->save_state;
300
Check if should allow concurrent inserts
303
Allow concurrent inserts if we don't have a hole in the table or
304
if there is no active write lock and there is active read locks and
305
myisam_concurrent_insert == 2. In this last case the new
306
row('s) are inserted at end of file instead of filling up the hole.
308
The last case is to allow one to inserts into a heavily read-used table
309
even if there is holes.
312
If there is a an rtree indexes in the table, concurrent inserts are
313
disabled in mi_open()
316
0 ok to use concurrent inserts
320
bool mi_check_status(void *param)
322
MI_INFO *info=(MI_INFO*) param;
324
The test for w_locks == 1 is here because this thread has already done an
325
external lock (in other words: w_locks == 1 means no other threads has
328
return (bool) !(info->s->state.dellink == HA_OFFSET_ERROR ||
329
(myisam_concurrent_insert == 2 && info->s->r_locks &&
330
info->s->w_locks == 1));
334
/****************************************************************************
220
335
** functions to read / write the state
221
336
****************************************************************************/
260
375
if (share->tot_locks == 0)
262
olderror=errno; /* Remember last error */
377
olderror=my_errno; /* Remember last error */
264
379
{ /* Two threads can't be here */
265
380
share->state.process= share->last_process= share->this_process;
266
381
share->state.unique= info->last_unique= info->this_unique;
267
382
share->state.update_count= info->last_loop= ++info->this_loop;
268
383
if ((error=mi_state_info_write(share->kfile, &share->state, 1)))
273
388
else if (operation)
274
389
share->changed= 1; /* Mark keyfile changed */
287
402
share->state.update_count != info->last_loop)
288
403
{ /* Keyfile has changed */
289
404
if (share->state.process != share->this_process)
290
flush_key_blocks(share->getKeyCache(), share->kfile, FLUSH_RELEASE);
405
flush_key_blocks(share->key_cache, share->kfile, FLUSH_RELEASE);
291
406
share->last_process=share->state.process;
292
407
info->last_unique= share->state.unique;
293
408
info->last_loop= share->state.update_count;