~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/archive/archive_reader.cc

This patch completes the first step in the splitting of
the XA resource manager API from the storage engine API,
as outlined in the specification here:

http://drizzle.org/wiki/XaStorageEngine

* Splits plugin::StorageEngine into a base StorageEngine
  class and two derived classes, TransactionalStorageEngine
  and XaStorageEngine.  XaStorageEngine derives from
  TransactionalStorageEngine and creates the XA Resource
  Manager API for storage engines.

  - The methods moved from StorageEngine to TransactionalStorageEngine
    include releaseTemporaryLatches(), startConsistentSnapshot(), 
    commit(), rollback(), setSavepoint(), releaseSavepoint(),
    rollbackToSavepoint() and hasTwoPhaseCommit()
  - The methods moved from StorageEngine to XaStorageEngine
    include recover(), commitXid(), rollbackXid(), and prepare()

* Places all static "EngineVector"s into their proper
  namespaces (typedefs belong in header files, not implementation files)
  and places all static methods corresponding
  to either only transactional engines or only XA engines
  into their respective files in /drizzled/plugin/

* Modifies the InnoDB "handler" files to extend plugin::XaStorageEngine
  and not plugin::StorageEngine

The next step, as outlined in the wiki spec page above, is to isolate
the XA Resource Manager API into its own plugin class and modify
plugin::XaStorageEngine to implement plugin::XaResourceManager via
composition.  This is necessary to enable building plugins which can
participate in an XA transaction *without having to have that plugin
implement the entire storage engine API*

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2006 MySQL AB
5
 
 *  Copyright (C) 2009 Sun Microsystems, Inc.
 
4
 *  Copyright (c) 2006 MySQL AB
 
5
 *  Copyright (c) 2009 Sun Microsystems, Inc.
6
6
 *
7
7
 *  This program is free software; you can redistribute it and/or modify
8
8
 *  it under the terms of the GNU General Public License as published by
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include <config.h>
22
 
#include <iostream>
23
 
#include <string>
24
 
#include <fstream>
25
 
#include <drizzled/configmake.h>
26
 
using namespace std;
27
 
#include <boost/program_options.hpp>
28
 
#include <boost/scoped_ptr.hpp>
29
 
namespace po= boost::program_options;
 
21
#include "config.h"
 
22
 
30
23
#include "azio.h"
31
24
#include <string.h>
32
25
#include <assert.h>
33
26
#include <stdio.h>
34
27
#include <stdarg.h>
35
28
#include <fcntl.h>
36
 
#include <memory>
37
 
#include <drizzled/charset_info.h>
38
 
#include <drizzled/internal/m_string.h>
 
29
#include "drizzled/charset_info.h"
 
30
#include "drizzled/internal/m_string.h"
 
31
#include "drizzled/my_getopt.h"
39
32
 
40
33
#define SHOW_VERSION "0.1"
41
34
 
42
35
using namespace drizzled;
43
36
 
44
 
string opt_tmpdir;
 
37
bool get_one_option(int optid, const struct my_option *opt, char *argument);
 
38
 
 
39
static void get_options(int *argc,char * * *argv);
 
40
static void print_version(void);
 
41
static void usage(void);
 
42
static const char *opt_tmpdir;
 
43
static const char *new_auto_increment;
45
44
uint64_t new_auto_increment_value;
46
 
bool opt_check, 
47
 
  opt_force,
48
 
  opt_backup, 
49
 
  opt_extract_table_message, 
50
 
  opt_silent,
51
 
  opt_quiet,
52
 
  opt_quick,
53
 
  opt_autoincrement;
 
45
static const char *load_default_groups[]= { "archive_reader", 0 };
 
46
static char **default_argv;
 
47
int opt_check, opt_force, opt_quiet, opt_backup= 0, opt_extract_table_message;
 
48
int opt_autoincrement;
54
49
 
