~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/drizzled.cc

  • Committer: Brian Aker
  • Date: 2011-02-04 09:29:39 UTC
  • mfrom: (2139.3.6 catalogs)
  • mto: This revision was merged to the branch mainline in revision 2144.
  • Revision ID: brian@tangent.org-20110204092939-nlwrimamw0fxxhgl
Main bit of this patch is that Inno now just uses the identifier so we only
have one spot to make changes for paths.

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
 
158
158
namespace po=boost::program_options;
159
159
namespace dpo=drizzled::program_options;
160
160
 
161
 
bool opt_daemon= false;
162
161
 
163
162
namespace drizzled
164
163
{
308
307
fs::path system_config_dir(SYSCONFDIR);
309
308
 
310
309
 
 
310
char system_time_zone[30];
 
311
char *default_tz_name;
 
312
DRIZZLED_API char glob_hostname[FN_REFLEN];
 
313
 
311
314
char *opt_tc_log_file;
312
315
const key_map key_map_empty(0);
313
316
key_map key_map_full(0);                        // Will be initialized later
355
358
global_buffer_constraint<uint64_t> global_read_rnd_buffer(0);
356
359
global_buffer_constraint<uint64_t> global_read_buffer(0);
357
360
 
358
 
DRIZZLED_API size_t transaction_message_threshold;
 
361
/** 
 
362
  Refresh value. We use to test this to find out if a refresh even has happened recently.
 
363
*/
 
364
uint64_t refresh_version;  /* Increments on each reload */
 
365
 
 
366
/* Function declarations */
 
367
bool drizzle_rm_tmp_tables();
359
368
 
360
369
static void drizzle_init_variables(void);
361
370
static void get_options();
366
375
 
367
376
fs::path base_plugin_dir(PKGPLUGINDIR);
368
377
 
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"));
 
378
po::options_description config_options("Config File Options");
 
379
po::options_description long_options("Kernel Options");
 
380
po::options_description plugin_load_options("Plugin Loading Options");
 
381
po::options_description plugin_options("Plugin Options");
 
382
po::options_description initial_options("Config and Plugin Loading");
 
383
po::options_description full_options("Kernel and Plugin Loading and Plugin");
375
384
vector<string> unknown_options;
376
385
vector<string> defaults_file_list;
377
386
po::variables_map vm;
381
390
  return vm;
382
391
}
383
392
 
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
393
 
404
394
/****************************************************************************
405
395
** Code to end drizzled
665
655
 
666
656
static void find_plugin_dir(string progname)
667
657
{
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"))
 
658
  if (progname[0] != FN_LIBCHAR)
 
659
  {
 
660
    /* We have a relative path and need to find the absolute */
 
661
    char working_dir[FN_REFLEN];
 
662
    char *working_dir_ptr= working_dir;
 
663
    working_dir_ptr= getcwd(working_dir_ptr, FN_REFLEN);
 
664
    string new_path(working_dir);
 
665
    if (*(new_path.end()-1) != '/')
 
666
      new_path.push_back('/');
 
667
    if (progname[0] == '.' && progname[1] == '/')
 
668
      new_path.append(progname.substr(2));
 
669
    else
 
670
      new_path.append(progname);
 
671
    progname.swap(new_path);
 
672
  }
 
673
 
 
674
  /* Now, trim off the exe name */
 
675
  string progdir(progname.substr(0, progname.rfind(FN_LIBCHAR)+1));
 
676
  if (progdir.rfind(".libs/") != string::npos)
 
677
  {
 
678
    progdir.assign(progdir.substr(0, progdir.rfind(".libs/")));
 
679
  }
 
680
  string testlofile(progdir);
 
681
  testlofile.append("drizzled.lo");
 
682
  string testofile(progdir);
 
683
  testofile.append("drizzled.o");
 
684
  struct stat testfile_stat;
 
685
  if (not (stat(testlofile.c_str(), &testfile_stat) && stat(testofile.c_str(), &testfile_stat)))
677
686
  {
678
687
    /* We are in a source dir! Plugin dir is ../plugin/.libs */
679
 
    base_plugin_dir= progdir.parent_path();
 
688
    size_t last_libchar_pos= progdir.rfind(FN_LIBCHAR,progdir.size()-2)+1;
 
689
    base_plugin_dir= progdir.substr(0,last_libchar_pos);
680
690
    base_plugin_dir /= "plugin";
681
691
    base_plugin_dir /= ".libs";
682
692
  }
1006
1016
 
1007
1017
static void check_limits_transaction_message_threshold(size_t in_transaction_message_threshold)
1008
1018
{
1009
 
  transaction_message_threshold= 1024*1024;
 
1019
  global_system_variables.transaction_message_threshold= 1024*1024;
1010
1020
  if ((int64_t) in_transaction_message_threshold < 128*1024 || (int64_t)in_transaction_message_threshold > 1024*1024)
1011
1021
  {
1012
1022
    cout << _("Error: Invalid Value for transaction_message_threshold valid values are between 131072 - 1048576 bytes");
1013
1023
    exit(-1);
1014
1024
  }
1015
 
  transaction_message_threshold= in_transaction_message_threshold;
 
1025
  global_system_variables.transaction_message_threshold= in_transaction_message_threshold;
1016
1026
}
1017
1027
 
1018
1028
static void process_defaults_files()
1074
1084
  }
1075
1085
}
1076
1086
 
1077
 
int init_basic_variables(int argc, char **argv)
 
