63
63
#include <drizzled/session/cache.h>
64
64
#include <drizzled/signal_handler.h>
65
65
#include <drizzled/transaction_services.h>
66
#include <drizzled/tztime.h>
66
67
#include <drizzled/unireg.h>
67
68
#include <drizzled/util/backtrace.h>
68
#include <drizzled/current_session.h>
69
#include <drizzled/daemon.h>
70
#include <drizzled/diagnostics_area.h>
71
#include <drizzled/sql_base.h>
72
#include <drizzled/sql_lex.h>
73
#include <drizzled/system_variables.h>
75
70
using namespace drizzled;
76
71
using namespace std;
72
namespace fs=boost::filesystem;
78
74
static pthread_t select_thread;
79
75
static uint32_t thr_kill_signal;
81
extern bool opt_daemon;
85
79
All global error messages are sent here where the first one is stored
88
82
static void my_message_sql(drizzled::error_t error, const char *str, myf MyFlags)
90
Session* session= current_session;
92
86
Put here following assertion when situation with EE_* error codes
89
if ((session= current_session))
97
91
if (MyFlags & ME_FATALERROR)
98
92
session->is_fatal_error= 1;
101
95
@TODO There are two exceptions mechanism (Session and sp_rcontext),
102
96
this could be improved by having a common stack of handlers.
104
98
if (session->handle_error(error, str, DRIZZLE_ERROR::WARN_LEVEL_ERROR))
109
session->lex().current_select == 0 if lex structure is not inited
102
session->lex->current_select == 0 if lex structure is not inited
110
103
(not query command (COM_QUERY))
112
if (! (session->lex().current_select &&
113
session->lex().current_select->no_error && !session->is_fatal_error))
105
if (! (session->lex->current_select &&
106
session->lex->current_select->no_error && !session->is_fatal_error))
115
if (! session->main_da().is_error()) // Return only first message
108
if (! session->main_da.is_error()) // Return only first message
117
110
if (error == EE_OK)
118
111
error= ER_UNKNOWN_ERROR;
252
245
/* Function generates error messages before abort */
253
246
error_handler_hook= my_message_sql;
255
247
/* init_common_variables must get basic settings such as data_home_dir
256
248
and plugin_load_list. */
257
if (init_basic_variables(argc, argv))
258
unireg_abort(1); // Will do exit
262
if (signal(SIGHUP, SIG_IGN) == SIG_ERR)
264
perror("Failed to ignore SIGHUP");
268
fprintf(stderr, "failed to daemon() in order to daemonize\n");
273
if (init_remaining_variables(modules))
249
if (init_common_variables(argc, argv, modules))
274
250
unireg_abort(1); // Will do exit
292
268
getDataHome().file_string().c_str());
296
ifstream old_uuid_file ("server.uuid");
297
if (old_uuid_file.is_open())
299
getline (old_uuid_file, server_uuid);
300
old_uuid_file.close();
305
char uuid_string[37];
306
uuid_generate_random(uu);
307
uuid_unparse(uu, uuid_string);
308
ofstream new_uuid_file ("server.uuid");
309
new_uuid_file << uuid_string;
310
new_uuid_file.close();
311
server_uuid= string(uuid_string);
314
271
if (mkdir("local", 0700))
316
273
/* We don't actually care */
326
boost::filesystem::path &full_data_home= getFullDataHome();
327
full_data_home= boost::filesystem::system_complete(getDataHome());
328
errmsg_printf(error::INFO, "Data Home directory is : %s", full_data_home.native_file_string().c_str());
283
fs::path &full_data_home= getFullDataHome();
284
full_data_home= fs::system_complete(getDataHome());
285
std::cerr << "home " << full_data_home << std::endl;
331
290
if (server_id == 0)
370
329
assert(plugin::num_trx_monitored_objects > 0);
371
drizzle_rm_tmp_tables();
372
errmsg_printf(error::INFO, _(ER(ER_STARTUP)), internal::my_progname, PANDORA_RELEASE_VERSION, COMPILATION_COMMENT);
330
if (drizzle_rm_tmp_tables() || my_tz_init((Session *)0, default_tz_name))
333
select_thread_in_use=0;
334
(void) pthread_kill(signal_thread, SIGTERM);
336
(void) unlink(pid_file.file_string().c_str()); // Not needed anymore
341
errmsg_printf(error::INFO, _(ER(ER_STARTUP)), internal::my_progname,
342
PANDORA_RELEASE_VERSION, COMPILATION_COMMENT);
375
345
TransactionServices &transaction_services= TransactionServices::singleton();
377
347
/* Send server startup event */
379
Session::shared_ptr session= Session::make_shared(plugin::Listen::getNullClient(), catalog::local());
380
currentSession().reset(session.get());
381
transaction_services.sendStartupEvent(*session);
382
plugin_startup_window(modules, *session.get());
349
Session::shared_ptr session;
351
if ((session= Session::make_shared(plugin::Listen::getNullClient(), catalog::local())))
353
currentSession().release();
354
currentSession().reset(session.get());
357
transaction_services.sendStartupEvent(*session);
359
plugin_startup_window(modules, *(session.get()));
389
365
Listen for new connections and start new session for each connection
390
366
accepted. The listen.getClient() method will return NULL when the server
391
367
should be shutdown.
393
while (plugin::Client* client= plugin::Listen::getClient())
369
plugin::Client *client;
370
while ((client= plugin::Listen::getClient()) != NULL)
395
Session::shared_ptr session= Session::make_shared(client, client->catalog());
372
Session::shared_ptr session;
373
session= Session::make_shared(client, client->catalog());
397
381
/* If we error on creation we drop the connection and delete the session. */
398
382
if (Session::schedule(session))
402
386
/* Send server shutdown event */
404
Session::shared_ptr session= Session::make_shared(plugin::Listen::getNullClient(), catalog::local());
405
currentSession().reset(session.get());
406
transaction_services.sendShutdownEvent(*session.get());
388
Session::shared_ptr session;
390
if ((session= Session::make_shared(plugin::Listen::getNullClient(), catalog::local())))
392
currentSession().release();
393
currentSession().reset(session.get());
394
transaction_services.sendShutdownEvent(*session.get());
410
boost::mutex::scoped_lock scopedLock(session::Cache::mutex());
399
boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
411
400
select_thread_in_use= false; // For close_connections
413
402
COND_thread_count.notify_all();
415
404
/* Wait until cleanup is done */
416
session::Cache::shutdownSecond();
405
session::Cache::singleton().shutdownSecond();
419
408
module::Registry::shutdown();