~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: Stewart Smith
  • Date: 2011-01-14 05:15:57 UTC
  • mto: (2086.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 2087.
  • Revision ID: stewart@flamingspork.com-20110114051557-sm1v4xrmqe5ql2pi
logging is done by plugins, so imply in docs that new plugins can implement new logging.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
#include "drizzled/diagnostics_area.h"
54
54
#include "drizzled/plugin/authorization.h"
55
55
 
 
56
#include "drizzled/catalog/instance.h"
 
57
#include "drizzled/catalog/local.h"
 
58
 
56
59
#include <boost/unordered_map.hpp>
57
60
 
58
61
#include <boost/thread/thread.hpp>
310
313
 * all member variables that are not critical to non-internal operations of the
311
314
 * session object.
312
315
 */
313
 
typedef int64_t session_id_t;
314
316
 
315
317
class Session : public Open_tables_state
316
318
{
319
321
  typedef boost::unordered_map<std::string, util::Storable *, util::insensitive_hash, util::insensitive_equal_to> PropertyMap;
320
322
  typedef Session* Ptr;
321
323
  typedef boost::shared_ptr<Session> shared_ptr;
 
324
  typedef Session& reference;
322
325
  typedef const Session& const_reference;
323
326
  typedef const Session* const_pointer;
324
327
  typedef Session* pointer;
325
328
 
 
329
  static shared_ptr make_shared(plugin::Client *client, catalog::Instance::shared_ptr instance_arg)
 
330
  {
 
331
    assert(instance_arg);
 
332
    return boost::make_shared<Session>(client, instance_arg);
 
333
  }
 
334
 
326
335
  /*
327
336
    MARK_COLUMNS_NONE:  Means mark_used_colums is not set and no indicator to
328
337
                        handler of fields used is set
520
529
 
521
530
    return util::string::const_shared_ptr(new std::string(""));
522
531
  }
523
 
  std::string catalog;
 
532
 
524
533
  /* current cache key */
525
534
  std::string query_cache_key;
526
535
  /**
659
668
  uint32_t file_id;     /**< File ID for LOAD DATA INFILE */
660
669
  /* @note the following three members should likely move to Client */
661
670
  uint32_t max_client_packet_length; /**< Maximum number of bytes a client can send in a single packet */
662
 
  time_t start_time;
663
 
  time_t user_time;
664
 
  uint64_t thr_create_utime; /**< track down slow pthread_create */
665
 
  uint64_t start_utime;
666
 
  uint64_t utime_after_lock;
 
671
 
 
672
private:
 
673
  boost::posix_time::ptime _epoch;
 
674
  boost::posix_time::ptime _connect_time;
 
675
  boost::posix_time::ptime _start_timer;
 
676
  boost::posix_time::ptime _end_timer;
 
677
 
 
678
  boost::posix_time::ptime _user_time;
 
679
public:
 
680
  uint64_t utime_after_lock; // This used by Innodb.
 
681
 
 
682
  void resetUserTime()
 
683
  {
 
684
    _user_time= boost::posix_time::not_a_date_time;
 
685
  }
 
686
 
 
687
  const boost::posix_time::ptime &start_timer() const
 
688
  {
 
689
    return _start_timer;
 
690
  }
 
691
 
 
692
  void getTimeDifference(boost::posix_time::time_duration &result_arg, const boost::posix_time::ptime &arg) const
 
693
  {
 
694
    result_arg=  arg - _start_timer;
 
695
  }
667
696
 
668
697
  thr_lock_type update_lock_default;
669
698
 
684
713
  */
685
714
  query_id_t query_id;
686
715
  query_id_t warn_query_id;
 
716
 
687
717
public:
688
718
  void **getEngineData(const plugin::MonitoredInTransaction *monitored);
689
719
  ResourceContext *getResourceContext(const plugin::MonitoredInTransaction *monitored,
886
916
    _global_read_lock= arg;
887
917
  }
888
918
 
889
 
  DrizzleLock *lockTables(Table **tables, uint32_t count, uint32_t flags, bool *need_reopen);
 
919
  DrizzleLock *lockTables(Table **tables, uint32_t count, uint32_t flags);
890
920
  bool lockGlobalReadLock();
891
921
  bool lock_table_names(TableList *table_list);
892
922
  bool lock_table_names_exclusively(TableList *table_list);
1126
1156
    auto_inc_intervals_forced.append(next_id, UINT64_MAX, 0);
1127
1157
  }
1128
1158
 
1129
 
  Session(plugin::Client *client_arg);
 
1159
  Session(plugin::Client *client_arg, catalog::Instance::shared_ptr catalog);
1130
1160
  virtual ~Session();
1131
1161
 
1132
1162
  void cleanup(void);
1240
1270
  const char* enter_cond(boost::condition_variable_any &cond, boost::mutex &mutex, const char* msg);
1241
1271
  void exit_cond(const char* old_msg);
1242
1272
 
1243
 
  inline time_t query_start() { return start_time; }
1244
 
  inline void set_time()
1245
 
  {
1246
 
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
1247
 
    boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
1248
 
    start_utime= utime_after_lock= (mytime-epoch).total_microseconds();
1249
 
 
1250
 
    if (user_time)
1251
 
    {
1252
 
      start_time= user_time;
1253
 
      connect_microseconds= start_utime;
1254
 
    }
1255
 
    else 
1256
 
      start_time= (mytime-epoch).total_seconds();
1257
 
  }
1258
 
  inline void   set_current_time()    { start_time= time(NULL); }
1259
 
  inline void   set_time(time_t t)
1260
 
  {
1261
 
    start_time= user_time= t;
1262
 
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
1263
 
    boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
1264
 
    uint64_t t_mark= (mytime-epoch).total_microseconds();
1265
 
 
1266
 
    start_utime= utime_after_lock= t_mark;
1267
 
  }
1268
 
  void set_time_after_lock()  { 
1269
 
     boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
1270
 
     boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
1271
 
     utime_after_lock= (mytime-epoch).total_microseconds();
1272
 
  }
 
1273
  time_t query_start()
 
1274
  {
 
1275
    return getCurrentTimestampEpoch();
 
1276
  }
 
1277
 
 
1278
  void set_time()
 
1279
  {
 
1280
    _end_timer= _start_timer= boost::posix_time::microsec_clock::universal_time();
 
1281
    utime_after_lock= (_start_timer - _epoch).total_microseconds();
 
1282
  }
 
1283
 
 
1284
  void set_time(time_t t) // This is done by a sys_var, as long as user_time is set, we will use that for all references to time
 
1285
  {
 
1286
    _user_time= boost::posix_time::from_time_t(t);
 
1287
  }
 
1288
 
 
1289
  void set_time_after_lock()
 
1290
  { 
 
1291
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::universal_time());
 
1292
    utime_after_lock= (mytime - _epoch).total_microseconds();
 
1293
  }
 