1087
int init_common_variables(int argc, char **argv, module::Registry &plugins)
1078
1088
{
1079
1089
  time_t curr_time;
1080
1090
  umask(((~internal::my_umask) & 0666));
1091
1101
  drizzle_init_variables();
1092
1102
 
1093
1103
  find_plugin_dir(argv[0]);
 
1104
  {
 
1105
    struct tm tm_tmp;
 
1106
    localtime_r(&server_start_time,&tm_tmp);
 
1107
    strncpy(system_time_zone, tzname[tm_tmp.tm_isdst != 0 ? 1 : 0],
 
1108
            sizeof(system_time_zone)-1);
1094
1109
 
 
1110
  }
1095
1111
  /*
1096
1112
    We set SYSTEM time zone as reasonable default and
1097
1113
    also for failure of my_tz_init() and bootstrap mode.
1100
1116
  */
1101
1117
  global_system_variables.time_zone= my_tz_SYSTEM;
1102
1118
 
1103
 
  char ret_hostname[FN_REFLEN];
1104
 
  if (gethostname(ret_hostname,sizeof(ret_hostname)) < 0)
 
1119
  if (gethostname(glob_hostname,sizeof(glob_hostname)) < 0)
1105
1120
  {
1106
 
    errmsg_printf(error::WARN,
1107
 
                  _("gethostname failed, using '%s' as hostname"),
1108
 
                  getServerHostname().c_str());
 
1121
    strncpy(glob_hostname, STRING_WITH_LEN("localhost"));
 
1122
    errmsg_printf(error::WARN, _("gethostname failed, using '%s' as hostname"),
 
1123
                  glob_hostname);
1109
1124
    pid_file= "drizzle";
1110
1125
  }
1111
1126
  else
1112
1127
  {
1113
 
    setServerHostname(ret_hostname);
1114
 
    pid_file= getServerHostname();
 
1128
    pid_file= glob_hostname;
1115
1129
  }
1116
1130
  pid_file.replace_extension(".pid");
1117
1131
 
1120
1134
  config_options.add_options()
1121
1135
  ("help,?", po::value<bool>(&opt_help)->default_value(false)->zero_tokens(),
1122
1136
  _("Display this help and exit."))
1123
 
  ("daemon,d", po::value<bool>(&opt_daemon)->default_value(false)->zero_tokens(),
1124
 
  _("Run as a daemon."))
1125
1137
  ("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1126
1138
  _("Configuration file defaults are not used if no-defaults is set"))
1127
1139
  ("defaults-file", po::value<vector<string> >()->composing()->notifier(&compose_defaults_file_list),
1199
1211
  _("Path for temporary files."))
1200
1212
  ("transaction-isolation", po::value<string>(),
1201
1213
  _("Default transaction isolation level."))
1202
 
  ("transaction-message-threshold", po::value<size_t>(&transaction_message_threshold)->default_value(1024*1024)->notifier(&check_limits_transaction_message_threshold),
 
1214
  ("transaction-message-threshold", po::value<size_t>(&global_system_variables.transaction_message_threshold)->default_value(1024*1024)->notifier(&check_limits_transaction_message_threshold),
1203
1215
  _("Max message size written to transaction log, valid values 131072 - 1048576 bytes."))
1204
1216
  ("user,u", po::value<string>(),
1205
1217
  _("Run drizzled daemon as user."))  
1305
1317
  po::value<uint64_t>(&global_system_variables.tmp_table_size)->default_value(16*1024*1024L)->notifier(&check_limits_tmp_table_size),
1306
1318
  _("If an internal in-memory temporary table exceeds this size, Drizzle will"
1307
1319
     " 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
1320
  ;
1311
1321
 
1312
1322
  full_options.add(long_options);
1399
1409
    unireg_abort(1);
1400
1410
  }
1401
1411
 
1402
 
  return 0;
1403
 
}
1404
 
 
1405
 
int init_remaining_variables(module::Registry &plugins)
1406
 
{
1407
 
  int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
1408
 
 
1409
 
  current_pid= getpid();                /* Save for later ref */
1410
 
 
1411
1412
  /* At this point, we've read all the options we need to read from files and
1412
1413
     collected most of them into unknown options - now let's load everything
1413
1414
  */
1487
1488
 
1488
1489
  fix_paths();
1489
1490
 
 
1491
  current_pid= getpid();                /* Save for later ref */
1490
1492
  init_time();                          /* Init time-functions (read zone) */
1491
1493
 
1492
1494
  if (item_create_init())
1721
1723
  {"help", '?', N_("Display this help and exit."),
1722
1724
   (char**) &opt_help, (char**) &opt_help, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1723
1725
   0, 0},
1724
 
  {"daemon", 'd', N_("Run as daemon."),
1725
 
   (char**) &opt_daemon, (char**) &opt_daemon, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1726
 
   0, 0},
1727
1726
  {"auto-increment-increment", OPT_AUTO_INCREMENT,
1728
1727
   N_("Auto-increment columns are incremented by this"),
1729
1728
   (char**) &global_system_variables.auto_increment_increment,
2237
2236
 
2238
2237
  if (vm.count("transaction-isolation"))
2239
2238
  {
2240
 
    int type= tx_isolation_typelib.find_type_or_exit(vm["transaction-isolation"].as<string>().c_str(), "transaction-isolation");
2241
 
    global_system_variables.tx_isolation= type - 1;
 
2239
    int type;
 
2240
    type= find_type_or_exit((char *)vm["transaction-isolation"].as<string>().c_str(), &tx_isolation_typelib, "transaction-isolation");
 
2241
    global_system_variables.tx_isolation= (type-1);
2242
2242
  }
2243
2243
 
2244
2244
  /* @TODO Make this all strings */