~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/main.cc

  • Committer: Monty Taylor
  • Date: 2010-09-26 21:24:15 UTC
  • mto: (1796.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1797.
  • Revision ID: mordred@inaugust.com-20100926212415-5fn3p3q75pgiei7r
Moved protocol doc into the docs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
48
48
#include "drizzled/gettext.h"
49
49
#include "drizzled/configmake.h"
50
50
#include "drizzled/session.h"
51
 
#include "drizzled/session/cache.h"
52
51
#include "drizzled/internal/my_sys.h"
53
52
#include "drizzled/unireg.h"
54
53
#include "drizzled/drizzled.h"
60
59
#include "drizzled/tztime.h"
61
60
#include "drizzled/signal_handler.h"
62
61
#include "drizzled/replication_services.h"
63
 
#include "drizzled/transaction_services.h"
64
 
 
65
 
#include "drizzled/util/backtrace.h"
66
62
 
67
63
using namespace drizzled;
68
64
using namespace std;
205
201
  (void)filename;
206
202
  (void)line;
207
203
  (void)message;
208
 
  std::cerr << "\n";
209
 
  drizzled::util::custom_backtrace();
210
 
  std::cerr << "\n";
211
204
  switch(level)
212
205
  {
213
206
  case google::protobuf::LOGLEVEL_INFO:
216
209
  case google::protobuf::LOGLEVEL_ERROR:
217
210
  case google::protobuf::LOGLEVEL_FATAL:
218
211
  default:
219
 
    std::cerr << "GoogleProtoErrorThrower(" << filename << ", " << line << ", " << message << ")";
220
212
    throw("error in google protocol buffer parsing");
221
213
  }
222
214
}
233
225
 
234
226
  module::Registry &modules= module::Registry::singleton();
235
227
  plugin::Client *client;
 
228
  Session *session;
236
229
 
237
230
  MY_INIT(argv[0]);             // init my_sys library & pthreads
238
231
  /* nothing should come before this line ^^^ */
243
236
  google::protobuf::SetLogHandler(&GoogleProtoErrorThrower);
244
237
 
245
238
  /* Function generates error messages before abort */
246
 
  error_handler_hook= my_message_sql;
247
239
  /* init_common_variables must get basic settings such as data_home_dir
248
240
     and plugin_load_list. */
249
 
  if (init_common_variables(argc, argv, modules))
 
241
  if (init_common_variables(argc, argv))
250
242
    unireg_abort(1);                            // Will do exit
251
243
 
252
 
  /*
253
 
    init signals & alarm
254
 
    After this we can't quit by a simple unireg_abort
255
 
  */
256
244
  init_signals();
257
245
 
258
246
 
261
249
 
262
250
  if (not opt_help)
263
251
  {
264
 
    if (chdir(getDataHome().file_string().c_str()))
 
252
    if (chdir(getDataHome().c_str()))
265
253
    {
266
254
      errmsg_printf(ERRMSG_LVL_ERROR,
267
255
                    _("Data directory %s does not exist\n"),
268
 
                    getDataHome().file_string().c_str());
 
256
                    getDataHome().c_str());
269
257
      unireg_abort(1);
270
258
    }
271
259
    if (mkdir("local", 0700))
276
264
    {
277
265
      errmsg_printf(ERRMSG_LVL_ERROR,
278
266
                    _("Local catalog %s/local does not exist\n"),
279
 
                    getDataHome().file_string().c_str());
 
267
                    getDataHome().c_str());
280
268
      unireg_abort(1);
281
269
    }
282
 
 
283
 
    full_data_home= fs::system_complete(getDataHome());
 
270
    /* TODO: This is a hack until we can properly support std::string in sys_var*/
 
271
    char **data_home_ptr= getDatadirPtr();
 
272
    *data_home_ptr= new char[getDataHome().size()+1] ();
 
273
    fs::path full_data_home_path(fs::system_complete(fs::path(getDataHome())));
 
274
    std::string full_data_home(full_data_home_path.file_string());
 
275
    memcpy(*data_home_ptr, full_data_home.c_str(), full_data_home.size());
284
276
    getDataHomeCatalog()= "./";
285
277
    getDataHome()= "../";
286
278
  }
312
304
  if (plugin::Listen::setup())
313
305
    unireg_abort(1);
314
306
 
 
307
  /*
 
308
    init signals & alarm
 
309
    After this we can't quit by a simple unireg_abort
 
310
  */
 
311
  error_handler_hook= my_message_sql;
315
312
 
316
313
  assert(plugin::num_trx_monitored_objects > 0);
317
314
  if (drizzle_rm_tmp_tables() ||
321
318
    select_thread_in_use=0;
322
319
    (void) pthread_kill(signal_thread, SIGTERM);
323
320
 
324
 
    (void) unlink(pid_file.file_string().c_str());      // Not needed anymore
 
321
    (void) unlink(pidfile_name);        // Not needed anymore
325
322
 
326
323
    exit(1);
327
324
  }
330
327
                PANDORA_RELEASE_VERSION, COMPILATION_COMMENT);
331
328
 
332
329
 
333
 
  TransactionServices &transaction_services= TransactionServices::singleton();
334
 
 
335
 
  /* Send server startup event */
336
 
  {
337
 
    Session *session;
338
 
 
339
 
    if ((session= new Session(plugin::Listen::getNullClient())))
340
 
    {
341
 
      currentSession().release();
342
 
      currentSession().reset(session);
343
 
      transaction_services.sendStartupEvent(session);
344
 
      delete session;
345
 
    }
346
 
  }
347
 
 
348
 
 
349
330
  /* Listen for new connections and start new session for each connection
350
331
     accepted. The listen.getClient() method will return NULL when the server
351
332
     should be shutdown. */
352
333
  while ((client= plugin::Listen::getClient()) != NULL)
353
334
  {
354
 
    Session::shared_ptr session(new Session(client));
355
 
 
356
 
    if (not session)
 
335
    if (!(session= new Session(client)))
357
336
    {
358
337
      delete client;
359
338
      continue;
360
339
    }
361
340
 
362
341
    /* If we error on creation we drop the connection and delete the session. */
363
 
    if (Session::schedule(session))
 
342
    if (session->schedule())
364
343
      Session::unlink(session);
365
344
  }
366
345
 
367
 
  /* Send server shutdown event */
368
 
  {
369
 
    Session *session;
370
 
 
371
 
    if ((session= new Session(plugin::Listen::getNullClient())))
372
 
    {
373
 
      currentSession().release();
374
 
      currentSession().reset(session);
375
 
      transaction_services.sendShutdownEvent(session);
376
 
      delete session;
377
 
    }
378
 
  }
379
 
 
380
 
  {
381
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
382
 
    select_thread_in_use= false;                        // For close_connections
383
 
  }
 
346
  LOCK_thread_count.lock();
 
347
  select_thread_in_use=0;                       // For close_connections
 
348
  LOCK_thread_count.unlock();
384
349
  COND_thread_count.notify_all();
385
350
 
386
351
  /* Wait until cleanup is done */
387
 
  {
388
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
389
 
    while (not ready_to_exit)
390
 
      COND_server_end.wait(scopedLock);
391
 
  }
 
352
  LOCK_thread_count.lock();
 
353
  while (!ready_to_exit)
 
354
    pthread_cond_wait(COND_server_end.native_handle(), LOCK_thread_count.native_handle());
 
355
  LOCK_thread_count.unlock();
392
356
 
393
357
  clean_up(1);
394
358
  module::Registry::shutdown();
395
359
  internal::my_end();
396
 
 
397
360
  return 0;
398
361
}
399
362