~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/drizzled.cc

  • Committer: Lee Bieber
  • Date: 2011-02-11 20:30:05 UTC
  • mfrom: (2157.1.3 build)
  • Revision ID: kalebral@gmail.com-20110211203005-757o1y2yf78dxzqr
Merge Stewart - 716848: drizzleimport displays wrong program_name
Merge Stewart - update README file
Merge Andrew and Joe - Exposes the InnoDB SYS_REPLICATION_LOG to data_dictionary so that it is fast and fixes many issues we have been having

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
21
 
 
22
 
#include <drizzled/configmake.h>
23
 
#include <drizzled/atomics.h>
24
 
#include <drizzled/data_home.h>
 
20
#include "config.h"
 
21
#include "drizzled/configmake.h"
 
22
#include "drizzled/atomics.h"
 
23
#include "drizzled/data_home.h"
25
24
 
26
25
#include <netdb.h>
27
26
#include <sys/types.h>
32
31
#include <stdexcept>
33
32
 
34
33
#include <boost/program_options.hpp>
35
 
#include <drizzled/program_options/config_file.h>
 
34
#include "drizzled/program_options/config_file.h"
36
35
#include <boost/thread/recursive_mutex.hpp>
37
36
#include <boost/thread/mutex.hpp>
38
37
#include <boost/thread/shared_mutex.hpp>
40
39
#include <boost/filesystem.hpp>
41
40
#include <boost/detail/atomic_count.hpp>
42
41
 
43
 
#include <drizzled/cached_directory.h>
44
 
#include <drizzled/charset.h>
45
 
#include <drizzled/data_home.h>
46
 
#include <drizzled/debug.h>
47
 
#include <drizzled/definition/cache.h>
48
 
#include <drizzled/drizzled.h>
 
42
#include "drizzled/internal/my_sys.h"
 
43
#include "drizzled/internal/my_bit.h"
 
44
#include <drizzled/my_hash.h>
 
45
#include <drizzled/error.h>
49
46
#include <drizzled/errmsg_print.h>
50
 
#include <drizzled/error.h>
51
 
#include <drizzled/global_buffer.h>
52
 
#include <drizzled/internal/my_bit.h>
53
 
#include <drizzled/internal/my_sys.h>
 
47
#include <drizzled/tztime.h>
 
48
#include <drizzled/sql_base.h>
 
49
#include <drizzled/show.h>
 
50
#include <drizzled/sql_parse.h>
54
51
#include <drizzled/item/cmpfunc.h>
 
52
#include <drizzled/session.h>
55
53
#include <drizzled/item/create.h>
56
 
#include <drizzled/message/cache.h>
57
 
#include <drizzled/module/load_list.h>
58
 
#include <drizzled/module/registry.h>
59
 
#include <drizzled/my_hash.h>
60
 
#include <drizzled/plugin/client.h>
61
 
#include <drizzled/plugin/error_message.h>
62
 
#include <drizzled/plugin/event_observer.h>
63
 
#include <drizzled/plugin/listen.h>
64
 
#include <drizzled/plugin/monitored_in_transaction.h>
65
 
#include <drizzled/plugin/scheduler.h>
66
 
#include <drizzled/plugin/storage_engine.h>
67
 
#include <drizzled/plugin/xa_resource_manager.h>
68
 
#include <drizzled/probes.h>
69
 
#include <drizzled/replication_services.h> /* For ReplicationServices::evaluateRegisteredPlugins() */
70
 
#include <drizzled/session.h>
71
 
#include <drizzled/session/cache.h>
72
 
#include <drizzled/show.h>
73
 
#include <drizzled/sql_base.h>
74
 
#include <drizzled/sql_parse.h>
75
 
#include <drizzled/temporal_format.h> /* For init_temporal_formats() */
76
 
#include <drizzled/tztime.h>
77
54
#include <drizzled/unireg.h>
78
 
#include <plugin/myisam/myisam.h>
79
 
#include <drizzled/typelib.h>
80
 
#include <drizzled/visibility.h>
 
55
#include "drizzled/temporal_format.h" /* For init_temporal_formats() */
 
56
#include "drizzled/plugin/listen.h"
 
57
#include "drizzled/plugin/error_message.h"
 
58
#include "drizzled/plugin/client.h"
 
59
#include "drizzled/plugin/scheduler.h"
 
60
#include "drizzled/plugin/xa_resource_manager.h"
 
61
#include "drizzled/plugin/monitored_in_transaction.h"
 
62
#include "drizzled/replication_services.h" /* For ReplicationServices::evaluateRegisteredPlugins() */
 
