~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/myisamchk.c

  • Committer: Mark Atwood
  • Date: 2008-10-16 11:33:16 UTC
  • mto: (520.1.13 drizzle)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: mark@fallenpegasus.com-20081016113316-ff6jdt31ck90sjdh
an implemention of the errmsg plugin

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