~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/mi_check.cc

Merged build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
#include <sys/mman.h>
55
55
#endif
56
56
#include <drizzled/util/test.h>
57
 
#include "drizzled/my_error.h"
 
57
#include "drizzled/error.h"
58
58
 
59
59
#include <algorithm>
60
60
 
61
61
using namespace std;
 
62
using namespace drizzled;
 
63
using namespace drizzled::internal;
62
64
 
63
65
 
64
66
#define my_off_t2double(A)  ((double) (my_off_t) (A))
74
76
static int writekeys(MI_SORT_PARAM *sort_param);
75
77
static int sort_one_index(MI_CHECK *param, MI_INFO *info,MI_KEYDEF *keyinfo,
76
78
                          my_off_t pagepos, int new_file);
77
 
extern "C"
78
 
{
79
 
  int sort_key_read(MI_SORT_PARAM *sort_param,void *key);
80
 
  int sort_get_next_record(MI_SORT_PARAM *sort_param);
81
 
  int sort_key_cmp(MI_SORT_PARAM *sort_param, const void *a,const void *b);
82
 
  int sort_key_write(MI_SORT_PARAM *sort_param, const void *a);
83
 
  my_off_t get_record_for_key(MI_INFO *info,MI_KEYDEF *keyinfo,
84
 
                              unsigned char *key);
85
 
  int sort_insert_key(MI_SORT_PARAM  *sort_param,
86
 
                      register SORT_KEY_BLOCKS *key_block,
87
 
                      unsigned char *key, my_off_t prev_block);
88
 
  int sort_delete_record(MI_SORT_PARAM *sort_param);
89
 
}
 
79
int sort_key_read(MI_SORT_PARAM *sort_param,void *key);
 
80
int sort_get_next_record(MI_SORT_PARAM *sort_param);
 
81
int sort_key_cmp(MI_SORT_PARAM *sort_param, const void *a,const void *b);
 
82
int sort_key_write(MI_SORT_PARAM *sort_param, const void *a);
 
83
my_off_t get_record_for_key(MI_INFO *info,MI_KEYDEF *keyinfo,
 
84
                            unsigned char *key);
 
85
int sort_insert_key(MI_SORT_PARAM  *sort_param,
 
86
                    register SORT_KEY_BLOCKS *key_block,
 
87
                    unsigned char *key, my_off_t prev_block);
 
88
int sort_delete_record(MI_SORT_PARAM *sort_param);
 
89
 
90
90
/*static int flush_pending_blocks(MI_CHECK *param);*/
91
91
static SORT_KEY_BLOCKS  *alloc_key_blocks(MI_CHECK *param, uint32_t blocks,
92
92
                                          uint32_t buffer_length);
1459
1459
  if (!rep_quick)
