~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/mi_check.cc

Remove PLUGIN and MODULES.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
*/
42
42
 
43
43
#include "myisam_priv.h"
44
 
#include <mystrings/m_string.h>
 
44
#include "drizzled/internal/m_string.h"
45
45
#include <stdarg.h>
46
 
#include <mysys/my_getopt.h>
 
46
#include "drizzled/my_getopt.h"
47
47
#ifdef HAVE_SYS_VADVISE_H
48
48
#include <sys/vadvise.h>
49
49
#endif
54
54
#include <sys/mman.h>
55
55
#endif
56
56
#include <drizzled/util/test.h>
 
57
#include "drizzled/my_error.h"
57
58
 
58
59
#include <algorithm>
59
60
 
60
61
using namespace std;
61
62
 
62
63
 
 
64
#define my_off_t2double(A)  ((double) (my_off_t) (A))
 
65
 
63
66
/* Functions defined in this file */
64
67
 
65
68
static int check_k_link(MI_CHECK *param, MI_INFO *info,uint32_t nr);
70
73
static ha_checksum calc_checksum(ha_rows count);
71
74
static int writekeys(MI_SORT_PARAM *sort_param);
72
75
static int sort_one_index(MI_CHECK *param, MI_INFO *info,MI_KEYDEF *keyinfo,
73
 
                          my_off_t pagepos, File new_file);
 
76
                          my_off_t pagepos, int new_file);
