~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/main.cc

  • Committer: Brian Aker
  • Date: 2010-09-15 20:24:31 UTC
  • mto: (1766.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1767.
  • Revision ID: brian@tangent.org-20100915202431-wbrrl4vg6rzjvdiu
Adding opt for optional schedulers and making them --plugin-add only.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <signal.h>
24
24
#include <sys/resource.h>
25
25
#include <unistd.h>
26
 
#include <sys/stat.h>
27
 
#include <sys/types.h>
28
 
 
29
26
 
30
27
#if TIME_WITH_SYS_TIME
31
28
# include <sys/time.h>
42
39
# include <locale.h>
43
40
#endif
44
41
 
45
 
#include <boost/filesystem.hpp>
46
42
 
47
43
#include "drizzled/plugin.h"
48
44
#include "drizzled/gettext.h"
49
45
#include "drizzled/configmake.h"
50
46
#include "drizzled/session.h"
51
 
#include "drizzled/session/cache.h"
52
47
#include "drizzled/internal/my_sys.h"
53
48
#include "drizzled/unireg.h"
54
49
#include "drizzled/drizzled.h"
60
55
#include "drizzled/tztime.h"
61
56
#include "drizzled/signal_handler.h"
62
57
#include "drizzled/replication_services.h"
63
 
#include "drizzled/transaction_services.h"
64
 
 
65
 
#include "drizzled/util/backtrace.h"
66
58
 
67
59
using namespace drizzled;
68
60
using namespace std;
69
 
namespace fs=boost::filesystem;
70
61
 
71
62
static pthread_t select_thread;
72
63
static uint32_t thr_kill_signal;
73
64
 
74
 
 
75
65
/**
76
66
  All global error messages are sent here where the first one is stored
77
67
  for the client.
205
195
  (void)filename;
206
196
  (void)line;
207
197
  (void)message;
208
 
  std::cerr << "\n";
209
 
  drizzled::util::custom_backtrace();
210
 
  std::cerr << "\n";
211
198
  switch(level)
212
199
  {
213
200
  case google::protobuf::LOGLEVEL_INFO:
216
203
  case google::protobuf::LOGLEVEL_ERROR:
217
204
  case google::protobuf::LOGLEVEL_FATAL:
218
205
  default:
219
 
    std::cerr << "GoogleProtoErrorThrower(" << filename << ", " << line << ", " << message << ")";
220
206
    throw("error in google protocol buffer parsing");
221
207
  }
222
208
}
233
219
 
234
220
  module::Registry &modules= module::Registry::singleton();
235
221
  plugin::Client *client;
 
222
  Session *session;
236
223
 
237
224
  MY_INIT(argv[0]);             // init my_sys library & pthreads
238
225
  /* nothing should come before this line ^^^ */
242
229
 
243
230
  google::protobuf::SetLogHandler(&GoogleProtoErrorThrower);
244
231
 
 
232
  /*
 
233
    init signals & alarm
 
234
    After this we can't quit by a simple unireg_abort
 
235
  */
 
236
  error_handler_hook= my_message_sql;
 
237
 
245
238
  /* Function generates error messages before abort */
246
 
  error_handler_hook= my_message_sql;
247
 
  /* init_common_variables must get basic settings such as data_home_dir
248
 
     and plugin_load_list. */
249
 
  if (init_common_variables(argc, argv, modules))
 
239
  if (init_common_variables(DRIZZLE_CONFIG_NAME,
 
240
                            argc, argv, load_default_groups))
250
241
    unireg_abort(1);                            // Will do exit
251
242
 
252
 
  /*
253
 
    init signals & alarm
254
 
    After this we can't quit by a simple unireg_abort
255
 
  */
256
243
  init_signals();
257
244
 
258
245
 
259
246
  select_thread=pthread_self();
260
247
  select_thread_in_use=1;
261
248
 
262
 
  if (not opt_help)
 
249
  if (chdir(data_home_real) && !opt_help)
263
250
  {
264
 
    if (chdir(getDataHome().file_string().c_str()))
265
 
    {
266
 
      errmsg_printf(ERRMSG_LVL_ERROR,
267
 
                    _("Data directory %s does not exist\n"),
268
 
                    getDataHome().file_string().c_str());
269
 
      unireg_abort(1);
270
 
    }
271
 
    if (mkdir("local", 0700))
272
 
    {
273
 
      /* We don't actually care */
274
 
    }
275
 
    if (chdir("local"))
276
 
    {
277
 
      errmsg_printf(ERRMSG_LVL_ERROR,
278
 
                    _("Local catalog %s/local does not exist\n"),
279
 
                    getDataHome().file_string().c_str());
280
 
      unireg_abort(1);
281
 
    }
282
 
 
283
 
    full_data_home= fs::system_complete(getDataHome());
284
 
    getDataHomeCatalog()= "./";
285
 
    getDataHome()= "../";
 
251
    errmsg_printf(ERRMSG_LVL_ERROR, _("Data directory %s does not exist\n"), data_home_real);
 
252
    unireg_abort(1);
286
253
  }
287
 
 
288
 
 
 
254
  data_home= data_home_buff;
 
255
  data_home[0]=FN_CURLIB;               // all paths are relative from here
 
256
  data_home[1]=0;
 
257
  data_home_len= 2;
289
258
 
290
259
  if (server_id == 0)
291
260
  {
312
281
  if (plugin::Listen::setup())
313
282
    unireg_abort(1);
314
283
 
315
 
 
316
284
  assert(plugin::num_trx_monitored_objects > 0);
317
285
  if (drizzle_rm_tmp_tables() ||
318
286
      my_tz_init((Session *)0, default_tz_name))
321
289
    select_thread_in_use=0;
322
290
    (void) pthread_kill(signal_thread, SIGTERM);
323
291
 
324
 
    (void) unlink(pid_file.file_string().c_str());      // Not needed anymore
 
292
    (void) unlink(pidfile_name);        // Not needed anymore
325
293
 
326
294
    exit(1);
327
295
  }
330
298
                PANDORA_RELEASE_VERSION, COMPILATION_COMMENT);
331
299
 
332
300
 
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
301
  /* Listen for new connections and start new session for each connection
350
302
     accepted. The listen.getClient() method will return NULL when the server
351
303
     should be shutdown. */
352
304
  while ((client= plugin::Listen::getClient()) != NULL)
353
305
  {
354
 
    Session::shared_ptr session(new Session(client));
355
 
 
356
 
    if (not session)
 
306
    if (!(session= new Session(client)))
357
307
    {
358
308
      delete client;
359
309
      continue;
360
310
    }
361
311
 
362
312
    /* If we error on creation we drop the connection and delete the session. */
363
 
    if (Session::schedule(session))
 
313
    if (session->schedule())
364
314
      Session::unlink(session);
365
315
  }
366
316
 
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
 
  }
 
317
  LOCK_thread_count.lock();
 
318
  select_thread_in_use=0;                       // For close_connections
 
319
  LOCK_thread_count.unlock();
384
320
  COND_thread_count.notify_all();
385
321
 
386
322
  /* 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
 
  }
 
323
  LOCK_thread_count.lock();
 
324
  while (!ready_to_exit)
 
325
    pthread_cond_wait(COND_server_end.native_handle(), LOCK_thread_count.native_handle());
 
326
  LOCK_thread_count.unlock();
392
327
 
393
328
  clean_up(1);
394
329
  module::Registry::shutdown();
395
330
  internal::my_end();
396
 
 
397
331
  return 0;
398
332
}
399
333