63
#include "drizzled/probes.h"
 
64
#include "drizzled/session/cache.h"
 
65
#include "drizzled/charset.h"
 
66
#include "plugin/myisam/myisam.h"
 
67
#include "drizzled/drizzled.h"
 
68
#include "drizzled/module/registry.h"
 
69
#include "drizzled/module/load_list.h"
 
70
#include "drizzled/global_buffer.h"
 
71
 
 
72
#include "drizzled/debug.h"
 
73
 
 
74
#include "drizzled/definition/cache.h"
 
75
 
 
76
#include "drizzled/plugin/event_observer.h"
 
77
 
 
78
#include "drizzled/data_home.h"
 
79
 
 
80
#include "drizzled/message/cache.h"
 
81
 
 
82
#include "drizzled/visibility.h"
81
83
 
82
84
#include <google/protobuf/stubs/common.h>
83
85
 
84
 
#include <drizzled/refresh_version.h>
85
 
 
86
86
#if TIME_WITH_SYS_TIME
87
87
# include <sys/time.h>
88
88
# include <time.h>
102
102
 
103
103
#include <errno.h>
104
104
#include <sys/stat.h>
105
 
#include <drizzled/option.h>
 
105
#include "drizzled/option.h"
106
106
#ifdef HAVE_SYSENT_H
107
107
#include <sysent.h>
108
108
#endif
136
136
#include <sys/fpu.h>
137
137
#endif
138
138
 
139
 
#include <drizzled/internal/my_pthread.h>                       // For thr_setconcurency()
140
 
#include <drizzled/constrained_value.h>
 
139
#include "drizzled/internal/my_pthread.h"                       // For thr_setconcurency()
 
140
#include "drizzled/constrained_value.h"
141
141
 
142
142
#include <drizzled/gettext.h>
143
143
 
308
308
fs::path system_config_dir(SYSCONFDIR);
309
309
 
310
310
 
 
311
char system_time_zone[30];
 
312
char *default_tz_name;
 
313
DRIZZLED_API char glob_hostname[FN_REFLEN];
 
314
 
311
315
char *opt_tc_log_file;
312
316
const key_map key_map_empty(0);
313
317
key_map key_map_full(0);                        // Will be initialized later
357
361
 
358
362
DRIZZLED_API size_t transaction_message_threshold;
359
363
 
 
364
/** 
 
365
  Refresh value. We use to test this to find out if a refresh even has happened recently.
 
366
*/
 
367
uint64_t refresh_version;  /* Increments on each reload */
 
368
 
 
369
/* Function declarations */
 
370
bool drizzle_rm_tmp_tables();
 
371
 
360
372
static void drizzle_init_variables(void);
361
373
static void get_options();
362
374
static void fix_paths();
366
378
 
367
379
fs::path base_plugin_dir(PKGPLUGINDIR);
368
380
 
369
 
po::options_description config_options(_("Config File Options"));
370
 
po::options_description long_options(_("Kernel Options"));
371
 
po::options_description plugin_load_options(_("Plugin Loading Options"));
372
 
po::options_description plugin_options(_("Plugin Options"));
373
 
po::options_description initial_options(_("Config and Plugin Loading"));
374
 
po::options_description full_options(_("Kernel and Plugin Loading and Plugin"));
 
381
po::options_description config_options("Config File Options");
 
382
po::options_description long_options("Kernel Options");
 
383
po::options_description plugin_load_options("Plugin Loading Options");
 
384
po::options_description plugin_options("Plugin Options");
 
385
po::options_description initial_options("Config and Plugin Loading");
 
386
po::options_description full_options("Kernel and Plugin Loading and Plugin");
375
387
vector<string> unknown_options;
376
388
vector<string> defaults_file_list;
377
389
po::variables_map vm;
381
393
  return vm;
382
394
}
383
395
 
384
 
namespace
385
 
{
386
 
 
387
 
std::string &getGlobHostname()
388
 
{
389
 
  static std::string glob_hostname("localhost");
390
 
  return glob_hostname;
391
 
}
392
 
 
393
 
void setServerHostname(const std::string &hostname)
394
 
{
395
 
  getGlobHostname()= hostname;
396
 
}
397
 
}
398
 
 
399
 
const std::string &getServerHostname()
400
 
{
401
 
  return getGlobHostname();
402
 
}
403
396
 
