~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/archive_reader.c

  • Committer: Brian Aker
  • Date: 2008-07-06 15:03:34 UTC
  • Revision ID: brian@tangent.org-20080706150334-xv3xa202trvs0712
USE_RAID cleanup, along with ftbench tools.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#include <assert.h>
4
4
#include <stdio.h>
5
5
#include <stdarg.h>
6
 
#include <mystrings/m_ctype.h>
7
 
#include <mystrings/m_string.h>
8
 
#include <mysys/my_getopt.h>
 
6
#include <m_ctype.h>
 
7
#include <m_string.h>
 
8
#include <my_getopt.h>
 
9
#include <mysql_version.h>
9
10
 
10
11
#define BUFFER_LEN 1024
11
12
#define ARCHIVE_ROW_HEADER_SIZE 4
17
18
static void usage(void);
18
19
static const char *opt_tmpdir;
19
20
static const char *new_auto_increment;
20
 
uint64_t new_auto_increment_value;
 
21
unsigned long long new_auto_increment_value;
21
22
static const char *load_default_groups[]= { "archive_reader", 0 };
22
23
static char **default_argv;
23
24
int opt_check, opt_force, opt_quiet, opt_backup= 0, opt_extract_frm;
38
39
    return 0;
39
40
  }
40
41
 
41
 
  if (!(ret= azopen(&reader_handle, argv[0], O_RDONLY, AZ_METHOD_BLOCK)))
 
42
  if (!(ret= azopen(&reader_handle, argv[0], O_RDONLY|O_BINARY, AZ_METHOD_BLOCK)))
42
43
  {
43
44
    printf("Could not open Archive file\n");
44
45
    return 0;
61
62
      new_auto_increment_value= reader_handle.auto_increment + 1;
62
63
    }
63
64
 
