~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/archive_reader.cc

  • Committer: Brian Aker
  • Date: 2009-04-27 14:36:40 UTC
  • Revision ID: brian@gaz-20090427143640-f6zjmtt9vm55qgm2
Patch on show processlist from  davi@apache.org

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
#include <mystrings/m_string.h>
8
8
#include <mysys/my_getopt.h>
9
9
 
10
 
#define BUFFER_LEN 1024
11
 
#define ARCHIVE_ROW_HEADER_SIZE 4
12
 
 
13
10
#define SHOW_VERSION "0.1"
14
11
 
15
12
static void get_options(int *argc,char * * *argv);
38
35
    return 0;
39
36
  }
40
37
 
41
 
  if (!(ret= azopen(&reader_handle, argv[0], O_RDONLY|O_BINARY, AZ_METHOD_BLOCK)))
 
38
  if (!(ret= azopen(&reader_handle, argv[0], O_RDONLY, AZ_METHOD_BLOCK)))
42
39
  {
43
40
    printf("Could not open Archive file\n");
44
41
    return 0;
61
58
      new_auto_increment_value= reader_handle.auto_increment + 1;
62
59
    }
63
60
 
64
 
    if (!(ret= azopen(&writer_handle, argv[0], O_CREAT|O_RDWR|O_BINARY, 
 
61
    if (!(ret= azopen(&writer_handle, argv[0], O_CREAT|O_RDWR,
65
62
                      AZ_METHOD_BLOCK)))
66
63
    {
67
64
      printf("Could not open file for update: %s\n", argv[0]);
97
94
      char *comment =
98
95
        (char *) malloc(sizeof(char) * reader_handle.comment_length);
99
96
      azread_comment(&reader_handle, comment);
100
 
      printf("\tComment length %u\n\t\t%.*s\n", reader_handle.comment_length, 
 
97
      printf("\tComment length %u\n\t\t%.*s\n", reader_handle.comment_length,
101
98
             reader_handle.comment_length, comment);
102
99
      free(comment);
103
100
    }
112
109
  if (opt_check)
113
110
  {
114
111
    int error;
115
 
    unsigned int read;
 
112
    unsigned int row_read;
116
113
    uint64_t row_count= 0;
117
114
 
118
 
    while ((read= azread_row(&reader_handle, &error)))
 
115
    while ((row_read= azread_row(&reader_handle, &error)))
119
116
    {
120
117
      if (error == Z_STREAM_ERROR)
121
118
      {
125
122
 
126
123
      row_count++;
127
124
 
128
 
      if (read > reader_handle.longest_row)
 
125
      if (row_read > reader_handle.longest_row)
129
126
      {
130
127
        printf("Table is damaged, row %"PRIu64" is invalid\n", row_count);
131
128
        goto end;
138
135
  if (opt_backup)
139
136
  {
140
137
    int error;
141
 
    unsigned int read;
 
138
    unsigned int row_read;
142
139
    uint64_t row_count= 0;
143
140
    char *buffer;
144
141
 
152
149
    }
153
150
 
154
151
 
155
 
    if (!(ret= azopen(&writer_handle, argv[1], O_CREAT|O_RDWR|O_BINARY,
 
152
    if (!(ret= azopen(&writer_handle, argv[1], O_CREAT|O_RDWR,
156
153
                      AZ_METHOD_BLOCK)))
157
154
    {
158
155
      printf("Could not open file for backup: %s\n", argv[1]);
163
160
    if (reader_handle.frm_length)
164
161
    {
165
162
      char *ptr;
166
 
      ptr= (char *)my_malloc(sizeof(char) * reader_handle.frm_length, MYF(0));
 
163
      ptr= (char *)malloc(sizeof(char) * reader_handle.frm_length);
 
164
      if (ptr == NULL)
 
165
      {
 
166
        printf("Could not allocate enough memory\n");
 
167
        goto end;
 
168
      }
167
169
      azread_frm(&reader_handle, ptr);
168
170
      azwrite_frm(&writer_handle, ptr, reader_handle.frm_length);
169
171
      free(ptr);
172
174
    if (reader_handle.comment_length)
173
175
    {
174
176
      char *ptr;
175
 
      ptr= (char *)my_malloc(sizeof(char) * reader_handle.comment_length, MYF(0));
 
177
      ptr= (char *)malloc(sizeof(char) * reader_handle.comment_length);
176
178
      azread_comment(&reader_handle, ptr);
177
179
      azwrite_comment(&writer_handle, ptr, reader_handle.comment_length);
178
180
      free(ptr);
179
181
    }
180
182
 
181
 
    while ((read= azread_row(&reader_handle, &error)))
 
183
    while ((row_read= azread_row(&reader_handle, &error)))
182
184
    {
183
185
      if (error == Z_STREAM_ERROR || error)
184
186
      {
187
189
      }
188
190
 
189
191
      /* If we read nothing we are at the end of the file */
190
 
      if (read == 0)
 
192
      if (row_read == 0)
191
193
        break;
192
194
 
193
195
      row_count++;
194
196
 
195
 
      azwrite_row(&writer_handle, reader_handle.row_ptr, read);
 
197
      azwrite_row(&writer_handle, reader_handle.row_ptr, row_read);
196
198
 
197
199
      if (reader_handle.rows == writer_handle.rows)
198
200
        break;
207
209
  {
208
210
    File frm_file;
209
211
    char *ptr;
210
 
    frm_file= my_open(argv[1], O_CREAT|O_RDWR|O_BINARY, MYF(0));
211
 
    ptr= (char *)my_malloc(sizeof(char) * reader_handle.frm_length, MYF(0));
 
212
    frm_file= my_open(argv[1], O_CREAT|O_RDWR, MYF(0));
 
213
    ptr= (char *)malloc(sizeof(char) * reader_handle.frm_length);
 
214
    if (ptr == NULL)
 
215
    {
 
216
      printf("Could not allocate enough memory\n");
 
217
      goto end;
 
218
    }
212
219
    azread_frm(&reader_handle, ptr);
213
220
    my_write(frm_file, (unsigned char*) ptr, reader_handle.frm_length, MYF(0));
214
221
    my_close(frm_file, MYF(0));
223
230
  return 0;
224
231
}
225
232
 
226
 
static bool
227
 
get_one_option(int optid,
228
 
               const struct my_option *opt __attribute__((unused)),
229
 
               char *argument)
 
233
extern "C" bool
 
234
get_one_option(int optid, const struct my_option *opt, char *argument)
230
235
{
 
236
  (void)opt;
231
237
  switch (optid) {
232
238
  case 'b':
233
239
    opt_backup= 1;
313
319
       license\n");
314
320
  puts("Read and modify Archive files directly\n");
315
321
  printf("Usage: %s [OPTIONS] file_to_be_looked_at [file_for_backup]\n", my_progname);
316
 
  print_defaults("my", load_default_groups);
 
322
  print_defaults("drizzle", load_default_groups);
317
323
  my_print_help(my_long_options);
318
324
}
319
325
 
325
331
 
326
332
static void get_options(int *argc, char ***argv)
327
333
{
328
 
  load_defaults("my", load_default_groups, argc, argv);
 
334
  load_defaults("drizzle", load_default_groups, argc, argv);
329
335
  default_argv= *argv;
330
336
 
331
337
  handle_options(argc, argv, my_long_options, get_one_option);