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"
42
#include <sys/resource.h>
50
#include "drizzled/identifier.h"
46
#include "drizzled/internal/getrusage.h"
47
#include "drizzled/security_context.h"
51
48
#include "drizzled/open_tables_state.h"
52
49
#include "drizzled/internal_error_handler.h"
53
50
#include "drizzled/diagnostics_area.h"
54
51
#include "drizzled/plugin/authorization.h"
56
53
#include <boost/unordered_map.hpp>
58
#include <boost/thread/thread.hpp>
59
54
#include <boost/thread/mutex.hpp>
60
55
#include <boost/thread/shared_mutex.hpp>
61
56
#include <boost/thread/condition_variable.hpp>
62
#include <boost/make_shared.hpp>
65
58
#define MIN_HANDSHAKE_SIZE 6
405
381
/** query associated with this statement */
406
typedef boost::shared_ptr<const std::string> QueryString;
408
boost::shared_ptr<std::string> query;
410
// Never allow for a modification of this outside of the class. c_str()
411
// requires under some setup non const, you must copy the QueryString in
414
QueryString getQueryString() const
419
void resetQueryString()
426
We need to copy the lock on the string in order to make sure we have a stable string.
427
Once this is done we can use it to build a const char* which can be handed off for
428
a method to use (Innodb is currently the only engine using this).
430
const char *getQueryStringCopy(size_t &length)
432
QueryString tmp_string(getQueryString());
441
length= tmp_string->length();
442
char *to_return= strmake(tmp_string->c_str(), tmp_string->length());
447
std::vector <char> _query;
450
typedef boost::shared_ptr<State> const_shared_ptr;
452
State(const char *in_packet, size_t in_packet_length)
454
if (in_packet_length)
456
size_t minimum= std::min(in_packet_length, static_cast<size_t>(PROCESS_LIST_WIDTH));
457
_query.resize(minimum + 1);
458
memcpy(&_query[0], in_packet, minimum);
466
const char *query() const
474
const char *query(size_t &size) const
478
size= _query.size() -1;
486
friend class Session;
487
typedef boost::shared_ptr<State> shared_ptr;
490
State::shared_ptr _state;
493
State::const_shared_ptr state()
499
385
Name of the current (default) database.
532
408
memory::Root warn_root; /**< Allocation area for warnings and errors */
533
409
plugin::Client *client; /**< Pointer to client object */
535
void setClient(plugin::Client *client_arg);
537
plugin::Client *getClient()
542
410
plugin::Scheduler *scheduler; /**< Pointer to scheduler object */
543
411
void *scheduler_arg; /**< Pointer to the optional scheduler argument */
545
413
typedef boost::unordered_map< std::string, user_var_entry *, util::insensitive_hash, util::insensitive_equal_to> UserVars;
547
414
typedef std::pair< UserVars::iterator, UserVars::iterator > UserVarsRange;
548
415
UserVars user_vars; /**< Hash of user variables defined during the session's lifetime */
552
const UserVars &getUserVariables() const
557
418
drizzle_system_variables variables; /**< Mutable local variables local to the session */
558
419
struct system_status_var status_var; /**< Session-local status counters */
559
420
THR_LOCK_INFO lock_info; /**< Locking information for this session */
560
421
THR_LOCK_OWNER main_lock_id; /**< To use for conventional queries */
561
422
THR_LOCK_OWNER *lock_id; /**< If not main_lock_id, points to the lock_id of a cursor. */
424
boost::mutex LOCK_delete; /**< Locked before session is deleted */
432
void unlockForDelete()
434
LOCK_delete.unlock();
438
* A peek into the query string for the session. This is a best effort
439
* delivery, there is no guarantee whether the content is meaningful.
441
char process_list_info[PROCESS_LIST_WIDTH+1];
564
444
* A pointer to the stack frame of the scheduler thread
619
501
uint32_t dbug_sentry; /**< watch for memory corruption */
621
boost::thread::id boost_thread_id;
622
boost_thread_shared_ptr _thread;
623
boost::this_thread::disable_interruption *interrupt;
625
503
internal::st_my_thread_var *mysys_var;
628
boost_thread_shared_ptr &getThread()
633
void pushInterrupt(boost::this_thread::disable_interruption *interrupt_arg)
635
interrupt= interrupt_arg;
638
boost::this_thread::disable_interruption &getThreadInterupt()
644
506
internal::st_my_thread_var *getThreadVar()
646
508
return mysys_var;
511
void resetThreadVar()
650
516
* Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
651
517
* first byte of the packet in executeStatement()
733
599
Field *dup_field;
734
600
sigset_t signals;
736
// As of right now we do not allow a concurrent execute to launch itself
738
bool concurrent_execute_allowed;
741
void setConcurrentExecute(bool arg)
743
concurrent_execute_allowed= arg;
746
bool isConcurrentExecuteAllowed() const
748
return concurrent_execute_allowed;
751
602
/* Tells if LAST_INSERT_ID(#) was called for the current statement */
752
603
bool arg_of_last_insert_id_function;
755
605
ALL OVER THIS FILE, "insert_id" means "*automatically generated* value for
756
606
insertion into an auto_increment column".
854
704
uint32_t row_count;
855
705
session_id_t thread_id;
856
706
uint32_t tmp_table;
857
enum global_read_lock_t
860
GOT_GLOBAL_READ_LOCK= 1,
861
MADE_GLOBAL_READ_LOCK_BLOCK_COMMIT= 2
864
global_read_lock_t _global_read_lock;
868
global_read_lock_t isGlobalReadLock() const
870
return _global_read_lock;
873
void setGlobalReadLock(global_read_lock_t arg)
875
_global_read_lock= arg;
878
DrizzleLock *lockTables(Table **tables, uint32_t count, uint32_t flags, bool *need_reopen);
879
bool lockGlobalReadLock();
880
bool lock_table_names(TableList *table_list);
881
bool lock_table_names_exclusively(TableList *table_list);
882
bool makeGlobalReadLockBlockCommit();
883
bool abortLockForThread(Table *table);
884
bool wait_if_global_read_lock(bool abort_on_refresh, bool is_not_commit);
885
int lock_table_name(TableList *table_list);
886
void abortLock(Table *table);
887
void removeLock(Table *table);
888
void unlockReadTables(DrizzleLock *sql_lock);
889
void unlockSomeTables(Table **table, uint32_t count);
890
void unlockTables(DrizzleLock *sql_lock);
891
void startWaitingGlobalReadLock();
892
void unlockGlobalReadLock();
895
int unlock_external(Table **table, uint32_t count);
896
int lock_external(Table **tables, uint32_t count);
897
bool wait_for_locked_table_names(TableList *table_list);
898
DrizzleLock *get_lock_data(Table **table_ptr, uint32_t count,
899
bool should_lock, Table **write_lock_used);
707
uint32_t global_read_lock;
902
708
uint32_t server_status;
903
709
uint32_t open_options;
904
710
uint32_t select_number; /**< number of select (used for EXPLAIN) */
1231
1031
inline time_t query_start() { return start_time; }
1232
1032
inline void set_time()
1234
boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
1235
boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
1236
start_utime= utime_after_lock= (mytime-epoch).total_microseconds();
1240
1036
start_time= user_time;
1241
connect_microseconds= start_utime;
1037
connect_microseconds= start_utime= utime_after_lock= my_micro_time();
1244
start_time= (mytime-epoch).total_seconds();
1040
start_utime= utime_after_lock= my_micro_time_and_time(&start_time);
1246
1042
inline void set_current_time() { start_time= time(NULL); }
1247
1043
inline void set_time(time_t t)
1249
1045
start_time= user_time= t;
1250
boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
1251
boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
1252
uint64_t t_mark= (mytime-epoch).total_microseconds();
1254
start_utime= utime_after_lock= t_mark;
1256
void set_time_after_lock() {
1257
boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
1258
boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
1259
utime_after_lock= (mytime-epoch).total_microseconds();
1046
start_utime= utime_after_lock= my_micro_time();
1048
void set_time_after_lock() { utime_after_lock= my_micro_time(); }
1262
1050
* Returns the current micro-timestamp
1264
1052
inline uint64_t getCurrentTimestamp()
1266
boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
1267
boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
1268
uint64_t t_mark= (mytime-epoch).total_microseconds();
1054
return my_micro_time();
1272
1056
inline uint64_t found_rows(void)
1709
1498
Table *openTable(TableList *table_list, bool *refresh, uint32_t flags= 0);
1711
1500
void unlink_open_table(Table *find);
1712
void drop_open_table(Table *table, const TableIdentifier &identifier);
1501
void drop_open_table(Table *table, TableIdentifier &identifier);
1713
1502
void close_cached_table(Table *table);
1715
1504
/* Create a lock in the cache */
1716
1505
table::Placeholder *table_cache_insert_placeholder(const TableIdentifier &identifier);
1717
bool lock_table_name_if_not_cached(const TableIdentifier &identifier, Table **table);
1506
bool lock_table_name_if_not_cached(TableIdentifier &identifier, Table **table);
1719
1508
typedef boost::unordered_map<std::string, message::Table, util::insensitive_hash, util::insensitive_equal_to> TableMessageCache;
1723
TableMessageCache table_message_cache;
1726
bool storeTableMessage(const TableIdentifier &identifier, message::Table &table_message);
1727
bool removeTableMessage(const TableIdentifier &identifier);
1728
bool getTableMessage(const TableIdentifier &identifier, message::Table &table_message);
1729
bool doesTableMessageExist(const TableIdentifier &identifier);
1730
bool renameTableMessage(const TableIdentifier &from, const TableIdentifier &to);
1509
TableMessageCache table_message_cache;
1511
bool storeTableMessage(const TableIdentifier &identifier, message::Table &table_message);
1512
bool removeTableMessage(const TableIdentifier &identifier);
1513
bool getTableMessage(const TableIdentifier &identifier, message::Table &table_message);
1514
bool doesTableMessageExist(const TableIdentifier &identifier);
1515
bool renameTableMessage(const TableIdentifier &from, const TableIdentifier &to);
1517
/* Work with temporary tables */
1518
Table *find_temporary_table(const TableIdentifier &identifier);
1520
void doGetTableNames(CachedDirectory &directory,
1521
const SchemaIdentifier &schema_identifier,
1522
std::set<std::string>& set_of_names);
1523
void doGetTableNames(const SchemaIdentifier &schema_identifier,
1524
std::set<std::string>& set_of_names);
1526
void doGetTableIdentifiers(CachedDirectory &directory,
1527
const SchemaIdentifier &schema_identifier,
1528
TableIdentifiers &set_of_identifiers);
1529
void doGetTableIdentifiers(const SchemaIdentifier &schema_identifier,
1530
TableIdentifiers &set_of_identifiers);
1532
int doGetTableDefinition(const drizzled::TableIdentifier &identifier,
1533
message::Table &table_proto);
1534
bool doDoesTableExist(const drizzled::TableIdentifier &identifier);
1536
void close_temporary_tables();
1537
void close_temporary_table(Table *table);
1538
// The method below just handles the de-allocation of the table. In
1539
// a better memory type world, this would not be needed.
1734
TableMessages _table_message_cache;
1541
void nukeTable(Table *table);
1737
TableMessages &getMessageCache()
1739
return _table_message_cache;
1544
void dumpTemporaryTableNames(const char *id);
1545
int drop_temporary_table(const drizzled::TableIdentifier &identifier);
1546
bool rm_temporary_table(plugin::StorageEngine *base, TableIdentifier &identifier);
1547
bool rm_temporary_table(TableIdentifier &identifier, bool best_effort= false);
1548
Table *open_temporary_table(TableIdentifier &identifier,
1549
bool link_in_list= true);
1742
1551
/* Reopen operations */
1743
1552
bool reopen_tables(bool get_locks, bool mark_share_as_old);