55
50
int main(int argc, char *argv[])
56
51
{
57
 
try
58
 
{
59
 
  po::options_description commandline_options("Options used only in command line");
60
 
  commandline_options.add_options()
61
 
  ("force,f",po::value<bool>(&opt_force)->default_value(false)->zero_tokens(),
62
 
  "Restart with -r if there are any errors in the table")
63
 
  ("help,?","Display this help and exit")
64
 
  ("version,V","Print version and exit")
65
 
  ("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
66
 
  "Configuration file defaults are not used if no-defaults is set")
67
 
  ;
68
 
 
69
 
  po::options_description archive_reader_options("Options specific to the archive reader");
70
 
  archive_reader_options.add_options()
71
 
  ("tmpdir,t",po::value<string>(&opt_tmpdir)->default_value(""),
72
 
  "Path for temporary files.") 
73
 
  ("set-auto-increment,A",po::value<uint64_t>(&new_auto_increment_value)->default_value(0),
74
 
  "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.")
75
 
  ("silent,s",po::value<bool>(&opt_silent)->default_value(false)->zero_tokens(),
76
 
  "Only print errors. One can use two -s to make archive_reader very silent.")
77
 
  ("quick,q",po::value<bool>(&opt_quick)->default_value(false)->zero_tokens(),
78
 
  "Faster repair but not modifying the data")
79
 
  ("repair,r",po::value<bool>(&opt_quick)->default_value(false)->zero_tokens(),
80
 
  "Repair a damaged Archive version 3 or above file.")
81
 
  ("back-up,b",po::value<bool>(&opt_backup)->default_value(false)->zero_tokens(),
82
 
  "Make a backup of an archive table.")
83
 
  ("check,c",po::value<bool>(&opt_check)->default_value(false)->zero_tokens(),
84
 
  "Check table for errors")
85
 
  ("extract-table-message,e",po::value<bool>(&opt_extract_table_message)->default_value(false)->zero_tokens(),
86
 
  "Extract the table protobuf message.")
87
 
  ;
88
 
 
89
52
  unsigned int ret;
90
 
  boost::scoped_ptr<azio_stream> reader_handle_ap(new azio_stream);
91
 
  azio_stream &reader_handle= *reader_handle_ap.get();
92
 
 
93
 
  std::string system_config_dir_archive_reader(SYSCONFDIR); 
94
 
  system_config_dir_archive_reader.append("/drizzle/archive_reader.cnf");
95
 
 
96
 
  std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
97
 
 
98
 
  if (user_config_dir.compare(0, 2, "~/") == 0)
99
 
  {
100
 
    char *homedir;
101
 
    homedir= getenv("HOME");
102
 
    if (homedir != NULL)
103
 
      user_config_dir.replace(0, 1, homedir);
104
 
  }
105
 
  
106
 
  po::options_description long_options("Allowed Options");
107
 
  long_options.add(commandline_options).add(archive_reader_options);
108
 
 
109
 
  po::variables_map vm;
110
 
  po::store(po::parse_command_line(argc,argv,long_options),vm);
111
 
 
112
 
  if (! vm["no-defaults"].as<bool>())
113
 
  {
114
 
    std::string user_config_dir_archive_reader(user_config_dir);
115
 
    user_config_dir_archive_reader.append("/drizzle/archive_reader.cnf");
116
 
  
117
 
    ifstream user_archive_reader_ifs(user_config_dir_archive_reader.c_str());
118
 
    po::store(parse_config_file(user_archive_reader_ifs, archive_reader_options), vm);
119
 
 
120
 
    ifstream system_archive_reader_ifs(system_config_dir_archive_reader.c_str());
121
 
    store(parse_config_file(system_archive_reader_ifs, archive_reader_options), vm);
122
 
 
123
 
  }
124
 
  po::notify(vm);
125
 
 
126
 
  if (vm.count("force") || vm.count("quiet") || vm.count("tmpdir"))
127
 
    cout << "Not implemented yet";
128
 
 
129
 
  if (vm.count("version"))
130
 
  {
131
 
    printf("%s  Ver %s, for %s-%s (%s)\n", internal::my_progname, SHOW_VERSION,
132
 
        HOST_VENDOR, HOST_OS, HOST_CPU);
133
 
    exit(0);
134
 
  }
135
 
  
136
 
  if (vm.count("set-auto-increment"))
137
 
  {
138
 
    opt_autoincrement= true;
139
 
  }
140
 
 
141
 
  if (vm.count("help") || argc == 0)
142
 
  {
143
 
    printf("%s  Ver %s, for %s-%s (%s)\n", internal::my_progname, SHOW_VERSION,
144
 
        HOST_VENDOR, HOST_OS, HOST_CPU);
145
 
    puts("This software comes with ABSOLUTELY NO WARRANTY. This is free "
146
 
         "software,\n"
147
 
         "and you are welcome to modify and redistribute it under the GPL "
148
 
         "license\n");
149
 
    puts("Read and modify Archive files directly\n");
150
 
    printf("Usage: %s [OPTIONS] file_to_be_looked_at [file_for_backup]\n", internal::my_progname);
151
 
    cout << long_options << endl;    
152
 
    exit(0); 
153
 
  }
154
 
  
 
53
  azio_stream reader_handle;
 
54
 
 
55
  internal::my_init();
 
56
  MY_INIT(argv[0]);
 
57
  get_options(&argc, &argv);
 
58
 
155
59
  if (argc < 1)
156
60
  {
157
61
    printf("No file specified. \n");
158
 
    return -1;
 
62
    return 0;
159
63
  }
160
64
 
161
65
  if (!(ret= azopen(&reader_handle, argv[0], O_RDONLY, AZ_METHOD_BLOCK)))
162
66
  {
163
67
    printf("Could not open Archive file\n");
164
 
    return -1;
 
68
    return 0;
165
69
  }
166
70
 
167
71
  if (opt_autoincrement)
168
72
  {
169
 
    boost::scoped_ptr<azio_stream> writer_handle_ap(new azio_stream);
170
 
    azio_stream &writer_handle= *writer_handle_ap.get();
 
73
    azio_stream writer_handle;
171
74
 
172
75
    if (new_auto_increment_value)
173
76
    {
264
167
    uint64_t row_count= 0;
265
168
    char *buffer;
266
169
 
267
 
    boost::scoped_ptr<azio_stream> writer_handle_ap(new azio_stream);
268
 
    azio_stream &writer_handle= *writer_handle_ap.get();
 
170
    azio_stream writer_handle;
269
171
 
270
172
    buffer= (char *)malloc(reader_handle.longest_row);
271
173
    if (buffer == NULL)
353
255
  azclose(&reader_handle);
354
256
 
355
257
  internal::my_end();
356
 
 
357
 
}
358
 
  catch(exception &e)
 
258
  return 0;
 
259
}
 
260
 
 
261
bool get_one_option(int optid, const struct my_option *opt, char *argument)
 
262
{
 
263
  (void)opt;
 
264
  switch (optid) {
 
265
  case 'b':
 
266
    opt_backup= 1;
 
267
    break;
 
268
  case 'c':
 
269
    opt_check= 1;
 
270
    break;
 
271
  case 'e':
 
272
    opt_extract_table_message= 1;
 
273
    break;
 
274
  case 'f':
 
275
    opt_force= 1;
 
276
    printf("Not implemented yet\n");
 
277
    break;
 
278
  case 'q':
 
279
    opt_quiet= 1;
 
280
    printf("Not implemented yet\n");
 
281
    break;
 
282
  case 'V':
 
283
    print_version();
 
284
    exit(0);
 
285
  case 't':
 
286
    printf("Not implemented yet\n");
 
287
    break;
 
288
  case 'A':
 
289
    opt_autoincrement= 1;
 
290
    if (argument)
 
291
      new_auto_increment_value= strtoull(argument, NULL, 0);
 
292
    else
 
293
      new_auto_increment_value= 0;
 
294
    break;
 
295
  case '?':
 
296
    usage();
 
297
    exit(0);
 
298
  }
 
299
  return 0;
 
300
}
 
301
 
 
302
static struct my_option my_long_options[] =
 
303
{
 
304
  {"backup", 'b',
 
305
   "Make a backup of an archive table.",
 
306
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
307
  {"check", 'c', "Check table for errors.",
 
308
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
309
  {"extract-table-message", 'e',
 
310
   "Extract the table protobuf message.",
 
311
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
312
  {"force", 'f',
 
313
   "Restart with -r if there are any errors in the table.",
 
314
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
315
  {"help", '?',
 
316
   "Display this help and exit.",
 
317
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
318
  {"quick", 'q', "Faster repair by not modifying the data file.",
 
319
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
320
  {"repair", 'r', "Repair a damaged Archive version 3 or above file.",
 
321
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
322
  {"set-auto-increment", 'A',
 
323
   "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.",
 
324
   (char**) &new_auto_increment,
 
325
   (char**) &new_auto_increment,
 
326
   0, GET_ULL, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
327
  {"silent", 's',
 
328
   "Only print errors. One can use two -s to make archive_reader very silent.",
 
329
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
330
  {"tmpdir", 't',
 
331
   "Path for temporary files.",
 
332
   (char**) &opt_tmpdir,
 
333
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
334
  {"version", 'V',
 
335
   "Print version and exit.",
 
336
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
337
  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
 
338
};
 
339
 
 
340
static void usage(void)
 
341
{
 
342
  print_version();
 
343
  puts("Copyright (C) 2007 MySQL AB");
 
344
  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\
 
345
       \nand you are welcome to modify and redistribute it under the GPL \
 
346
       license\n");
 
347
  puts("Read and modify Archive files directly\n");
 
348
  printf("Usage: %s [OPTIONS] file_to_be_looked_at [file_for_backup]\n", internal::my_progname);
 
349
  internal::print_defaults("drizzle", load_default_groups);
 
350
  my_print_help(my_long_options);
 
351
}
 
352
 
 
353
static void print_version(void)
 
354
{
 
355
  printf("%s  Ver %s, for %s-%s (%s)\n", internal::my_progname, SHOW_VERSION,
 
356
         HOST_VENDOR, HOST_OS, HOST_CPU);
 
357
}
 
358
 
 
359
static void get_options(int *argc, char ***argv)
 
360
{
 
361
  internal::load_defaults("drizzle", load_default_groups, argc, argv);
 
362
  default_argv= *argv;
 
363
 
 
364
  handle_options(argc, argv, my_long_options, get_one_option);
 
365
 
 
366
  if (*argc == 0)
359
367
  {
360
 
    cerr<<"Error"<<e.what()<<endl;
 
368
    usage();
 
369
    exit(-1);
361
370
  }
362
 
  return 0;
363
 
}
364
371
 
 
372
  return;
 
373
} /* get options */