74
77
extern "C"
75
78
{
76
79
  int sort_key_read(MI_SORT_PARAM *sort_param,void *key);
1263
1266
  free(mi_get_rec_buff_ptr(info, record));
1264
1267
  return (error);
1265
1268
 err:
1266
 
  mi_check_print_error(param,"got error: %d when reading datafile at record: %s",my_errno, llstr(records,llbuff));
 
1269
  mi_check_print_error(param,"got error: %d when reading datafile at record: %s",errno, llstr(records,llbuff));
1267
1270
 err2:
1268
1271
  free(mi_get_rec_buff_ptr(info, record));
1269
1272
  param->testflag|=T_RETRY_WITHOUT_QUICK;
1404
1407
  int error,got_error;
1405
1408
  ha_rows start_records,new_header_length;
1406
1409
  my_off_t del;
1407
 
  File new_file;
 
1410
  int new_file;
1408
1411
  MYISAM_SHARE *share=info->s;
1409
1412
  char llbuff[22],llbuff2[22];
1410
1413
  SORT_INFO sort_info;
1512
1515
  {
1513
1516
    if (writekeys(&sort_param))
1514
1517
    {
1515
 
      if (my_errno != HA_ERR_FOUND_DUPP_KEY)
 
1518
      if (errno != HA_ERR_FOUND_DUPP_KEY)
1516
1519
        goto err;
1517
1520
      mi_check_print_info(param,"Duplicate key %2d for record at %10s against new record at %10s",
1518
1521
                          info->errkey+1,
1547
1550
  {
1548
1551
    mi_check_print_warning(param,
1549
1552
                           "Can't change size of indexfile, error: %d",
1550
 
                           my_errno);
 
1553
                           errno);
1551
1554
    goto err;
1552
1555
  }
1553
1556
 
1619
1622
  if (got_error)
1620
1623
  {
1621
1624
    if (! param->error_printed)
1622
 
      mi_check_print_error(param,"%d for record at pos %s",my_errno,
 
1625
      mi_check_print_error(param,"%d for record at pos %s",errno,
1623
1626
                  llstr(sort_param.start_recpos,llbuff));
1624
1627
    if (new_file >= 0)
1625
1628
    {
1681
1684
  return(0);
1682
1685
 
1683
1686
 err:
1684
 
  if (my_errno == HA_ERR_FOUND_DUPP_KEY)
 
1687
  if (errno == HA_ERR_FOUND_DUPP_KEY)
1685
1688
  {
1686
1689
    info->errkey=(int) i;                       /* This key was found */
1687
1690
    while ( i-- > 0 )
1758
1761
    int success = mlockall(MCL_CURRENT);        /* or plock(DATLOCK); */
1759
1762
    if (geteuid() == 0 && success != 0)
1760
1763
      mi_check_print_warning(param,
1761
 
                             "Failed to lock memory. errno %d",my_errno);
 
1764
                             "Failed to lock memory. errno %d",errno);
1762
1765
  }
1763
1766
#else
1764
1767
  (void)param;
1768
1771
 
1769
1772
        /* Flush all changed blocks to disk */
1770
1773
 
1771
 
int flush_blocks(MI_CHECK *param, KEY_CACHE *key_cache, File file)
 
1774
int flush_blocks(MI_CHECK *param, KEY_CACHE *key_cache, int file)
1772
1775
{
1773
1776
  if (flush_key_blocks(key_cache, file, FLUSH_RELEASE))
1774
1777
  {
1775
 
    mi_check_print_error(param,"%d when trying to write bufferts",my_errno);
 
1778
    mi_check_print_error(param,"%d when trying to write bufferts",errno);
1776
1779
    return(1);
1777
1780
  }
1778
1781
  if (!param->using_global_keycache)
1787
1790
{
1788
1791
  register uint32_t key;
1789
1792
  register MI_KEYDEF *keyinfo;
1790
 
  File new_file;
 
1793
  int new_file;
1791
1794
  my_off_t index_pos[HA_MAX_POSSIBLE_KEY];
1792
1795
  uint32_t r_locks,w_locks;
1793
1796
  int old_lock;
1881
1884
         /* Sort records recursive using one index */
1882
1885
 
1883
1886
static int sort_one_index(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo,
1884
 
                          my_off_t pagepos, File new_file)
 
1887
                          my_off_t pagepos, int new_file)
1885
1888
{
1886
1889
  uint32_t length,nod_flag,used_length, key_length;
1887
1890
  unsigned char *buff,*keypos,*endpos;
1932
1935
  if (my_pwrite(new_file,(unsigned char*) buff,(uint) keyinfo->block_length,
1933
1936
                new_page_pos,MYF(MY_NABP | MY_WAIT_IF_FULL)))
1934
1937
  {
1935
 
    mi_check_print_error(param,"Can't write indexblock, error: %d",my_errno);
 
1938
    mi_check_print_error(param,"Can't write indexblock, error: %d",errno);
1936
1939
    goto err;
1937
1940
  }
1938
1941
  free(buff);
1970
1973
 
1971
1974
        /* Copy a block between two files */
1972
1975
 
1973
 
int filecopy(MI_CHECK *param, File to,File from,my_off_t start,
 
1976
int filecopy(MI_CHECK *param, int to,int from,my_off_t start,
1974
1977
             my_off_t length, const char *type)
1975
1978
{
1976
1979
  char tmp_buff[IO_SIZE],*buff;
2000
2003
  if (buff != tmp_buff)
2001
2004
    free(buff);
2002
2005
  mi_check_print_error(param,"Can't copy %s to tempfile, error %d",
2003
 
                       type,my_errno);
 
2006
                       type,errno);
2004
2007
  return(1);
2005
2008
}
2006
2009
 
2028
2031
  ulong length;
2029
2032
  ha_rows start_records;
2030
2033
  my_off_t new_header_length,del;
2031
 
  File new_file;
 
2034
  int new_file;
2032
2035
  MI_SORT_PARAM sort_param;
2033
2036
  MYISAM_SHARE *share=info->s;
2034
2037
  HA_KEYSEG *keyseg;
2275
2278
      if (ftruncate(info->dfile, skr))
2276
2279
        mi_check_print_warning(param,
2277
2280
                               "Can't change size of datafile,  error: %d",
2278
 
                               my_errno);
 
2281
                               errno);
2279
2282
  }
2280
2283
  if (param->testflag & T_CALC_CHECKSUM)
2281
2284
    info->state->checksum=param->glob_crc;
2283
2286
  if (ftruncate(share->kfile, info->state->key_file_length))
2284
2287
    mi_check_print_warning(param,
2285
2288
                           "Can't change size of indexfile, error: %d",
2286
 
                           my_errno);
 
2289
                           errno);
2287
2290
 
2288
2291
  if (!(param->testflag & T_SILENT))
2289
2292
  {
2320
2323
  if (got_error)
2321
2324
  {
2322
2325
    if (! param->error_printed)
2323
 
      mi_check_print_error(param,"%d when fixing table",my_errno);
 
2326
      mi_check_print_error(param,"%d when fixing table",errno);
2324
2327
    if (new_file >= 0)
2325
2328
    {
2326
2329
      my_close(new_file,MYF(0));
2405
2408
  ulong rec_length;
2406
2409
  ha_rows start_records;
2407
2410
  my_off_t new_header_length,del;
2408
 
  File new_file;
 
2411
  int new_file;
2409
2412
  MI_SORT_PARAM *sort_param=0;
2410
2413
  MYISAM_SHARE *share=info->s;
2411
2414
  ulong   *rec_per_key_part;
2773
2776
      if (ftruncate(info->dfile, skr))
2774
2777
        mi_check_print_warning(param,
2775
2778
                               "Can't change size of datafile,  error: %d",
2776
 
                               my_errno);
 
2779
                               errno);
2777
2780
  }
2778
2781
  if (param->testflag & T_CALC_CHECKSUM)
2779
2782
    info->state->checksum=param->glob_crc;
2780
2783
 
2781
2784
  if (ftruncate(share->kfile, info->state->key_file_length))
2782
2785
    mi_check_print_warning(param,
2783
 
                           "Can't change size of indexfile, error: %d", my_errno);
 
2786
                           "Can't change size of indexfile, error: %d", errno);
2784
2787
 
2785
2788
  if (!(param->testflag & T_SILENT))
2786
2789
  {
2830
2833
  if (got_error)
2831
2834
  {
2832
2835
    if (! param->error_printed)
2833
 
      mi_check_print_error(param,"%d when fixing table",my_errno);
 
2836
      mi_check_print_error(param,"%d when fixing table",errno);
2834
2837
    if (new_file >= 0)
2835
2838
    {
2836
2839
      my_close(new_file,MYF(0));
3210
3213
        {
3211
3214
          mi_check_print_info(param,
3212
3215
                              "Read error for block at: %s (error: %d); Skipped",
3213
 
                              llstr(block_info.filepos,llbuff),my_errno);
 
3216
                              llstr(block_info.filepos,llbuff),errno);
3214
3217
          goto try_next;
3215
3218
        }
3216
3219
        left_length-=block_info.data_len;
3303
3306
      if (my_b_write(&info->rec_cache,sort_param->record,
3304
3307
                     share->base.pack_reclength))
3305
3308
      {
3306
 
        mi_check_print_error(param,"%d when writing to datafile",my_errno);
 
3309
        mi_check_print_error(param,"%d when writing to datafile",errno);
3307
3310
        return(1);
3308
3311
      }
3309
3312
      sort_param->filepos+=share->base.pack_reclength;
3357
3360
                                  sort_param->filepos+block_length,
3358
3361
                                  &from,&reclength,&flag))
3359
3362
        {
3360
 
          mi_check_print_error(param,"%d when writing to datafile",my_errno);
 
3363
          mi_check_print_error(param,"%d when writing to datafile",errno);
3361
3364
          return(1);
3362
3365
        }
3363
3366
        sort_param->filepos+=block_length;
3803
3806
                &create_info,
3804
3807
                HA_DONT_TOUCH_DATA))
3805
3808
  {
3806
 
    mi_check_print_error(param,"Got error %d when trying to recreate indexfile",my_errno);
 
3809
    mi_check_print_error(param,"Got error %d when trying to recreate indexfile",errno);
3807
3810
    goto end;
3808
3811
  }
3809
3812
  *org_info=mi_open(filename,O_RDWR,
3813
3816
  if (!*org_info)
3814
3817
  {
3815
3818
    mi_check_print_error(param,"Got error %d when trying to open re-created indexfile",
3816
 
                my_errno);
 
3819
                errno);
3817
3820
    goto end;
3818
3821
  }
3819
3822
  /* We are modifing */
3855
3858
    if (my_b_write(&info->rec_cache,buff,sizeof(buff)))
3856
3859
    {
3857
3860
      mi_check_print_error(sort_info->param,
3858
 
                           "%d when writing to datafile",my_errno);
 
3861
                           "%d when writing to datafile",errno);
3859
3862
      return 1;
3860
3863
    }
3861
3864
    sort_info->param->read_cache.end_of_file+=sizeof(buff);
3920
3923
      return 0;
3921
3924
  }
3922
3925
err:
3923
 
  mi_check_print_error(param,"%d when updating keyfile",my_errno);
 
3926
  mi_check_print_error(param,"%d when updating keyfile",errno);
3924
3927
  return 1;
3925
3928
}
3926
3929
 
3967
3970
  mi_extra(info,HA_EXTRA_KEYREAD,0);
3968
3971
  if (mi_rlast(info, record, info->s->base.auto_key-1))
3969
3972
  {
3970
 
    if (my_errno != HA_ERR_END_OF_FILE)
 
3973
    if (errno != HA_ERR_END_OF_FILE)
3971
3974
    {
3972
3975
      mi_extra(info,HA_EXTRA_NO_KEYREAD,0);
3973
3976
      free(mi_get_rec_buff_ptr(info, record));
3974
 
      mi_check_print_error(param,"%d when reading last record",my_errno);
 
3977
      mi_check_print_error(param,"%d when reading last record",errno);
3975
3978
      return;
3976
3979
    }
3977
3980
    if (!repair_only)