~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: Monty Taylor
  • Date: 2010-12-06 21:17:06 UTC
  • mto: (1977.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1980.
  • Revision ID: mordred@inaugust.com-20101206211706-iiuzzkxhh3fm10zf
Add ability to add a validation function to any sys_var. duh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#include "drizzled/transaction_context.h"
37
37
#include "drizzled/util/storable.h"
38
38
#include "drizzled/my_hash.h"
 
39
#include "drizzled/pthread_globals.h"
39
40
 
40
41
#include <netdb.h>
 
42
#include <sys/time.h>
 
43
#include <sys/resource.h>
 
44
 
41
45
#include <map>
42
46
#include <string>
43
47
#include <bitset>
44
48
#include <deque>
45
49
 
46
 
#include "drizzled/internal/getrusage.h"
47
50
#include "drizzled/security_context.h"
48
51
#include "drizzled/open_tables_state.h"
49
52
#include "drizzled/internal_error_handler.h"
51
54
#include "drizzled/plugin/authorization.h"
52
55
 
53
56
#include <boost/unordered_map.hpp>
 
57
 
 
58
#include <boost/thread/thread.hpp>
54
59
#include <boost/thread/mutex.hpp>
55
60
#include <boost/thread/shared_mutex.hpp>
56
61
#include <boost/thread/condition_variable.hpp>
206
211
  uint64_t preload_buff_size;
207
212
  uint32_t read_buff_size;
208
213
  uint32_t read_rnd_buff_size;
 
214
  bool replicate_query;
209
215
  size_t sortbuff_size;
210
216
  uint32_t thread_handling;
211
217
  uint32_t tx_isolation;
309
315
public:
310
316
  // Plugin storage in Session.
311
317
  typedef boost::unordered_map<std::string, util::Storable *, util::insensitive_hash, util::insensitive_equal_to> PropertyMap;
 
318
  typedef Session* Ptr;
 
319
  typedef boost::shared_ptr<Session> shared_ptr;
312
320
 
313
321
  /*
314
322
    MARK_COLUMNS_NONE:  Means mark_used_colums is not set and no indicator to
393
401
    return lex;
394
402
  }
395
403
  /** query associated with this statement */
396
 
  std::string query;
 
404
  typedef boost::shared_ptr<const std::string> QueryString;
 
405
private:
 
406
  boost::shared_ptr<std::string> query;
 
407
 
 
408
  // Never allow for a modification of this outside of the class. c_str()
 
409
  // requires under some setup non const, you must copy the QueryString in
 
410
  // order to use it.
 
411
public:
 
412
  QueryString getQueryString() const
 
413
  {
 
414
    return query;
 
415
  }
 
416
 
 
417
  void resetQueryString()
 
418
  {
 
419
    return query.reset(new std::string);
 
420
  }
 
421
 
 
422
  /*
 
423
    We need to copy the lock on the string in order to make sure we have a stable string.
 
424
    Once this is done we can use it to build a const char* which can be handed off for
 
425
    a method to use (Innodb is currently the only engine using this).
 
426
  */
 
427
  const char *getQueryStringCopy(size_t &length)
 
428
  {
 
429
    QueryString tmp_string(getQueryString());
 
430
 
 
431
    length= tmp_string->length();
 
432
    char *to_return= strmake(tmp_string->c_str(), tmp_string->length());
 
433
    return to_return;
 
434
  }
397
435
 
398
436
  /**
399
437
    Name of the current (default) database.
408
446
    only responsible for freeing this member.
409
447
  */
410
448
  std::string db;
 
449
 
 
450
  const std::string &getSchema() const
 
451
  {
 
452
    return db;
 
453
  }
411
454
  std::string catalog;
412
455
  /* current cache key */
413
456
  std::string query_cache_key;
421
464
 
422
465
  memory::Root warn_root; /**< Allocation area for warnings and errors */
423
466
  plugin::Client *client; /**< Pointer to client object */
 
467
 
 
468
  void setClient(plugin::Client *client_arg);
 
469
 
 
470
  plugin::Client *getClient()
 
471
  {
 
472
    return client;
 
473
  }
 
474
 
424
475
  plugin::Scheduler *scheduler; /**< Pointer to scheduler object */
425
476
  void *scheduler_arg; /**< Pointer to the optional scheduler argument */
426
477
 
441
492
  THR_LOCK_INFO lock_info; /**< Locking information for this session */
442
493
  THR_LOCK_OWNER main_lock_id; /**< To use for conventional queries */
443
494
  THR_LOCK_OWNER *lock_id; /**< If not main_lock_id, points to the lock_id of a cursor. */
444
 
private:
445
 
  boost::mutex LOCK_delete; /**< Locked before session is deleted */
446
 
public:
447
 
 
448
 
  void lockForDelete()
449
 
  {
450
 
    LOCK_delete.lock();
451
 
  }
452
 
 
453
 
  void unlockForDelete()
454
 
  {
455
 
    LOCK_delete.unlock();
456
 
  }
457
 
 
458
 
  /**
459
 
   * A peek into the query string for the session. This is a best effort
460
 
   * delivery, there is no guarantee whether the content is meaningful.
461
 
   */
462
 
  char process_list_info[PROCESS_LIST_WIDTH+1];
463
495
 
464
496
  /**
465
497
   * A pointer to the stack frame of the scheduler thread
500
532
  /**
501
533
   * Is this session viewable by the current user?
502
534
   */
503
 
  bool isViewable() const
504
 
  {
505
 
    return plugin::Authorization::isAuthorized(current_session->getSecurityContext(),
506
 
                                               this,
507
 
                                               false);
508
 
  }
 
535
  bool isViewable() const;
509
536
 
510
537
  /**
511
538
    Used in error messages to tell user in what part of MySQL we found an
521
548
  */
522
549
  uint32_t dbug_sentry; /**< watch for memory corruption */
523
550
private:
 
551
  boost::thread::id boost_thread_id;
 
552
  boost_thread_shared_ptr _thread;
 
553
  boost::this_thread::disable_interruption *interrupt;
 
554
 
524
555
  internal::st_my_thread_var *mysys_var;
525
556
public:
526
557
 
 
558
  boost_thread_shared_ptr &getThread()
 
559
  {
 
560
    return _thread;
 
561
  }
 
562
 
 
563
  void pushInterrupt(boost::this_thread::disable_interruption *interrupt_arg)
 
564
  {
 
565
    interrupt= interrupt_arg;
 
566
  }
 
567
 
 
568
  boost::this_thread::disable_interruption &getThreadInterupt()
 
569
  {
 
570
    assert(interrupt);
 
571
    return *interrupt;
 
572
  }
 
573
 
527
574
  internal::st_my_thread_var *getThreadVar()
528
575
  {
529
576
    return mysys_var;
530
577
  }
531
578
 
532
 
  void resetThreadVar()
533
 
  {
534
 
    mysys_var= NULL;
535
 
  }
536
579
  /**
537
580
   * Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
538
581
   * first byte of the packet in executeStatement()
620
663
  Field *dup_field;
621
664
  sigset_t signals;
622
665
 
 
666
  // As of right now we do not allow a concurrent execute to launch itself
 
667
private:
 
668
  bool concurrent_execute_allowed;
 
669
public:
 
670
 
 
671
  void setConcurrentExecute(bool arg)
 
672
  {
 
673
    concurrent_execute_allowed= arg;
 
674
  }
 
675
 
 
676
  bool isConcurrentExecuteAllowed() const
 
677
  {
 
678
    return concurrent_execute_allowed;
 
679
  }
 
680
 
623
681
  /* Tells if LAST_INSERT_ID(#) was called for the current statement */
624
682
  bool arg_of_last_insert_id_function;
 
683
 
625
684
  /*
626
685
    ALL OVER THIS FILE, "insert_id" means "*automatically generated* value for
627
686
    insertion into an auto_increment column".
911
970
    return warn_query_id;
912
971
  }
913
972
 
914
 
  /** Returns the current query text */
915
 
  inline const std::string &getQueryString()  const
916
 
  {
917
 
    return query;
918
 
  }
919
 
 
920
 
  /** Returns the length of the current query text */
921
 
  inline size_t getQueryLength() const
922
 
  {
923
 
    if (! query.empty())
924
 
      return query.length();
925
 
    else
926
 
      return 0;
927
 
  }
928
 
 
929
973
  /** Accessor method returning the session's ID. */
930
974
  inline session_id_t getSessionId()  const
931
975
  {
1101
1145
  /**
1102
1146
   * Schedule a session to be run on the default scheduler.
1103
1147
   */
1104
 
  bool schedule();
 
1148
  static bool schedule(Session::shared_ptr&);
 
1149
 
 
1150
  static void unlink(Session::shared_ptr&);
1105
1151
 
1106
1152
  /*
1107
1153
    For enter_cond() / exit_cond() to work the mutex must be got before
1114
1160
  inline time_t query_start() { return start_time; }
1115
1161
  inline void set_time()
1116
1162
  {
 
1163
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
 
1164
    boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
 
1165
    start_utime= utime_after_lock= (mytime-epoch).total_microseconds();
 
1166
 
1117
1167
    if (user_time)
1118
1168
    {
1119
1169
      start_time= user_time;
1120
 
      connect_microseconds= start_utime= utime_after_lock= my_micro_time();
 
1170
      connect_microseconds= start_utime;
1121
1171
    }
1122
 
    else
1123
 
      start_utime= utime_after_lock= my_micro_time_and_time(&start_time);
 
1172
    else 
 
1173
      start_time= (mytime-epoch).total_seconds();
1124
1174
  }
1125
1175
  inline void   set_current_time()    { start_time= time(NULL); }
1126
1176
  inline void   set_time(time_t t)
1127
1177
  {
1128
1178
    start_time= user_time= t;
1129
 
    start_utime= utime_after_lock= my_micro_time();
1130
 
  }
1131
 
  void set_time_after_lock()  { utime_after_lock= my_micro_time(); }
 
1179
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
 
1180
    boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
 
1181
    uint64_t t_mark= (mytime-epoch).total_microseconds();
 
1182
 
 
1183
    start_utime= utime_after_lock= t_mark;
 
1184
  }
 
1185
  void set_time_after_lock()  { 
 
1186
     boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
 
1187
     boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
 
1188
     utime_after_lock= (mytime-epoch).total_microseconds();
 
1189
  }
1132
1190
  /**
1133
1191
   * Returns the current micro-timestamp
1134
1192
   */
1135
1193
  inline uint64_t getCurrentTimestamp()  
1136
1194
  { 
1137
 
    return my_micro_time(); 
 
1195
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
 
1196
    boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
 
1197
    uint64_t t_mark= (mytime-epoch).total_microseconds();
 
1198
 
 
1199
    return t_mark; 
1138
1200
  }
1139
1201
  inline uint64_t found_rows(void)
1140
1202
  {
1160
1222
    @todo: To silence an error, one should use Internal_error_handler
1161
1223
    mechanism. In future this function will be removed.
1162
1224
  */
1163
 
  inline void clear_error()
 
1225
  inline void clear_error(bool full= false)
1164
1226
  {
1165
1227
    if (main_da.is_error())
1166
1228
      main_da.reset_diagnostics_area();
1167
 
    return;
 
1229
 
 
1230
    if (full)
 
1231
    {
 
1232
      drizzle_reset_errors(this, true);
 
1233
    }
 
1234
  }
 
1235
 
 
1236
  void clearDiagnostics()
 
1237
  {
 
1238
    main_da.reset_diagnostics_area();
1168
1239
  }
1169
1240
 
1170
1241
  /**
1534
1605
  void close_old_data_files(bool morph_locks= false,
1535
1606
                            bool send_refresh= false);
1536
1607
  void close_open_tables();
1537
 
  void close_data_files_and_morph_locks(TableIdentifier &identifier);
 
1608
  void close_data_files_and_morph_locks(const TableIdentifier &identifier);
1538
1609
 
1539
1610
private:
1540
1611
  bool free_cached_table();
1571
1642
  Table *openTable(TableList *table_list, bool *refresh, uint32_t flags= 0);
1572
1643
 
1573
1644
  void unlink_open_table(Table *find);
1574
 
  void drop_open_table(Table *table, TableIdentifier &identifier);
 
1645
  void drop_open_table(Table *table, const TableIdentifier &identifier);
1575
1646
  void close_cached_table(Table *table);
1576
1647
 
1577
1648
  /* Create a lock in the cache */
1578
1649
  table::Placeholder *table_cache_insert_placeholder(const TableIdentifier &identifier);
1579
 
  bool lock_table_name_if_not_cached(TableIdentifier &identifier, Table **table);
 
1650
  bool lock_table_name_if_not_cached(const TableIdentifier &identifier, Table **table);
1580
1651
 
1581
1652
  typedef boost::unordered_map<std::string, message::Table, util::insensitive_hash, util::insensitive_equal_to> TableMessageCache;
1582
1653
 
1637
1708
    return global_system_variables.storage_engine;
1638
1709
  }
1639
1710
 
1640
 
  static void unlink(Session *session);
1641
 
 
1642
1711
  void get_xid(DRIZZLE_XID *xid); // Innodb only
1643
1712
 
1644
1713
  table::Instance *getInstanceTable();
1754
1823
static const std::bitset<CF_BIT_SIZE> CF_SHOW_TABLE_COMMAND(1 << CF_BIT_SHOW_TABLE_COMMAND);
1755
1824
static const std::bitset<CF_BIT_SIZE> CF_WRITE_LOGS_COMMAND(1 << CF_BIT_WRITE_LOGS_COMMAND);
1756
1825
 
 
1826
namespace display  {
 
1827
const std::string &type(drizzled::Session::global_read_lock_t type);
 
1828
size_t max_string_length(drizzled::Session::global_read_lock_t type);
 
1829
} /* namespace display */
 
1830
 
1757
1831
} /* namespace drizzled */
1758
1832
 
1759
1833
#endif /* DRIZZLED_SESSION_H */