~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/myisamchk.c

  • Committer: Andy Lester
  • Date: 2008-08-09 05:13:22 UTC
  • mto: (266.1.29 use-replace-funcs)
  • mto: This revision was merged to the branch mainline in revision 287.
  • Revision ID: andy@petdance.com-20080809051322-dzas70no2mv6c9i5
removed incorrect comment

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#ifdef HAVE_SYS_MMAN_H
30
30
#include <sys/mman.h>
31
31
#endif
32
 
#include <drizzled/util/test.h>
 
32
SET_STACK_SIZE(9000)                    /* Minimum stack size for program */
 
33
 
 
34
#define my_raid_create(A,B,C,D,E,F,G) my_create(A,B,C,G)
 
35
#define my_raid_delete(A,B,C) my_delete(A,B)
33
36
 
34
37
#include "myisamdef.h"
35
38
 
36
 
static uint32_t decode_bits;
 
39
static uint decode_bits;
37
40
static char **default_argv;
38
41
static const char *load_default_groups[]= { "myisamchk", 0 };
39
42
static const char *set_collation_name, *opt_tmpdir;
69
72
static int myisamchk(MI_CHECK *param, char *filename);
70
73
static void descript(MI_CHECK *param, register MI_INFO *info, char * name);
71
74
static int mi_sort_records(MI_CHECK *param, register MI_INFO *info,
72
 
                           char * name, uint32_t sort_key,
73
 
                           bool write_info, bool update_index);
 
75
                           char * name, uint sort_key,
 
76
                           my_bool write_info, my_bool update_index);
74
77
static int sort_record_index(MI_SORT_PARAM *sort_param, MI_INFO *info,
75
78
                             MI_KEYDEF *keyinfo,
76
 
                             my_off_t page,unsigned char *buff,uint32_t sortkey,
77
 
                             File new_file, bool update_index);
 
79
                             my_off_t page,uchar *buff,uint sortkey,
 
80
                             File new_file, my_bool update_index);
78
81
 
79
82
MI_CHECK check_param;
80
83
 
97
100
    int new_error=myisamchk(&check_param, *(argv++));
98
101
    if ((check_param.testflag & T_REP_ANY) != T_REP)
99
102
      check_param.testflag&= ~T_REP;
100
 
    fflush(stdout);
101
 
    fflush(stderr);
 
103
    VOID(fflush(stdout));
 
104
    VOID(fflush(stderr));
102
105
    if ((check_param.error_printed | check_param.warning_printed) &&
103
106
        (check_param.testflag & T_FORCE_CREATE) &&
104
107
        (!(check_param.testflag & (T_REP | T_REP_BY_SORT | T_SORT_RECORDS |
105
108
                                   T_SORT_INDEX))))
106
109
    {
107
 
      uint32_t old_testflag=check_param.testflag;
 
110
      uint old_testflag=check_param.testflag;
108
111
      if (!(check_param.testflag & T_REP))
109
112
        check_param.testflag|= T_REP_BY_SORT;
110
113
      check_param.testflag&= ~T_EXTEND;                 /* Don't needed  */
111
114
      error|=myisamchk(&check_param, argv[-1]);
112
115
      check_param.testflag= old_testflag;
113
 
      fflush(stdout);
114
 
      fflush(stderr);
 
116
      VOID(fflush(stdout));
 
117
      VOID(fflush(stderr));
115
118
    }
116
119
    else
117
120
      error|=new_error;
118
121
    if (argc && (!(check_param.testflag & T_SILENT) || check_param.testflag & T_INFO))
119
122
    {
120
123
      puts("\n---------\n");
121
 
      fflush(stdout);
 
124
      VOID(fflush(stdout));
122
125
    }
123
126
  }
124
127
  if (check_param.total_files > 1)
275
278
  { "key_buffer_size", OPT_KEY_BUFFER_SIZE, "",
276
279
    (char**) &check_param.use_buffers, (char**) &check_param.use_buffers, 0,
277
280
    GET_ULONG, REQUIRED_ARG, (long) USE_BUFFER_INIT, (long) MALLOC_OVERHEAD,
278
 
    INT32_MAX, (long) MALLOC_OVERHEAD, (long) IO_SIZE, 0},
 