404
397
/****************************************************************************
405
398
** Code to end drizzled
665
658
 
666
659
static void find_plugin_dir(string progname)
667
660
{
668
 
  fs::path full_progname(fs::system_complete(progname));
669
 
 
670
 
  fs::path progdir(full_progname.parent_path());
671
 
  if (progdir.filename() == ".libs")
672
 
  {
673
 
    progdir= progdir.parent_path();
674
 
  }
675
 
 
676
 
  if (fs::exists(progdir / "drizzled.lo") || fs::exists(progdir / "drizzled.o"))
 
661
  if (progname[0] != FN_LIBCHAR)
 
662
  {
 
663
    /* We have a relative path and need to find the absolute */
 
664
    char working_dir[FN_REFLEN];
 
665
    char *working_dir_ptr= working_dir;
 
666
    working_dir_ptr= getcwd(working_dir_ptr, FN_REFLEN);
 
667
    string new_path(working_dir);
 
668
    if (*(new_path.end()-1) != '/')
 
669
      new_path.push_back('/');
 
670
    if (progname[0] == '.' && progname[1] == '/')
 
671
      new_path.append(progname.substr(2));
 
672
    else
 
673
      new_path.append(progname);
 
674
    progname.swap(new_path);
 
675
  }
 
676
 
 
677
  /* Now, trim off the exe name */
 
678
  string progdir(progname.substr(0, progname.rfind(FN_LIBCHAR)+1));
 
679
  if (progdir.rfind(".libs/") != string::npos)
 
680
  {
 
681
    progdir.assign(progdir.substr(0, progdir.rfind(".libs/")));
 
682
  }
 
683
  string testlofile(progdir);
 
684
  testlofile.append("drizzled.lo");
 
685
  string testofile(progdir);
 
686
  testofile.append("drizzled.o");
 
687
  struct stat testfile_stat;
 
688
  if (not (stat(testlofile.c_str(), &testfile_stat) && stat(testofile.c_str(), &testfile_stat)))
677
689
  {
678
690
    /* We are in a source dir! Plugin dir is ../plugin/.libs */
679
 
    base_plugin_dir= progdir.parent_path();
 
691
    size_t last_libchar_pos= progdir.rfind(FN_LIBCHAR,progdir.size()-2)+1;
 
692
    base_plugin_dir= progdir.substr(0,last_libchar_pos);
680
693
    base_plugin_dir /= "plugin";
681
694
    base_plugin_dir /= ".libs";
682
695
  }
1091
1104
  drizzle_init_variables();
1092
1105
 
1093
1106
  find_plugin_dir(argv[0]);
 
1107
  {
 
1108
    struct tm tm_tmp;
 
1109
    localtime_r(&server_start_time,&tm_tmp);
 
1110
    strncpy(system_time_zone, tzname[tm_tmp.tm_isdst != 0 ? 1 : 0],
 
1111
            sizeof(system_time_zone)-1);
1094
1112
 
 
1113
  }
1095
1114
  /*
1096
1115
    We set SYSTEM time zone as reasonable default and
1097
1116
    also for failure of my_tz_init() and bootstrap mode.
1100
1119
  */
1101
1120
  global_system_variables.time_zone= my_tz_SYSTEM;
1102
1121
 
1103
 
  char ret_hostname[FN_REFLEN];
1104
 
  if (gethostname(ret_hostname,sizeof(ret_hostname)) < 0)
 
1122
  if (gethostname(glob_hostname,sizeof(glob_hostname)) < 0)
1105
1123
  {
1106
 
    errmsg_printf(error::WARN,
1107
 
                  _("gethostname failed, using '%s' as hostname"),
1108
 
                  getServerHostname().c_str());
 
1124
    strncpy(glob_hostname, STRING_WITH_LEN("localhost"));
 
1125
    errmsg_printf(error::WARN, _("gethostname failed, using '%s' as hostname"),
 
1126
                  glob_hostname);
1109
1127
    pid_file= "drizzle";
1110
1128
  }
1111
1129
  else
1112
1130
  {
1113
 
    setServerHostname(ret_hostname);
1114
 
    pid_file= getServerHostname();
 
1131
    pid_file= glob_hostname;
1115
1132
  }
1116
1133
  pid_file.replace_extension(".pid");
1117
1134
 
1305
1322
  po::value<uint64_t>(&global_system_variables.tmp_table_size)->default_value(16*1024*1024L)->notifier(&check_limits_tmp_table_size),
1306
1323
  _("If an internal in-memory temporary table exceeds this size, Drizzle will"
1307
1324
     " automatically convert it to an on-disk MyISAM table."))
1308
 
  ("verbose", po::value<std::string>()->default_value(error::verbose_string())->notifier(&error::check_verbosity),
1309
 
  _("The stack size for each thread."))
1310
1325
  ;
1311
1326
 
1312
1327
  full_options.add(long_options);