1294
 
 
1295
  void set_end_timer()
 
1296
  {
 
1297
    _end_timer= boost::posix_time::microsec_clock::universal_time();
 
1298
    status_var.execution_time_nsec+=(_end_timer - _start_timer).total_microseconds();
 
1299
  }
 
1300
 
 
1301
  uint64_t getElapsedTime() const
 
1302
  {
 
1303
    return (_end_timer - _start_timer).total_microseconds();
 
1304
  }
 
1305
 
1273
1306
  /**
1274
1307
   * Returns the current micro-timestamp
1275
1308
   */
1276
 
  inline uint64_t getCurrentTimestamp()  
 
1309
  uint64_t getCurrentTimestamp(bool actual= true) const
1277
1310
  { 
1278
 
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
1279
 
    boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
1280
 
    uint64_t t_mark= (mytime-epoch).total_microseconds();
 
1311
    uint64_t t_mark;
 
1312
 
 
1313
    if (actual)
 
1314
    {
 
1315
      boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::universal_time());
 
1316
      t_mark= (mytime - _epoch).total_microseconds();
 
1317
    }
 
1318
    else
 
1319
    {
 
1320
      t_mark= (_end_timer - _epoch).total_microseconds();
 
1321
    }
1281
1322
 
1282
1323
    return t_mark; 
