~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/internal/default.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:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/****************************************************************************
17
17
 Add all options from files named "group".cnf from the default_directories
33
33
 --print-defaults         ; Print the modified command line and exit
34
34
****************************************************************************/
35
35
 
36
 
#include <config.h>
 
36
#include "config.h"
37
37
 
38
 
#include <drizzled/internal/my_sys.h>
39
 
#include <drizzled/internal/m_string.h>
40
 
#include <drizzled/charset_info.h>
41
 
#include <drizzled/typelib.h>
 
38
#include "drizzled/internal/my_sys.h"
 
39
#include "drizzled/internal/m_string.h"
 
40
#include "drizzled/charset_info.h"
42
41
#include <drizzled/configmake.h>
43
42
#include <drizzled/gettext.h>
44
43
 
45
 
#include <drizzled/cached_directory.h>
 
44
#include "drizzled/cached_directory.h"
46
45
 
47
46
#ifdef HAVE_SYS_STAT_H
48
47
# include <sys/stat.h>
182
181
    TYPELIB *group= ctx->group;
183
182
 
184
183
    if (!(extra_groups=
185
 
          (const char**)ctx->alloc->alloc_root(
 
184
          (const char**)alloc_root(ctx->alloc,
186
185
                                   (2*group->count+1)*sizeof(char*))))
187
186
      goto err;
188
187
 
192
191
      extra_groups[i]= group->type_names[i]; /** copy group */
193
192
 
194
193
      len= strlen(extra_groups[i]);
195
 
      if (!(ptr= (char *)ctx->alloc->alloc_root( len+instance_len+1)))
 
194
      if (!(ptr= (char *)alloc_root(ctx->alloc, len+instance_len+1)))
196
195
        goto err;
197
196
 
198
197
      extra_groups[i+group->count]= ptr;
288
287
  if (!option)
289
288
    return 0;
290
289
 
291
 
  if (ctx->group->find_type(const_cast<char*>(group_name), 3))
 
290
  if (find_type((char *)group_name, ctx->group, 3))
292
291
  {
293
 
    if (!(tmp= (char *)ctx->alloc->alloc_root(strlen(option) + 1)))
 
292
    if (!(tmp= (char *)alloc_root(ctx->alloc, strlen(option) + 1)))
294
293
      return 1;
295
294
    if (insert_dynamic(ctx->args, (unsigned char*) &tmp))
296
295
      return 1;
325
324
  int org_argc= argc, prev_argc= 0;
326
325
  *defaults= *extra_defaults= *group_suffix= 0;
327
326
 
328
 
  const std::string DEFAULTS_FILE("--defaults-file=");
329
 
  const std::string DEFAULTS_EXTRA_FILE("--defaults-extra-file=");
330
 
  const std::string DEFAULTS_GROUP_SUFFIX("--defaults-group-suffix=");
331
 
 
332
327
  while (argc >= 2 && argc != prev_argc)
333
328
  {
334
329
    /* Skip program name or previously handled argument */
335
330
    argv++;
336
331
    prev_argc= argc;                            /* To check if we found */
337
 
    if (!*defaults && (strncmp(*argv,
338
 
                               DEFAULTS_FILE.c_str(),
339
 
                               DEFAULTS_FILE.size()) == 0))
 
332
    if (!*defaults && (strncmp(*argv,"--defaults-file=", sizeof("--defaults-file=")) == 0))
340
333
    {
341
 
      *defaults= *argv + DEFAULTS_FILE.size();
 
334
      *defaults= *argv + sizeof("--defaults-file=")-1;
342
335
       argc--;
343
336
       continue;
344
337
    }
345
 
    if (!*extra_defaults && (strncmp(*argv, 
346
 
                                     DEFAULTS_EXTRA_FILE.c_str(),
347
 
                                     DEFAULTS_EXTRA_FILE.size()) == 0))
 
338
    if (!*extra_defaults && (strncmp(*argv, "--defaults-extra-file=", sizeof("--defaults-extra-file=")) == 0))
348
339
    {
349
 
      *extra_defaults= *argv + DEFAULTS_EXTRA_FILE.size();
 
340
      *extra_defaults= *argv + sizeof("--defaults-extra-file=")-1;
350
341
      argc--;
351
342
      continue;
352
343
    }
353
 
    if (!*group_suffix && (strncmp(*argv, 
354
 
                                   DEFAULTS_GROUP_SUFFIX.c_str(),
355
 
                                   DEFAULTS_GROUP_SUFFIX.size()) == 0))
356
 
 
 
344
    if (!*group_suffix && (strncmp(*argv, "--defaults-group-suffix=", sizeof("--defaults-group-suffix=")) == 0))
357
345
    {
358
 
      *group_suffix= *argv + DEFAULTS_GROUP_SUFFIX.size();
 
346
      *group_suffix= *argv + sizeof("--defaults-group-suffix=")-1;
359
347
      argc--;
360
348
      continue;
361
349
    }
400
388
{
401
389
  DYNAMIC_ARRAY args;
402
390
  TYPELIB group;
 
391
  bool found_print_defaults= 0;
403
392
  uint32_t args_used= 0;
404
393
  int error= 0;
405
 
  memory::Root alloc(512);
 
394
  memory::Root alloc;
406
395
  char *ptr,**res;
407
396
  struct handle_option_ctx ctx;
408
397
 
409
398
  init_default_directories();
 
399
  init_alloc_root(&alloc,512);
410
400
  /*
411
401
    Check if the user doesn't want any default option processing
412
402
    --no-defaults is always the first option
415
405
  {
416
406
    /* remove the --no-defaults argument and return only the other arguments */
417
407
    uint32_t i;
418
 
    if (!(ptr=(char*) alloc.alloc_root(sizeof(alloc)+ (*argc + 1)*sizeof(char*))))
 
408
    if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+
 
409
                                 (*argc + 1)*sizeof(char*))))
419
410
      goto err;
420
411
    res= (char**) (ptr+sizeof(alloc));
421
412
    memset(res,0,(*argc + 1));
449
440
    Here error contains <> 0 only if we have a fully specified conf_file
450
441
    or a forced default file
451
442
  */
452
 
  if (!(ptr=(char*) alloc.alloc_root(sizeof(alloc)+ (args.elements + *argc +1) *sizeof(char*))))
 
443
  if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+
 
444
                               (args.elements + *argc +1) *sizeof(char*))))