1460
1460
  {
1461
1461
    /* Get real path for data file */
1462
 
    if ((new_file=my_create(fn_format(param->temp_filename,
 
1462
    if ((new_file=my_create(internal::fn_format(param->temp_filename,
1463
1463
                                      share->data_file_name, "",
1464
1464
                                      DATA_TMP_EXT, 2+4),
1465
1465
                            0,param->tmpfile_createflag,
1576
1576
 
1577
1577
  if (!rep_quick)
1578
1578
  {
1579
 
    my_close(info->dfile,MYF(0));
 
1579
    internal::my_close(info->dfile,MYF(0));
1580
1580
    info->dfile=new_file;
1581
1581
    info->state->data_file_length=sort_param.filepos;
1582
1582
    share->state.version=(ulong) time((time_t*) 0);     /* Force reopen */
1609
1609
    /* Replace the actual file with the temporary file */
1610
1610
    if (new_file >= 0)
1611
1611
    {
1612
 
      my_close(new_file,MYF(0));
 
1612
      internal::my_close(new_file,MYF(0));
1613
1613
      info->dfile=new_file= -1;
1614
1614
      if (change_to_newfile(share->data_file_name,MI_NAME_DEXT,
1615
1615
                            DATA_TMP_EXT, share->base.raid_chunks,
1626
1626
                  llstr(sort_param.start_recpos,llbuff));
1627
1627
    if (new_file >= 0)
1628
1628
    {
1629
 
      my_close(new_file,MYF(0));
 
1629
      internal::my_close(new_file,MYF(0));
1630
1630
      my_delete(param->temp_filename, MYF(MY_WME));
1631
1631
      info->rec_cache.file=-1; /* don't flush data to new_file, it's closed */
1632
1632
    }
1753
1753
 
1754
1754
        /* Tell system that we want all memory for our cache */
1755
1755
 
1756
 
void lock_memory(MI_CHECK *param)
 
1756
void lock_memory(MI_CHECK *)
1757
1757
{
1758
 
#ifdef SUN_OS                           /* Key-cacheing thrases on sun 4.1 */
1759
 
  if (param->opt_lock_memory)
1760
 
  {
1761
 
    int success = mlockall(MCL_CURRENT);        /* or plock(DATLOCK); */
1762
 
    if (geteuid() == 0 && success != 0)
1763
 
      mi_check_print_warning(param,
1764
 
                             "Failed to lock memory. errno %d",errno);
1765
 
  }
1766
 
#else
1767
 
  (void)param;
1768
 
#endif
1769
1758
} /* lock_memory */
1770
1759
 
1771
1760
 
1805
1794
    printf("- Sorting index for MyISAM-table '%s'\n",name);
1806
1795
 
1807
1796
  /* Get real path for index file */
1808
 
  fn_format(param->temp_filename,name,"", MI_NAME_IEXT,2+4+32);
1809
 
  if ((new_file=my_create(fn_format(param->temp_filename,param->temp_filename,
 
1797
  internal::fn_format(param->temp_filename,name,"", MI_NAME_IEXT,2+4+32);
 
1798
  if ((new_file=my_create(internal::fn_format(param->temp_filename,param->temp_filename,
1810
1799
                                    "", INDEX_TMP_EXT,2+4),
1811
1800
                          0,param->tmpfile_createflag,MYF(0))) <= 0)
1812
1801
  {
1848
1837
        /* Put same locks as old file */
1849
1838
  share->r_locks= share->w_locks= share->tot_locks= 0;
1850
1839
  (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
1851
 
  my_close(share->kfile,MYF(MY_WME));
 
1840
  internal::my_close(share->kfile,MYF(MY_WME));
1852
1841
  share->kfile = -1;
1853
 
  my_close(new_file,MYF(MY_WME));
 
1842
  internal::my_close(new_file,MYF(MY_WME));
1854
1843
  if (change_to_newfile(share->index_file_name,MI_NAME_IEXT,INDEX_TMP_EXT,0,
1855
1844
                        MYF(0)) ||
1856
1845
      mi_open_keyfile(share))
1874
1863
  return(0);
1875
1864
 
1876
1865
err:
1877
 
  my_close(new_file,MYF(MY_WME));
 
1866
  internal::my_close(new_file,MYF(MY_WME));
1878
1867
err2:
1879
1868
  my_delete(param->temp_filename,MYF(MY_WME));
1880
1869
  return(-1);
1963
1952
  (void)raid_chunks;
1964
1953
  char old_filename[FN_REFLEN],new_filename[FN_REFLEN];
1965
1954
  /* Get real path to filename */
1966
 
  (void) fn_format(old_filename,filename,"",old_ext,2+4+32);
 
1955
  (void) internal::fn_format(old_filename,filename,"",old_ext,2+4+32);
1967
1956
  return my_redel(old_filename,
1968
 
                  fn_format(new_filename,old_filename,"",new_ext,2+4),
 
1957
                  internal::fn_format(new_filename,old_filename,"",new_ext,2+4),
1969
1958
                  MYF(MY_WME | MY_LINK_WARNING | MyFlags));
1970
1959
} /* change_to_newfile */
1971
1960
 
2083
2072
  if (!rep_quick)
2084
2073
  {
2085
2074
    /* Get real path for data file */
2086
 
    if ((new_file=my_create(fn_format(param->temp_filename,
 
2075
    if ((new_file=my_create(internal::fn_format(param->temp_filename,
2087
2076
                                      share->data_file_name, "",
2088
2077
                                      DATA_TMP_EXT, 2+4),
2089
2078
                            0,param->tmpfile_createflag,
2235
2224
        sort_param.filepos;
2236
2225
      /* Only whole records */
2237
2226
      share->state.version=(ulong) time((time_t*) 0);
2238
 
      my_close(info->dfile,MYF(0));
 
2227
      internal::my_close(info->dfile,MYF(0));
2239
2228
      info->dfile=new_file;
2240
2229
      share->data_file_type=sort_info.new_data_file_type;
2241
2230
      share->pack.header_length=(ulong) new_header_length;
2310
2299
    /* Replace the actual file with the temporary file */
2311
2300
    if (new_file >= 0)
2312
2301
    {
2313
 
      my_close(new_file,MYF(0));
 
2302
      internal::my_close(new_file,MYF(0));
2314
2303
      info->dfile=new_file= -1;
2315
2304
      if (change_to_newfile(share->data_file_name,MI_NAME_DEXT,
2316
2305
                            DATA_TMP_EXT, share->base.raid_chunks,
2326
2315
      mi_check_print_error(param,"%d when fixing table",errno);
2327
2316
    if (new_file >= 0)
2328
2317
    {
2329
 
      my_close(new_file,MYF(0));
 
2318
      internal::my_close(new_file,MYF(0));
2330
2319
      my_delete(param->temp_filename, MYF(MY_WME));
2331
2320
      if (info->dfile == new_file)
2332
2321
        info->dfile= -1;
2492
2481
  if (!rep_quick)
2493
2482
  {
2494
2483
    /* Get real path for data file */
2495
 
    if ((new_file=my_create(fn_format(param->temp_filename,
 
2484
    if ((new_file=my_create(internal::fn_format(param->temp_filename,
2496
2485
                                      share->data_file_name, "",
2497
2486
                                      DATA_TMP_EXT,
2498
2487
                                      2+4),
2744
2733
      Exchange the data file descriptor of the table, so that we use the
2745
2734
      new file from now on.
2746
2735
     */
2747
 
    my_close(info->dfile,MYF(0));
 
2736
    internal::my_close(info->dfile,MYF(0));
2748
2737
    info->dfile=new_file;
2749
2738
 
2750
2739
    share->data_file_type=sort_info.new_data_file_type;
2820
2809
    /* Replace the actual file with the temporary file */
2821
2810
    if (new_file >= 0)
2822
2811
    {
2823
 
      my_close(new_file,MYF(0));
 
2812
      internal::my_close(new_file,MYF(0));
2824
2813
      info->dfile=new_file= -1;
2825
2814
      if (change_to_newfile(share->data_file_name,MI_NAME_DEXT,
2826
2815
                            DATA_TMP_EXT, share->base.raid_chunks,
2836
2825
      mi_check_print_error(param,"%d when fixing table",errno);
2837
2826
    if (new_file >= 0)
2838
2827
    {
2839
 
      my_close(new_file,MYF(0));
 
2828
      internal::my_close(new_file,MYF(0));
2840
2829
      my_delete(param->temp_filename, MYF(MY_WME));
2841
2830
      if (info->dfile == new_file)
2842
2831
        info->dfile= -1;