~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/mi_locking.cc

  • Committer: lbieber
  • Date: 2010-08-04 22:35:53 UTC
  • mfrom: (1685.3.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 1687.
  • Revision ID: lbieber@orisndriz03-20100804223553-9q2sz4yc1fvkpup4
Merge Brian - custom lock encapsulation, and myisam lock removel code

Show diffs side-by-side

added added

removed removed

Lines of Context:
224
224
 
225
225
 
226
226
/****************************************************************************
227
 
  The following functions are called by thr_lock() in threaded applications
228
 
****************************************************************************/
229
 
 
230
 
/*
231
 
  Create a copy of the current status for the table
232
 
 
233
 
  SYNOPSIS
234
 
    mi_get_status()
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)
238
 
*/
239
 
 
240
 
void mi_get_status(void* param, int concurrent_insert)
241
 
{
242
 
  MI_INFO *info=(MI_INFO*) param;
243
 
 
244
 
  info->save_state=info->s->state.state;
245
 
  info->state= &info->save_state;
246
 
  info->append_insert_at_end= concurrent_insert;
247
 
  return;
248
 
}
249
 
 
250
 
 
251
 
void mi_update_status(void* param)
252
 
{
253
 
  MI_INFO *info=(MI_INFO*) param;
254
 
  /*
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)
259
 
  */
260
 
  if (info->state == &info->save_state)
261
 
  {
262
 
    info->s->state.state= *info->state;
263
 
    info->state= &info->s->state.state;
264
 
  }
265
 
  info->append_insert_at_end= 0;
266
 
 
267
 
  /*
268
 
    We have to flush the write cache here as other threads may start
269
 
    reading the table before mi_lock_database() is called
270
 
  */
271
 
  if (info->opt_flag & WRITE_CACHE_USED)
272
 
  {
273
 
    if (end_io_cache(&info->rec_cache))
274
 
    {
275
 
      mi_print_error(info->s, HA_ERR_CRASHED);
276
 
      mi_mark_crashed(info);
277
 
    }
278
 
    info->opt_flag&= ~WRITE_CACHE_USED;
279
 
  }
280
 
}
281
 
 
282
 
 
283
 
void mi_restore_status(void *param)
284
 
{
285
 
  MI_INFO *info= (MI_INFO*) param;
286
 
  info->state= &info->s->state.state;
287
 
  info->append_insert_at_end= 0;
288
 
}
289
 
 
290
 
 
291
 
void mi_copy_status(void* to,void *from)
292
 
{
293
 
  ((MI_INFO*) to)->state= &((MI_INFO*) from)->save_state;
294
 
}
295
 
 
296
 
 
297
 
/*
298
 
  Check if should allow concurrent inserts
299
 
 
300
 
  IMPLEMENTATION
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.
305
 
 
306
 
    The last case is to allow one to inserts into a heavily read-used table
307
 
    even if there is holes.
308
 
 
309
 
  NOTES
310
 
    If there is a an rtree indexes in the table, concurrent inserts are
311
 
    disabled in mi_open()
312
 
 
313
 
  RETURN
314
 
    0  ok to use concurrent inserts
315
 
    1  not ok
316
 
*/
317
 
 
318
 
bool mi_check_status(void *param)
319
 
{
320
 
  MI_INFO *info=(MI_INFO*) param;
321
 
  /*
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
324
 
    a write lock)
325
 
  */
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));
329
 
}
330
 
 
331
 
 
332
 
/****************************************************************************
333
227
 ** functions to read / write the state
334
228
****************************************************************************/
335
229