64
 
    if (!(ret= azopen(&writer_handle, argv[0], O_CREAT|O_RDWR, 
 
65
    if (!(ret= azopen(&writer_handle, argv[0], O_CREAT|O_RDWR|O_BINARY, 
65
66
                      AZ_METHOD_BLOCK)))
66
67
    {
67
68
      printf("Could not open file for update: %s\n", argv[0]);
78
79
  if (reader_handle.version > 2)
79
80
  {
80
81
    printf("\tMinor version %u\n", reader_handle.minor_version);
81
 
    printf("\tStart position %"PRIu64"\n", (uint64_t)reader_handle.start);
 
82
    printf("\tStart position %lu\n", (unsigned long long)reader_handle.start);
82
83
    printf("\tBlock size %u\n", reader_handle.block_size);
83
 
    printf("\tRows %"PRIu64"\n", reader_handle.rows);
84
 
    printf("\tAutoincrement %"PRIu64"\n", reader_handle.auto_increment);
85
 
    printf("\tCheck Point %"PRIu64"\n", reader_handle.check_point);
86
 
    printf("\tForced Flushes %"PRIu64"\n", reader_handle.forced_flushes);
 
84
    printf("\tRows %lu\n", reader_handle.rows);
 
85
    printf("\tAutoincrement %lu\n", reader_handle.auto_increment);
 
86
    printf("\tCheck Point %lu\n", reader_handle.check_point);
 
87
    printf("\tForced Flushes %lu\n", reader_handle.forced_flushes);
87
88
    printf("\tLongest Row %u\n", reader_handle.longest_row);
88
89
    printf("\tShortest Row %u\n", reader_handle.shortest_row);
89
90
    printf("\tState %s\n", ( reader_handle.dirty ? "dirty" : "clean"));
113
114
  {
114
115
    int error;
115
116
    unsigned int read;
116
 
    uint64_t row_count= 0;
 
117
    unsigned long long row_count= 0;
117
118
 
118
119
    while ((read= azread_row(&reader_handle, &error)))
119
120
    {
127
128
 
128
129
      if (read > reader_handle.longest_row)
129
130
      {
130
 
        printf("Table is damaged, row %"PRIu64" is invalid\n", row_count);
 
131
        printf("Table is damaged, row %lu is invalid\n", row_count);
131
132
        goto end;
132
133
      }
133
134
    }
134
135
 
135
 
    printf("Found %"PRIu64" rows\n", row_count);
 
136
    printf("Found %lu rows\n", row_count);
136
137
  }
137
138
 
138
139
  if (opt_backup)
139
140
  {
140
141
    int error;
141
142
    unsigned int read;
142
 
    uint64_t row_count= 0;
 
143
    unsigned long long row_count= 0;
143
144
    char *buffer;
144
145
 
145
146
    azio_stream writer_handle;
147
148
    buffer= (char *)malloc(reader_handle.longest_row);
148
149
    if (buffer == NULL)
149
150
    {
150
 
      printf("Could not allocate memory for row %"PRIu64"\n", row_count);
 
151
      printf("Could not allocate memory for row %lu\n", row_count);
151
152
      goto end;
152
153
    }
153
154
 
154
155
 
155
 
    if (!(ret= azopen(&writer_handle, argv[1], O_CREAT|O_RDWR,
 
156
    if (!(ret= azopen(&writer_handle, argv[1], O_CREAT|O_RDWR|O_BINARY,
156
157
                      AZ_METHOD_BLOCK)))
157
158
    {
158
159
      printf("Could not open file for backup: %s\n", argv[1]);
166
167
      ptr= (char *)my_malloc(sizeof(char) * reader_handle.frm_length, MYF(0));
167
168
      azread_frm(&reader_handle, ptr);
168
169
      azwrite_frm(&writer_handle, ptr, reader_handle.frm_length);
169
 
      free(ptr);
 
170
      my_free(ptr, MYF(0));
170
171
    }
171
172
 
172
173
    if (reader_handle.comment_length)
175
176
      ptr= (char *)my_malloc(sizeof(char) * reader_handle.comment_length, MYF(0));
176
177
      azread_comment(&reader_handle, ptr);
177
178
      azwrite_comment(&writer_handle, ptr, reader_handle.comment_length);
178
 
      free(ptr);
 
179
      my_free(ptr, MYF(0));
179
180
    }
180
181
 
181
182
    while ((read= azread_row(&reader_handle, &error)))
207
208
  {
208
209
    File frm_file;
209
210
    char *ptr;
210
 
    frm_file= my_open(argv[1], O_CREAT|O_RDWR, MYF(0));
 
211
    frm_file= my_open(argv[1], O_CREAT|O_RDWR|O_BINARY, MYF(0));
211
212
    ptr= (char *)my_malloc(sizeof(char) * reader_handle.frm_length, MYF(0));
212
213
    azread_frm(&reader_handle, ptr);
213
 
    my_write(frm_file, (unsigned char*) ptr, reader_handle.frm_length, MYF(0));
 
214
    my_write(frm_file, (uchar*) ptr, reader_handle.frm_length, MYF(0));
214
215
    my_close(frm_file, MYF(0));
215
 
    free(ptr);
 
216
    my_free(ptr, MYF(0));
216
217
  }
217
218
 
218
219
end:
223
224
  return 0;
224
225
}
225
226
 
226
 
static bool
 
227
static my_bool
227
228
get_one_option(int optid,
228
229
               const struct my_option *opt __attribute__((unused)),
229
230
               char *argument)
262
263
  case '?':
263
264
    usage();
264
265
    exit(0);
 
266
  case '#':
 
267
    if (argument == disabled_my_option)
 
268
    {
 
269
      DBUG_POP();
 
270
    }
 
271
    else
 
272
    {
 
273
      DBUG_PUSH(argument ? argument : "d:t:o,/tmp/archive_reader.trace");
 
274
    }
 
275
    break;
265
276
  }
266
277
  return 0;
267
278
}
273
284
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
274
285
  {"check", 'c', "Check table for errors.",
275
286
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
287
#ifndef DBUG_OFF
 
288
  {"debug", '#',
 
289
   "Output debug log. Often this is 'd:t:o,filename'.",
 
290
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
291
#endif
276
292
  {"extract-frm", 'e',
277
293
   "Extract the frm file.",
278
294
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
288
304
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
289
305
  {"set-auto-increment", 'A',
290
306
   "Force auto_increment to start at this or higher value. If no value is given, then sets the next auto_increment value to the highest used value for the auto key + 1.",
291
 
   (char**) &new_auto_increment,
292
 
   (char**) &new_auto_increment,
 
307
   (uchar**) &new_auto_increment,
 
308
   (uchar**) &new_auto_increment,
293
309
   0, GET_ULL, OPT_ARG, 0, 0, 0, 0, 0, 0},
294
310
  {"silent", 's',
295
311
   "Only print errors. One can use two -s to make archive_reader very silent.",
296
312
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
297
313
  {"tmpdir", 't',
298
314
   "Path for temporary files.",
299
 
   (char**) &opt_tmpdir,
 
315
   (uchar**) &opt_tmpdir,
300
316
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
301
317
  {"version", 'V',
302
318
   "Print version and exit.",
319
335
 
320
336
static void print_version(void)
321
337
{
322
 
  printf("%s  Ver %s, for %s (%s)\n", my_progname, SHOW_VERSION,
323
 
         SYSTEM_TYPE, MACHINE_TYPE);
 
338
  printf("%s  Ver %s Distrib %s, for %s (%s)\n", my_progname, SHOW_VERSION,
 
339
         MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
324
340
}
325
341
 
326
342
static void get_options(int *argc, char ***argv)