~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to storage/myisam/mi_extra.c

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#endif
20
20
 
21
21
static void mi_extra_keyflag(MI_INFO *info, enum ha_extra_function function);
22
 
 
 
22
static int log_flushed_write_cache_physical(IO_CACHE *cache_to_table,
 
23
                                            const uchar *buffert,
 
24
                                            uint length, my_off_t offset);
23
25
 
24
26
/*
25
27
  Set options and buffers to optimize table handling
144
146
                         HA_STATE_WRITE_AT_END |
145
147
                         HA_STATE_EXTEND_BLOCK);
146
148
      }
 
149
#ifdef HAVE_MYISAM_PHYSICAL_LOGGING
 
150
    if (!share->temporary)
 
151
    {
 
152
      /*
 
153
        This is a post_write: physical_logging_state has to be checked after
 
154
        doing the table write (see mi_log_start_physical()).
 
155
        We set it now as physical logging may be requested later when the
 
156
        cache has started being used.
 
157
      */
 
158
      info->rec_cache.post_write= log_flushed_write_cache_physical;
 
159
      info->rec_cache.arg= share;
 
160
    }
 
161
#endif
147
162
    break;
148
163
  case HA_EXTRA_PREPARE_FOR_UPDATE:
149
164
    if (info->s->data_file_type != DYNAMIC_RECORD)
216
231
    info->lock_wait=0;
217
232
    break;
218
233
  case HA_EXTRA_NO_WAIT_LOCK:
219
 
    info->lock_wait=MY_DONT_WAIT;
 
234
    info->lock_wait= MY_SHORT_WAIT;
220
235
    break;
221
236
  case HA_EXTRA_NO_KEYS:
222
237
    if (info->lock_type == F_UNLCK)
248
263
        }
249
264
      }
250
265
      share->state.state= *info->state;
251
 
      error=mi_state_info_write(share->kfile,&share->state,1 | 2);
 
266
      error= mi_state_info_write(share, share->kfile, &share->state, 1 | 2);
252
267
    }
253
268
    break;
254
269
  case HA_EXTRA_FORCE_REOPEN:
256
271
    share->last_version= 0L;                    /* Impossible version */
257
272
    pthread_mutex_unlock(&THR_LOCK_myisam);
258
273
    break;
259
 
  case HA_EXTRA_PREPARE_FOR_DELETE:
 
274
  case HA_EXTRA_PREPARE_FOR_RENAME:
 
275
  case HA_EXTRA_PREPARE_FOR_DROP:
260
276
    pthread_mutex_lock(&THR_LOCK_myisam);
261
277
    share->last_version= 0L;                    /* Impossible version */
262
278
#ifdef __WIN__REMOVE_OBSOLETE_WORKAROUND
263
279
    /* Close the isam and data files as Win32 can't drop an open table */
264
280
    pthread_mutex_lock(&share->intern_lock);
265
281
    if (flush_key_blocks(share->key_cache, share->kfile,
266
 
                         (function == HA_EXTRA_FORCE_REOPEN ?
267
 
                          FLUSH_RELEASE : FLUSH_IGNORE_CHANGED)))
 
282
                         (function == HA_EXTRA_PREPARE_FOR_DROP ?
 
283
                          FLUSH_IGNORE_CHANGED : FLUSH_RELEASE)))
268
284
    {
269
285
      error=my_errno;
270
286
      share->changed=1;
386
402
  {
387
403
    char tmp[1];
388
404
    tmp[0]=function;
389
 
    myisam_log_command(MI_LOG_EXTRA,info,(uchar*) tmp,1,error);
 
405
    myisam_log_command_logical(MI_LOG_EXTRA, info, (uchar*)tmp, 1, error);
390
406
  }
391
407
  DBUG_RETURN(error);
392
408
} /* mi_extra */
436
452
  */
437
453
  if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
438
454
  {
 
455
    /*
 
456
      If there is a WRITE_CACHE here and we don't hold a write-lock or
 
457
      intern_lock on the table, then mi_log_stop_physical() may be running
 
458
      now in another thread and may be flushing the write cache now (and two
 
459
      concurrent end_io_cache() will cause problems). For example when the
 
460
      SQL layer unlocks tables and then calls ha_myisam::reset() we must not
 
461
      come here. Temp tables are not concerned.
 
462
    */
 
463
    if (!share->temporary && (info->opt_flag & WRITE_CACHE_USED) &&
 
464
        (info->lock.type <= TL_READ_NO_INSERT))
 
465
    {
 
466
      safe_mutex_assert_owner(&share->intern_lock);
 
467
    }
439
468
    info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
440
469
    error= end_io_cache(&info->rec_cache);
441
470
  }
455
484
                 HA_STATE_PREV_FOUND);
456
485
  DBUG_RETURN(error);
457
486
}
 
487
 
 
488
 
 
489
/**
 
490
  Logs when the WRITE_CACHE is flushed to the data file, to the physical
 
491
  log.
 
492
 
 
493
  @param  cache_for_table  pointer to the table's WRITE_CACHE IO_CACHE
 
494
  @param  buffert          argument to the pwrite
 
495
  @param  length           length of buffer
 
496
  @param  filepos          offset in file where buffer was written
 
497
 
 
498
  @return Operation status, always 0
 
499
    @retval 0      ok. Yes, even if log write fails we return ok, don't want
 
500
                   to make the table writer believe its table is now
 
501
                   corrupted.
 
502
*/
 
503
 
 
504
static int log_flushed_write_cache_physical(IO_CACHE *cache_for_table,
 
505
                                            const uchar *buffert,
 
506
                                            uint length, my_off_t filepos)
 
507
{
 
508
  MYISAM_SHARE *share= (MYISAM_SHARE *)(cache_for_table->arg);
 
509
  DBUG_ENTER("log_flushed_write_cache_physical");
 
510
  if (unlikely(mi_get_physical_logging_state(share)))
 
511
    myisam_log_pwrite_physical(MI_LOG_WRITE_BYTES_MYD, share, buffert,
 
512
                               length, filepos);
 
513
  DBUG_RETURN(0);
 
514
}