281
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) IO_SIZE, 0},
279
282
  { "key_cache_block_size", OPT_KEY_CACHE_BLOCK_SIZE,  "",
280
283
    (char**) &opt_key_cache_block_size,
281
284
    (char**) &opt_key_cache_block_size, 0,
289
292
    (char**) &check_param.read_buffer_length,
290
293
    (char**) &check_param.read_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
291
294
    (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
292
 
    INT32_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
 
295
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
293
296
  { "write_buffer_size", OPT_WRITE_BUFFER_SIZE, "",
294
297
    (char**) &check_param.write_buffer_length,
295
298
    (char**) &check_param.write_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
296
299
    (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
297
 
    INT32_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
 
300
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
298
301
  { "sort_buffer_size", OPT_SORT_BUFFER_SIZE, "",
299
302
    (char**) &check_param.sort_buffer_length,
300
303
    (char**) &check_param.sort_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
301
304
    (long) SORT_BUFFER_INIT, (long) (MIN_SORT_BUFFER + MALLOC_OVERHEAD),
302
 
    INT32_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
 
305
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
303
306
  { "sort_key_blocks", OPT_SORT_KEY_BLOCKS, "",
304
307
    (char**) &check_param.sort_key_blocks,
305
308
    (char**) &check_param.sort_key_blocks, 0, GET_ULONG, REQUIRED_ARG,
437
440
}
438
441
 
439
442
const char *myisam_stats_method_names[] = {"nulls_unequal", "nulls_equal",
440
 
                                           "nulls_ignored", NULL};
 
443
                                           "nulls_ignored", NullS};
441
444
TYPELIB myisam_stats_method_typelib= {
442
445
  array_elements(myisam_stats_method_names) - 1, "",
443
446
  myisam_stats_method_names, NULL};
713
716
  if ((check_param.testflag & T_UNPACK) &&
714
717
      (check_param.testflag & (T_QUICK | T_SORT_RECORDS)))
715
718
  {
716
 
    fprintf(stderr,
717
 
            "%s: --unpack can't be used with --quick or --sort-records\n",
718
 
            my_progname_short);
 
719
    VOID(fprintf(stderr,
 
720
                 "%s: --unpack can't be used with --quick or --sort-records\n",
 
721
                 my_progname_short));
719
722
    exit(1);
720
723
  }
721
724
  if ((check_param.testflag & T_READONLY) &&
723
726
       (T_REP_ANY | T_STATISTICS | T_AUTO_INC |
724
727
        T_SORT_RECORDS | T_SORT_INDEX | T_FORCE_CREATE)))
725
728
  {
726
 
    fprintf(stderr,
727
 
            "%s: Can't use --readonly when repairing or sorting\n",
728
 
            my_progname_short);
 
729
    VOID(fprintf(stderr,
 
730
                 "%s: Can't use --readonly when repairing or sorting\n",
 
731
                 my_progname_short));
729
732
    exit(1);
730
733
  }
731
734
 
751
754
{
752
755
  int error,lock_type,recreate;
753
756
  int rep_quick= param->testflag & (T_QUICK | T_FORCE_UNIQUENESS);
754
 
  uint32_t raid_chunks;
 
757
  uint raid_chunks;
755
758
  MI_INFO *info;
756
759
  File datafile;
757
760
  char llbuff[22],llbuff2[22];
758
 
  bool state_updated=0;
 
761
  my_bool state_updated=0;
759
762
  MYISAM_SHARE *share;
760
763
 
761
764
  param->out_flag=error=param->warning_printed=param->error_printed=
821
824
  */
822
825
  if (param->testflag & (T_FAST | T_CHECK_ONLY_CHANGED))
823
826
  {
824
 
    bool need_to_check= mi_is_crashed(info) || share->state.open_count != 0;
 
827
    my_bool need_to_check= mi_is_crashed(info) || share->state.open_count != 0;
825
828
 
826
829
    if ((param->testflag & (T_REP_ANY | T_SORT_RECORDS)) &&
827
830
        ((share->state.changed & (STATE_CHANGED | STATE_CRASHED |
878
881
      param->language= set_collation->number;
879
882
    if (recreate_table(param, &info,filename))
880
883
    {
881
 
      fprintf(stderr,
882
 
              "MyISAM-table '%s' is not fixed because of errors\n",
883
 
              filename);
 
884
      VOID(fprintf(stderr,
 
885
                   "MyISAM-table '%s' is not fixed because of errors\n",
 
886
              filename));
884
887
      return(-1);
885
888
    }
886
889
    recreate=1;
971
974
      }
972
975
      if (!error && param->testflag & T_SORT_RECORDS)
973
976
      {
974
 
        uint32_t key;
 
977
        uint key;
975
978
        /*
976
979
          We can't update the index in mi_sort_records if we have a
977
980
          prefix compressed or fulltext index
978
981
        */
979
 
        bool update_index=1;
 
982
        my_bool update_index=1;
980
983
        for (key=0 ; key < share->base.keys; key++)
981
984
          if (share->keyinfo[key].flag & (HA_BINARY_PACK_KEY))
982
985
            update_index=0;
983
986
 
984
987
        error=mi_sort_records(param,info,filename,param->opt_sort_key,
985
988
                           /* what is the following parameter for ? */
986
 
                              (bool) !(param->testflag & T_REP),
 
989
                              (my_bool) !(param->testflag & T_REP),
987
990
                              update_index);
988
991
        datafile=info->dfile;   /* This is now locked */
989
992
        if (!error && !update_index)
1029
1032
          !(param->testflag & (T_FAST | T_FORCE_CREATE)))
1030
1033
      {
1031
1034
        if (param->testflag & (T_EXTEND | T_MEDIUM))
1032
 
          init_key_cache(dflt_key_cache,opt_key_cache_block_size,
1033
 
                         param->use_buffers, 0, 0);
1034
 
        init_io_cache(&param->read_cache,datafile,
1035
 
                      (uint) param->read_buffer_length,
1036
 
                      READ_CACHE,
1037
 
                      (param->start_check_pos ?
1038
 
                       param->start_check_pos :
1039
 
                       share->pack.header_length),
1040
 
                      1,
1041
 
                      MYF(MY_WME));
 
1035
          VOID(init_key_cache(dflt_key_cache,opt_key_cache_block_size,
 
1036
                              param->use_buffers, 0, 0));
 
1037
        VOID(init_io_cache(&param->read_cache,datafile,
 
1038
                           (uint) param->read_buffer_length,
 
1039
                           READ_CACHE,
 
1040
                           (param->start_check_pos ?
 
1041
                            param->start_check_pos :
 
1042
                            share->pack.header_length),
 
1043
                           1,
 
1044
                           MYF(MY_WME)));
1042
1045
        lock_memory(param);
1043
1046
        if ((info->s->options & (HA_OPTION_PACK_RECORD |
1044
1047
                                 HA_OPTION_COMPRESS_RECORD)) ||
1045
1048
            (param->testflag & (T_EXTEND | T_MEDIUM)))
1046
1049
          error|=chk_data_link(param, info, param->testflag & T_EXTEND);
1047
1050
        error|=flush_blocks(param, share->key_cache, share->kfile);
1048
 
        end_io_cache(&param->read_cache);
 
1051
        VOID(end_io_cache(&param->read_cache));
1049
1052
      }
1050
1053
      if (!error)
1051
1054
      {
1066
1069
  if ((param->testflag & T_AUTO_INC) ||
1067
1070
      ((param->testflag & T_REP_ANY) && info->s->base.auto_key))
1068
1071
    update_auto_increment_key(param, info,
1069
 
                              (bool) !test(param->testflag & T_AUTO_INC));
 
1072
                              (my_bool) !test(param->testflag & T_AUTO_INC));
1070
1073
 
1071
1074
  if (!(param->testflag & T_DESCRIPT))
1072
1075
  {
1098
1101
      error|=change_to_newfile(filename,MI_NAME_IEXT,INDEX_TMP_EXT,0,
1099
1102
                               MYF(0));
1100
1103
  }
1101
 
  fflush(stdout); fflush(stderr);
 
1104
  VOID(fflush(stdout)); VOID(fflush(stderr));
1102
1105
  if (param->error_printed)
1103
1106
  {
1104
1107
    if (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX))
1105
1108
    {
1106
 
      fprintf(stderr,
1107
 
              "MyISAM-table '%s' is not fixed because of errors\n",
1108
 
              filename);
 
1109
      VOID(fprintf(stderr,
 
1110
                   "MyISAM-table '%s' is not fixed because of errors\n",
 
1111
                   filename));
1109
1112
      if (param->testflag & T_REP_ANY)
1110
 
        fprintf(stderr,
1111
 
                "Try fixing it by using the --safe-recover (-o), the --force (-f) option or by not using the --quick (-q) flag\n");
 
1113
        VOID(fprintf(stderr,
 
1114
                     "Try fixing it by using the --safe-recover (-o), the --force (-f) option or by not using the --quick (-q) flag\n"));
1112
1115
    }
1113
1116
    else if (!(param->error_printed & 2) &&
1114
1117
             !(param->testflag & T_FORCE_CREATE))
1115
 
      fprintf(stderr,
1116
 
              "MyISAM-table '%s' is corrupted\nFix it using switch \"-r\" or \"-o\"\n",
1117
 
              filename);
 
1118
      VOID(fprintf(stderr,
 
1119
      "MyISAM-table '%s' is corrupted\nFix it using switch \"-r\" or \"-o\"\n",
 
1120
              filename));
1118
1121
  }
1119
1122
  else if (param->warning_printed &&
1120
1123
           ! (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX |
1121
1124
                          T_FORCE_CREATE)))
1122
 
    fprintf(stderr, "MyISAM-table '%s' is usable but should be fixed\n",
1123
 
            filename);
1124
 
  fflush(stderr);
 
1125
    VOID(fprintf(stderr, "MyISAM-table '%s' is usable but should be fixed\n",
 
1126
                 filename));
 
1127
  VOID(fflush(stderr));
1125
1128
  return(error);
1126
1129
} /* myisamchk */
1127
1130
 
1130
1133
 
1131
1134
static void descript(MI_CHECK *param, register MI_INFO *info, char * name)
1132
1135
{
1133
 
  uint32_t key,keyseg_nr,field,start;
 
1136
  uint key,keyseg_nr,field,start;
1134
1137
  register MI_KEYDEF *keyinfo;
1135
1138
  register HA_KEYSEG *keyseg;
1136
1139
  register const char *text;
1167
1170
    }
1168
1171
    pos=buff;
1169
1172
    if (share->state.changed & STATE_CRASHED)
1170
 
      my_stpcpy(buff,"crashed");
 
1173
      strmov(buff,"crashed");
1171
1174
    else
1172
1175
    {
1173
1176
      if (share->state.open_count)
1174
 
        pos=my_stpcpy(pos,"open,");
 
1177
        pos=strmov(pos,"open,");
1175
1178
      if (share->state.changed & STATE_CHANGED)
1176
 
        pos=my_stpcpy(pos,"changed,");
 
1179
        pos=strmov(pos,"changed,");
1177
1180
      else
1178
 
        pos=my_stpcpy(pos,"checked,");
 
1181
        pos=strmov(pos,"checked,");
1179
1182
      if (!(share->state.changed & STATE_NOT_ANALYZED))
1180
 
        pos=my_stpcpy(pos,"analyzed,");
 
1183
        pos=strmov(pos,"analyzed,");
1181
1184
      if (!(share->state.changed & STATE_NOT_OPTIMIZED_KEYS))
1182
 
        pos=my_stpcpy(pos,"optimized keys,");
 
1185
        pos=strmov(pos,"optimized keys,");
1183
1186
      if (!(share->state.changed & STATE_NOT_SORTED_PAGES))
1184
 
        pos=my_stpcpy(pos,"sorted index pages,");
 
1187
        pos=strmov(pos,"sorted index pages,");
1185
1188
      pos[-1]=0;                                /* Remove extra ',' */
1186
1189
    }      
1187
1190
    printf("Status:              %s\n",buff);
1191
1194
             share->base.auto_key,
1192
1195
             llstr(share->state.auto_increment,llbuff));
1193
1196
    }
 
1197
    if (share->base.raid_type)
 
1198
    {
 
1199
      printf("RAID:                Type:  %u   Chunks: %u  Chunksize: %lu\n",
 
1200
             share->base.raid_type,
 
1201
             share->base.raid_chunks,
 
1202
             share->base.raid_chunksize);
 
1203
    }
1194
1204
    if (share->options & (HA_OPTION_CHECKSUM | HA_OPTION_COMPRESS_RECORD))
1195
1205
      printf("Checksum:  %23s\n",llstr(info->state->checksum,llbuff));
1196
1206
;
1240
1250
  printf("Key Start Len Index   Type");
1241
1251
  if (param->testflag & T_VERBOSE)
1242
1252
    printf("                     Rec/key         Root  Blocksize");
1243
 
  putchar('\n');
 
1253
  VOID(putchar('\n'));
1244
1254
 
1245
1255
  for (key=keyseg_nr=0, keyinfo= &share->keyinfo[0] ;
1246
1256
       key < share->base.keys;
1253
1263
    pos=buff;
1254
1264
    if (keyseg->flag & HA_REVERSE_SORT)
1255
1265
      *pos++ = '-';
1256
 
    pos=my_stpcpy(pos,type_names[keyseg->type]);
 
1266
    pos=strmov(pos,type_names[keyseg->type]);
1257
1267
    *pos++ = ' ';
1258
1268
    *pos=0;
1259
1269
    if (keyinfo->flag & HA_PACK_KEY)
1260
 
      pos=my_stpcpy(pos,prefix_packed_txt);
 
1270
      pos=strmov(pos,prefix_packed_txt);
1261
1271
    if (keyinfo->flag & HA_BINARY_PACK_KEY)
1262
 
      pos=my_stpcpy(pos,bin_packed_txt);
 
1272
      pos=strmov(pos,bin_packed_txt);
1263
1273
    if (keyseg->flag & HA_SPACE_PACK)
1264
 
      pos=my_stpcpy(pos,diff_txt);
 
1274
      pos=strmov(pos,diff_txt);
1265
1275
    if (keyseg->flag & HA_BLOB_PART)
1266
 
      pos=my_stpcpy(pos,blob_txt);
 
1276
      pos=strmov(pos,blob_txt);
1267
1277
    if (keyseg->flag & HA_NULL_PART)
1268
 
      pos=my_stpcpy(pos,null_txt);
 
1278
      pos=strmov(pos,null_txt);
1269
1279
    *pos=0;
1270
1280
 
1271
1281
    printf("%-4d%-6ld%-3d %-8s%-21s",
1278
1288
      printf("%11lu %12s %10d",
1279
1289
             share->state.rec_per_key_part[keyseg_nr++],
1280
1290
             buff,keyinfo->block_length);
1281
 
    putchar('\n');
 
1291
    VOID(putchar('\n'));
1282
1292
    while ((++keyseg)->type != HA_KEYTYPE_END)
1283
1293
    {
1284
1294
      pos=buff;
1285
1295
      if (keyseg->flag & HA_REVERSE_SORT)
1286
1296
        *pos++ = '-';
1287
 
      pos=my_stpcpy(pos,type_names[keyseg->type]);
 
1297
      pos=strmov(pos,type_names[keyseg->type]);
1288
1298
      *pos++= ' ';
1289
1299
      if (keyseg->flag & HA_SPACE_PACK)
1290
 
        pos=my_stpcpy(pos,diff_txt);
 
1300
        pos=strmov(pos,diff_txt);
1291
1301
      if (keyseg->flag & HA_BLOB_PART)
1292
 
        pos=my_stpcpy(pos,blob_txt);
 
1302
        pos=strmov(pos,blob_txt);
1293
1303
      if (keyseg->flag & HA_NULL_PART)
1294
 
        pos=my_stpcpy(pos,null_txt);
 
1304
        pos=strmov(pos,null_txt);
1295
1305
      *pos=0;
1296
1306
      printf("    %-6ld%-3d         %-21s",
1297
1307
             (long) keyseg->start+1,keyseg->length,buff);
1298
1308
      if (param->testflag & T_VERBOSE)
1299
1309
        printf("%11lu", share->state.rec_per_key_part[keyseg_nr++]);
1300
 
      putchar('\n');
 
1310
      VOID(putchar('\n'));
1301
1311
    }
1302
1312
    keyseg++;
1303
1313
  }
1308
1318
    for (key=0,uniqueinfo= &share->uniqueinfo[0] ;
1309
1319
         key < share->state.header.uniques; key++, uniqueinfo++)
1310
1320
    {
1311
 
      bool new_row=0;
 
1321
      my_bool new_row=0;
1312
1322
      char null_bit[8],null_pos[8];
1313
1323
      printf("%-8d%-5d",key+1,uniqueinfo->key+1);
1314
1324
      for (keyseg=uniqueinfo->seg ; keyseg->type != HA_KEYTYPE_END ; keyseg++)
1335
1345
    printf("\nField Start Length Nullpos Nullbit Type");
1336
1346
    if (share->options & HA_OPTION_COMPRESS_RECORD)
1337
1347
      printf("                         Huff tree  Bits");
1338
 
    putchar('\n');
 
1348
    VOID(putchar('\n'));
1339
1349
    start=1;
1340
1350
    for (field=0 ; field < share->base.fields ; field++)
1341
1351
    {
1343
1353
        type=share->rec[field].base_type;
1344
1354
      else
1345
1355
        type=(enum en_fieldtype) share->rec[field].type;
1346
 
      end=my_stpcpy(buff,field_pack[type]);
 
1356
      end=strmov(buff,field_pack[type]);
1347
1357
      if (share->options & HA_OPTION_COMPRESS_RECORD)
1348
1358
      {
1349
1359
        if (share->rec[field].pack_type & PACK_TYPE_SELECTED)
1350
 
          end=my_stpcpy(end,", not_always");
 
1360
          end=strmov(end,", not_always");
1351
1361
        if (share->rec[field].pack_type & PACK_TYPE_SPACE_FIELDS)
1352
 
          end=my_stpcpy(end,", no empty");
 
1362
          end=strmov(end,", no empty");
1353
1363
        if (share->rec[field].pack_type & PACK_TYPE_ZERO_FILL)
1354
1364
        {
1355
1365
          sprintf(end,", zerofill(%d)",share->rec[field].space_length_bits);
1356
 
          end= strchr(end, '\0');
 
1366
          end=strend(end);
1357
1367
        }
1358
1368
      }
1359
1369
      if (buff[0] == ',')
1360
 
        my_stpcpy(buff,buff+2);
 
1370
        strmov(buff,buff+2);
1361
1371
      int10_to_str((long) share->rec[field].length,length,10);
1362
1372
      null_bit[0]=null_pos[0]=0;
1363
1373
      if (share->rec[field].null_bit)
1374
1384
                 (uint) (share->rec[field].huff_tree-share->decode_trees)+1,
1375
1385
                 share->rec[field].huff_tree->quick_table_bits);
1376
1386
      }
1377
 
      putchar('\n');
 
1387
      VOID(putchar('\n'));
1378
1388
      start+=share->rec[field].length;
1379
1389
    }
1380
1390
  }
1386
1396
 
1387
1397
static int mi_sort_records(MI_CHECK *param,
1388
1398
                           register MI_INFO *info, char * name,
1389
 
                           uint32_t sort_key,
1390
 
                           bool write_info,
1391
 
                           bool update_index)
 
1399
                           uint sort_key,
 
1400
                           my_bool write_info,
 
1401
                           my_bool update_index)
1392
1402
{
1393
1403
  int got_error;
1394
 
  uint32_t key;
 
1404
  uint key;
1395
1405
  MI_KEYDEF *keyinfo;
1396
1406
  File new_file;
1397
 
  unsigned char *temp_buff;
 
1407
  uchar *temp_buff;
1398
1408
  ha_rows old_record_count;
1399
1409
  MYISAM_SHARE *share=info->s;
1400
1410
  char llbuff[22],llbuff2[22];
1443
1453
    goto err;
1444
1454
  info->opt_flag|=WRITE_CACHE_USED;
1445
1455
 
1446
 
  if (!(temp_buff=(unsigned char*) my_alloca((uint) keyinfo->block_length)))
 
1456
  if (!(temp_buff=(uchar*) my_alloca((uint) keyinfo->block_length)))
1447
1457
  {
1448
1458
    mi_check_print_error(param,"Not enough memory for key block");
1449
1459
    goto err;
1455
1465
    goto err;
1456
1466
  }
1457
1467
  fn_format(param->temp_filename,name,"", MI_NAME_DEXT,2+4+32);
1458
 
  new_file=my_create(fn_format(param->temp_filename,
1459
 
                               param->temp_filename,"",
1460
 
                               DATA_TMP_EXT,2+4),        
1461
 
                     0,param->tmpfile_createflag,
1462
 
                     MYF(0));
 
1468
  new_file=my_raid_create(fn_format(param->temp_filename,
 
1469
                                    param->temp_filename,"",
 
1470
                                    DATA_TMP_EXT,2+4),
 
1471
                          0,param->tmpfile_createflag,
 
1472
                          share->base.raid_type,
 
1473
                          share->base.raid_chunks,
 
1474
                          share->base.raid_chunksize,
 
1475
                          MYF(0));
1463
1476
  if (new_file < 0)
1464
1477
  {
1465
1478
    mi_check_print_error(param,"Can't create new tempfile: '%s'",
1476
1489
  for (key=0 ; key < share->base.keys ; key++)
1477
1490
    share->keyinfo[key].flag|= HA_SORT_ALLOWS_SAME;
1478
1491
 
1479
 
  if (my_pread(share->kfile,(unsigned char*) temp_buff,
 
1492
  if (my_pread(share->kfile,(uchar*) temp_buff,
1480
1493
               (uint) keyinfo->block_length,
1481
1494
               share->state.key_root[sort_key],
1482
1495
               MYF(MY_NABP+MY_WME)))
1511
1524
    goto err;
1512
1525
  }
1513
1526
 
1514
 
  my_close(info->dfile,MYF(MY_WME));
 
1527
  VOID(my_close(info->dfile,MYF(MY_WME)));
1515
1528
  param->out_flag|=O_NEW_DATA;                  /* Data in new file */
1516
1529
  info->dfile=new_file;                         /* Use new datafile */
1517
1530
  info->state->del=0;
1525
1538
 
1526
1539
  if (param->testflag & T_WRITE_LOOP)
1527
1540
  {
1528
 
    fputs("          \r",stdout); fflush(stdout);
 
1541
    VOID(fputs("          \r",stdout)); VOID(fflush(stdout));
1529
1542
  }
1530
1543
  got_error=0;
1531
1544
 
1532
1545
err:
1533
1546
  if (got_error && new_file >= 0)
1534
1547
  {
1535
 
    end_io_cache(&info->rec_cache);
 
1548
    VOID(end_io_cache(&info->rec_cache));
1536
1549
    (void) my_close(new_file,MYF(MY_WME));
1537
 
    (void) my_delete(param->temp_filename, MYF(MY_WME));
 
1550
    (void) my_raid_delete(param->temp_filename, share->base.raid_chunks,
 
1551
                          MYF(MY_WME));
1538
1552
  }
1539
1553
  if (temp_buff)
1540
1554
  {
1541
 
    my_afree((unsigned char*) temp_buff);
 
1555
    my_afree((uchar*) temp_buff);
1542
1556
  }
1543
 
  void * rec_buff_ptr= mi_get_rec_buff_ptr(info, sort_param.record);
1544
 
  if (rec_buff_ptr != NULL)
1545
 
    free(rec_buff_ptr);
1546
 
 
 
1557
  my_free(mi_get_rec_buff_ptr(info, sort_param.record),
 
1558
          MYF(MY_ALLOW_ZERO_PTR));
1547
1559
  info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
1548
 
  end_io_cache(&info->rec_cache);
1549
 
  free(sort_info.buff);
 
1560
  VOID(end_io_cache(&info->rec_cache));
 
1561
  my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR));
1550
1562
  sort_info.buff=0;
1551
1563
  share->state.sortkey=sort_key;
1552
1564
  return(flush_blocks(param, share->key_cache, share->kfile) |
1558
1570
 
1559
1571
static int sort_record_index(MI_SORT_PARAM *sort_param,MI_INFO *info,
1560
1572
                             MI_KEYDEF *keyinfo,
1561
 
                             my_off_t page, unsigned char *buff, uint32_t sort_key,
1562
 
                             File new_file,bool update_index)
 
1573
                             my_off_t page, uchar *buff, uint sort_key,
 
1574
                             File new_file,my_bool update_index)
1563
1575
{
1564
1576
  uint  nod_flag,used_length,key_length;
1565
 
  unsigned char *temp_buff,*keypos,*endpos;
 
1577
  uchar *temp_buff,*keypos,*endpos;
1566
1578
  my_off_t next_page,rec_pos;
1567
 
  unsigned char lastkey[MI_MAX_KEY_BUFF];
 
1579
  uchar lastkey[MI_MAX_KEY_BUFF];
1568
1580
  char llbuff[22];
1569
1581
  SORT_INFO *sort_info= sort_param->sort_info;
1570
1582
  MI_CHECK *param=sort_info->param;
1574
1586
 
1575
1587
  if (nod_flag)
1576
1588
  {
1577
 
    if (!(temp_buff=(unsigned char*) my_alloca((uint) keyinfo->block_length)))
 
1589
    if (!(temp_buff=(uchar*) my_alloca((uint) keyinfo->block_length)))
1578
1590
    {
1579
1591
      mi_check_print_error(param,"Not Enough memory");
1580
1592
      return(-1);
1588
1600
    if (nod_flag)
1589
1601
    {
1590
1602
      next_page=_mi_kpos(nod_flag,keypos);
1591
 
      if (my_pread(info->s->kfile,(unsigned char*) temp_buff,
 
1603
      if (my_pread(info->s->kfile,(uchar*) temp_buff,
1592
1604
                  (uint) keyinfo->block_length, next_page,
1593
1605
                   MYF(MY_NABP+MY_WME)))
1594
1606
      {
1627
1639
  }
1628
1640
  /* Clear end of block to get better compression if the table is backuped */
1629
1641
  memset(buff+used_length, 0, keyinfo->block_length-used_length);
1630
 
  if (my_pwrite(info->s->kfile,(unsigned char*) buff,(uint) keyinfo->block_length,
 
1642
  if (my_pwrite(info->s->kfile,(uchar*) buff,(uint) keyinfo->block_length,
1631
1643
                page,param->myf_rw))
1632
1644
  {
1633
1645
    mi_check_print_error(param,"%d when updating keyblock",my_errno);
1634
1646
    goto err;
1635
1647
  }
1636
1648
  if (temp_buff)
1637
 
    my_afree((unsigned char*) temp_buff);
 
1649
    my_afree((uchar*) temp_buff);
1638
1650
  return(0);
1639
1651
err:
1640
1652
  if (temp_buff)
1641
 
    my_afree((unsigned char*) temp_buff);
 
1653
    my_afree((uchar*) temp_buff);
1642
1654
  return(1);
1643
1655
} /* sort_record_index */
1644
1656
 
1666
1678
  va_list args;
1667
1679
 
1668
1680
  va_start(args,fmt);
1669
 
  vfprintf(stdout, fmt, args);
1670
 
  fputc('\n',stdout);
 
1681
  VOID(vfprintf(stdout, fmt, args));
 
1682
  VOID(fputc('\n',stdout));
1671
1683
  va_end(args);
1672
1684
}
1673
1685
 
1688
1700
  param->warning_printed=1;
1689
1701
  va_start(args,fmt);
1690
1702
  fprintf(stderr,"%s: warning: ",my_progname_short);
1691
 
  vfprintf(stderr, fmt, args);
1692
 
  fputc('\n',stderr);
 
1703
  VOID(vfprintf(stderr, fmt, args));
 
1704
  VOID(fputc('\n',stderr));
1693
1705
  fflush(stderr);
1694
1706
  va_end(args);
1695
1707
  return;
1711
1723
  param->error_printed|=1;
1712
1724
  va_start(args,fmt);
1713
1725
  fprintf(stderr,"%s: error: ",my_progname_short);
1714
 
  vfprintf(stderr, fmt, args);
1715
 
  fputc('\n',stderr);
 
1726
  VOID(vfprintf(stderr, fmt, args));
 
1727
  VOID(fputc('\n',stderr));
1716
1728
  fflush(stderr);
1717
1729
  va_end(args);
1718
1730
  return;