453
445
    goto err;
454
446
  res= (char**) (ptr+sizeof(alloc));
455
447
 
464
456
    Check if we wan't to see the new argument list
465
457
    This options must always be the last of the default options
466
458
  */
 
459
  if (*argc >= 2 && !strcmp(argv[0][1],"--print-defaults"))
 
460
  {
 
461
    found_print_defaults=1;
 
462
    --*argc; ++*argv;                           /* skip argument */
 
463
  }
 
464
 
467
465
  if (*argc)
468
466
    memcpy(res+1+args.elements, *argv + 1, (*argc-1)*sizeof(char*));
469
467
  res[args.elements+ *argc]=0;                  /* last null */
472
470
  *argv= static_cast<char**>(res);
473
471
  *(memory::Root*) ptr= alloc;                  /* Save alloc root for free */
474
472
  delete_dynamic(&args);
475
 
 
 
473
  if (found_print_defaults)
 
474
  {
 
475
    int i;
 
476
    printf("%s would have been started with the following arguments:\n",
 
477
           **argv);
 
478
    for (i=1 ; i < *argc ; i++)
 
479
      printf("%s ", (*argv)[i]);
 
480
    puts("");
 
481
    exit(0);
 
482
  }
476
483
  return(error);
477
484
 
478
485
 err:
485
492
{
486
493
  memory::Root ptr;
487
494
  memcpy(&ptr, (char*) argv - sizeof(ptr), sizeof(ptr));
488
 
  ptr.free_root(MYF(0));
 
495
  free_root(&ptr,MYF(0));
489
496
}
490
497
 
491
498
 
937
944
    }
938
945
  }
939
946
  puts("\nThe following options may be given as the first argument:\n\
 
947
  --print-defaults      Print the program argument list and exit\n\
940
948
  --no-defaults         Don't read default options from any options file\n\
941
949
  --defaults-file=#     Only read default options from the given file #\n\
942
950
  --defaults-extra-file=# Read this file after the global files are read");
946
954
  This extra complexity is to avoid declaring 'rc' if it won't be
947
955
  used.
948
956
*/
949
 
static void add_directory(const char* dir)
950
 
{
951
 
  array_append_string_unique(dir, default_directories, array_elements(default_directories));
952
 
}
953
 
 
954
 
static void add_common_directories()
955
 
{
956
 
  const char *env= getenv("DRIZZLE_HOME"); 
957
 
  if (env) 
958
 
    add_directory(env); 
959
 
  // Placeholder for --defaults-extra-file=<path>
960
 
  add_directory(""); 
961
 
}
 
957
#define ADD_DIRECTORY(DIR)  (void) array_append_string_unique((DIR), default_directories, \
 
958
                             array_elements(default_directories))
 
959
 
 
960
#define ADD_COMMON_DIRECTORIES() \
 
961
  do { \
 
962
    const char *env; \
 
963
    if ((env= getenv("DRIZZLE_HOME"))) \
 
964
      ADD_DIRECTORY(env); \
 
965
    /* Placeholder for --defaults-extra-file=<path> */ \
 
966
    ADD_DIRECTORY(""); \
 
967
  } while (0)
 
968
 
962
969
 
963
970
/**
964
971
  Initialize default directories for Unix
975
982
static void init_default_directories(void)
976
983
{
977
984
  memset(default_directories, 0, sizeof(default_directories));
978
 
  add_directory("/etc/");
979
 
  add_directory("/etc/drizzle/");
980
 
  add_directory(SYSCONFDIR);
981
 
  add_common_directories();
982
 
  add_directory("~/");
 
985
  ADD_DIRECTORY("/etc/");
 
986
  ADD_DIRECTORY("/etc/drizzle/");
 
987
  ADD_DIRECTORY(SYSCONFDIR);
 
988
  ADD_COMMON_DIRECTORIES();
 
989
  ADD_DIRECTORY("~/");
983
990
}
984
991
 
985
992
} /* namespace internal */