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>
70
extern "C" int daemonize(int nochdir, int noclose, int wait_sigusr1);
71
extern "C" int daemon_is_ready(void);
75
73
using namespace drizzled;
76
74
using namespace std;
75
namespace fs=boost::filesystem;
78
77
static pthread_t select_thread;
79
78
static uint32_t thr_kill_signal;
88
87
static void my_message_sql(drizzled::error_t error, const char *str, myf MyFlags)
90
Session* session= current_session;
92
91
Put here following assertion when situation with EE_* error codes
94
if ((session= current_session))
97
96
if (MyFlags & ME_FATALERROR)
98
97
session->is_fatal_error= 1;
101
100
@TODO There are two exceptions mechanism (Session and sp_rcontext),
102
101
this could be improved by having a common stack of handlers.
104
103
if (session->handle_error(error, str, DRIZZLE_ERROR::WARN_LEVEL_ERROR))
109
session->lex().current_select == 0 if lex structure is not inited
107
session->lex->current_select == 0 if lex structure is not inited
110
108
(not query command (COM_QUERY))
112
if (! (session->lex().current_select &&
113
session->lex().current_select->no_error && !session->is_fatal_error))
110
if (! (session->lex->current_select &&
111
session->lex->current_select->no_error && !session->is_fatal_error))
115
if (! session->main_da().is_error()) // Return only first message
113
if (! session->main_da.is_error()) // Return only first message
117
115
if (error == EE_OK)
118
116
error= ER_UNKNOWN_ERROR;
264
262
perror("Failed to ignore SIGHUP");
264
if (daemonize(1, 1, 1) == -1)
268
266
fprintf(stderr, "failed to daemon() in order to daemonize\n");
269
267
exit(EXIT_FAILURE);
292
290
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
293
if (mkdir("local", 0700))
316
295
/* 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());
305
fs::path &full_data_home= getFullDataHome();
306
full_data_home= fs::system_complete(getDataHome());
307
std::cerr << "home " << full_data_home << std::endl;
331
312
if (server_id == 0)
370
351
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);
352
if (drizzle_rm_tmp_tables() || my_tz_init((Session *)0, default_tz_name))
355
select_thread_in_use=0;
356
(void) pthread_kill(signal_thread, SIGTERM);
358
(void) unlink(pid_file.file_string().c_str()); // Not needed anymore
363
errmsg_printf(error::INFO, _(ER(ER_STARTUP)), internal::my_progname,
364
PANDORA_RELEASE_VERSION, COMPILATION_COMMENT);
375
367
TransactionServices &transaction_services= TransactionServices::singleton();
377
369
/* 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());
371
Session::shared_ptr session;
373
if ((session= Session::make_shared(plugin::Listen::getNullClient(), catalog::local())))
375
currentSession().release();
376
currentSession().reset(session.get());
379
transaction_services.sendStartupEvent(*session);
381
plugin_startup_window(modules, *(session.get()));
386
386
daemon_is_ready();
389
389
Listen for new connections and start new session for each connection
390
390
accepted. The listen.getClient() method will return NULL when the server
391
391
should be shutdown.
393
while (plugin::Client* client= plugin::Listen::getClient())
393
plugin::Client *client;
394
while ((client= plugin::Listen::getClient()) != NULL)
395
Session::shared_ptr session= Session::make_shared(client, client->catalog());
396
Session::shared_ptr session;
397
session= Session::make_shared(client, client->catalog());
397
405
/* If we error on creation we drop the connection and delete the session. */
398
406
if (Session::schedule(session))
402
410
/* 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());
412
Session::shared_ptr session;
414
if ((session= Session::make_shared(plugin::Listen::getNullClient(), catalog::local())))
416
currentSession().release();
417
currentSession().reset(session.get());
418
transaction_services.sendShutdownEvent(*session.get());
410
boost::mutex::scoped_lock scopedLock(session::Cache::mutex());
423
boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
411
424
select_thread_in_use= false; // For close_connections
413
426
COND_thread_count.notify_all();
415
428
/* Wait until cleanup is done */
416
session::Cache::shutdownSecond();
429
session::Cache::singleton().shutdownSecond();
419
432
module::Registry::shutdown();