1283
1324
  }
1284
 
  inline uint64_t found_rows(void)
 
1325
 
 
1326
  // We may need to set user on this
 
1327
  time_t getCurrentTimestampEpoch() const
 
1328
  { 
 
1329
    if (not _user_time.is_not_a_date_time())
 
1330
      return (_user_time - _epoch).total_seconds();
 
1331
 
 
1332
    return (_start_timer - _epoch).total_seconds();
 
1333
  }
 
1334
 
 
1335
  time_t getCurrentTimestampEpoch(uint32_t &fraction_arg) const
 
1336
  { 
 
1337
    if (not _user_time.is_not_a_date_time())
 
1338
    {
 
1339
      fraction_arg= 0;
 
1340
      return (_user_time - _epoch).total_seconds();
 
1341
    }
 
1342
 
 
1343
    fraction_arg= _start_timer.time_of_day().fractional_seconds() % 1000000;
 
1344
    return (_start_timer - _epoch).total_seconds();
 
1345
  }
 
1346
 
 
1347
  uint64_t found_rows(void) const
1285
1348
  {
1286
1349
    return limit_found_rows;
1287
1350
  }
 
1351
 
1288
1352
  /** Returns whether the session is currently inside a transaction */
1289
 
  inline bool inTransaction()
 
1353
  bool inTransaction() const
1290
1354
  {
1291
1355
    return server_status & SERVER_STATUS_IN_TRANS;
1292
1356
  }
 
1357
 
1293
1358
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1294
1359
                              const char* str, uint32_t length,
1295
1360
                              bool allocate_lex_string);
 
1361
 
1296
1362
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1297
1363
                              const std::string &str,
1298
1364
                              bool allocate_lex_string);
1299
1365
 
1300
1366
  int send_explain_fields(select_result *result);
 
1367
 
1301
1368
  /**
1302
1369
    Clear the current error, if any.
1303
1370
    We do not clear is_fatal_error or is_fatal_sub_stmt_error since we
1446
1513
   *
1447
1514
   * @note  For the connection that is doing shutdown, this is called twice
1448
1515
   */
1449
 
  void disconnect(enum drizzled_error_code errcode= EE_OK);
 
1516
  void disconnect(enum error_t errcode= EE_OK);
1450
1517
 
1451
1518
  /**
1452
1519
   * Check if user exists and the password supplied is correct.
1466
1533
   * Returns the timestamp (in microseconds) of when the Session 
1467
1534
   * connected to the server.
1468
1535
   */
1469
 
  inline uint64_t getConnectMicroseconds() const
1470
 
  {
1471
 
    return connect_microseconds;
 
1536
  uint64_t getConnectMicroseconds() const
 
1537
  {
 
1538
    return (_connect_time - _epoch).total_microseconds();
 
1539
  }
 
1540
 
 
1541
  uint64_t getConnectSeconds() const
 
1542
  {
 
1543
    return (_connect_time - _epoch).total_seconds();
1472
1544
  }
1473
1545
 
1474
1546
  /**
1589
1661
  
1590
1662
  
1591
1663
 private:
1592
 
 /** Microsecond timestamp of when Session connected */
1593
 
  uint64_t connect_microseconds;
1594
1664
  const char *proc_info;
1595
1665
 
1596
1666
  /** The current internal error handler for this thread, or NULL. */
1813
1883
    return usage;
1814
1884
  }
1815
1885
 
 
1886
  catalog::Instance::const_reference catalog() const
 
1887
  {
 
1888
    return *(_catalog.get());
 
1889
  }
 
1890
 
 
1891
  catalog::Instance::reference catalog()
 
1892
  {
 
1893
    return *(_catalog.get());
 
1894
  }
 
1895
 
1816
1896
private:
 
1897
  catalog::Instance::shared_ptr _catalog;
 
1898
 
1817
1899
  // This lives throughout the life of Session
1818
1900
  bool use_usage;
1819
1901
  PropertyMap life_properties;