~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: Lee Bieber
  • Date: 2011-04-13 18:54:56 UTC
  • mfrom: (2275.1.2 build)
  • Revision ID: kalebral@gmail.com-20110413185456-ygv8a7lxf92ttoee
Merge Joe - 755201: slave plugin queryForReplicationEvents() query needs to be ordered
Merge Olaf - Refactor Session

Show diffs side-by-side

added added

removed removed

Lines of Context:
167
167
  // requires under some setup non const, you must copy the QueryString in
168
168
  // order to use it.
169
169
public:
 
170
  void resetQueryString();
 
171
  const boost::shared_ptr<session::State>& state();
 
172
 
170
173
  QueryString getQueryString() const
171
174
  {
172
175
    return query;
173
176
  }
174
177
 
175
 
  void resetQueryString()
176
 
  {
177
 
    query.reset();
178
 
    _state.reset();
179
 
  }
180
 
 
181
 
  /*
182
 
    We need to copy the lock on the string in order to make sure we have a stable string.
183
 
    Once this is done we can use it to build a const char* which can be handed off for
184
 
    a method to use (Innodb is currently the only engine using this).
185
 
  */
186
 
  const char *getQueryStringCopy(size_t &length)
 
178
  const char* getQueryStringCopy(size_t &length)
187
179
  {
188
180
    QueryString tmp_string(getQueryString());
189
 
 
190
181
    if (not tmp_string)
191
182
    {
192
183
      length= 0;
193
184
      return NULL;
194
185
    }
195
 
 
196
186
    length= tmp_string->length();
197
 
    char *to_return= strmake(tmp_string->c_str(), tmp_string->length());
198
 
    return to_return;
199
 
  }
200
 
 
201
 
private:
202
 
  boost::shared_ptr<session::State> _state;
203
 
 
204
 
public:
205
 
 
206
 
  const boost::shared_ptr<session::State>& state()
207
 
  {
208
 
    return _state;
209
 
  }
210
 
 
211
 
  /**
212
 
    Name of the current (default) database.
213
 
 
214
 
    If there is the current (default) database, "db" contains its name. If
215
 
    there is no current (default) database, "db" is NULL and "db_length" is
216
 
    0. In other words, "db", "db_length" must either be NULL, or contain a
217
 
    valid database name.
218
 
 
219
 
    @note this attribute is set and alloced by the slave SQL thread (for
220
 
    the Session of that thread); that thread is (and must remain, for now) the
221
 
    only responsible for freeing this member.
222
 
  */
223
 
public:
224
 
 
225
 
  util::string::const_shared_ptr schema() const
226
 
  {
227
 
    return _schema ? _schema : util::string::const_shared_ptr(new std::string);
228
 
  }
 
187
    return strmake(tmp_string->c_str(), tmp_string->length());
 
188
  }
 
189
 
 
190
  util::string::ptr schema() const;
229
191
 
230
192
  /* current cache key */
231
193
  std::string query_cache_key;
358
320
   * Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
359
321
   * first byte of the packet in executeStatement()
360
322
   */
361
 
  enum enum_server_command command;
362
 
  uint32_t file_id;     /**< File ID for LOAD DATA INFILE */
363
 
  /* @note the following three members should likely move to Client */
364
 
  uint32_t max_client_packet_length; /**< Maximum number of bytes a client can send in a single packet */
365
 
 
366
 
private:
367
 
  boost::posix_time::ptime _epoch;
368
 
  boost::posix_time::ptime _connect_time;
369
 
  boost::posix_time::ptime _start_timer;
370
 
  boost::posix_time::ptime _end_timer;
371
 
 
372
 
  boost::posix_time::ptime _user_time;
373
 
public:
374
 
  uint64_t utime_after_lock; // This used by Innodb.
375
 
 
376
 
  void resetUserTime()
377
 
  {
378
 
    _user_time= boost::posix_time::not_a_date_time;
379
 
  }
380
 
 
381
 
  const boost::posix_time::ptime &start_timer() const
382
 
  {
383
 
    return _start_timer;
384
 
  }
385
 
 
386
 
  void getTimeDifference(boost::posix_time::time_duration &result_arg, const boost::posix_time::ptime &arg) const
387
 
  {
388
 
    result_arg=  arg - _start_timer;
389
 
  }
 
323
  enum_server_command command;
390
324
 
391
325
  thr_lock_type update_lock_default;
392
326
 
414
348
 
415
349
  session::Transactions& transaction;
416
350
  Open_tables_state& open_tables;
 
351
        session::Times& times;
417
352
 
418
353
  Field *dup_field;
419
354
  sigset_t signals;
801
736
   * slave.
802
737
   */
803
738
  void cleanup_after_query();
804
 
  bool storeGlobals();
 
739
  void storeGlobals();
805
740
  void awake(Session::killed_state_t state_to_set);
806
 
  /**
807
 
   * Pulls thread-specific variables into Session state.
808
 
   *
809
 
   * Returns true most times, or false if there was a problem
810
 
   * allocating resources for thread-specific storage.
811
 
   *
812
 
   * @TODO Kill this.  It's not necessary once my_thr_init() is bye bye.
813
 
   *
814
 
   */
815
 
  bool initGlobals();
816
741
 
817
742
  /**
818
743
    Initialize memory roots necessary for query processing and (!)
875
800
   * Returns true on success, or false on failure.
876
801
   */
877
802
  bool authenticate();
878
 
 
879
 
  /**
880
 
   * Run a session.
881
 
   *
882
 
   * This will initialize the session and begin the command loop.
883
 
   */
884
803
  void run();
885
 
 
886
 
  /**
887
 
   * Schedule a session to be run on the default scheduler.
888
 
   */
889
804
  static bool schedule(Session::shared_ptr&);
890
 
 
891
 
  static void unlink(session_id_t &session_id);
 
805
  static void unlink(session_id_t&);
892
806
  static void unlink(Session::shared_ptr&);
893
807
 
894
808
  /*
899
813
  const char* enter_cond(boost::condition_variable_any &cond, boost::mutex &mutex, const char* msg);
900
814
  void exit_cond(const char* old_msg);
901
815
 
902
 
  type::Time::epoch_t query_start()
903
 
  {
904
 
    return getCurrentTimestampEpoch();
905
 
  }
906
 
 
907
 
  void set_time()
908
 
  {
909
 
    _end_timer= _start_timer= boost::posix_time::microsec_clock::universal_time();
910
 
    utime_after_lock= (_start_timer - _epoch).total_microseconds();
911
 
  }
912
 
 
913
 
  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
914
 
  {
915
 
    _user_time= boost::posix_time::from_time_t(t);
916
 
  }
917
 
 
918
 
  void set_time_after_lock()
919
 
  {
920
 
    utime_after_lock= (boost::posix_time::microsec_clock::universal_time() - _epoch).total_microseconds();
921
 
  }
922
 
 
923
 
  void set_end_timer();
924
 
 
925
 
  uint64_t getElapsedTime() const
926
 
  {
927
 
    return (_end_timer - _start_timer).total_microseconds();
928
 
  }
929
 
 
930
 
  /**
931
 
   * Returns the current micro-timestamp
932
 
   */
933
 
  type::Time::epoch_t getCurrentTimestamp(bool actual= true) const
934
 
  {
935
 
    return ((actual ? boost::posix_time::microsec_clock::universal_time() : _end_timer) - _epoch).total_microseconds();
936
 
  }
937
 
 
938
 
  // We may need to set user on this
939
 
  type::Time::epoch_t getCurrentTimestampEpoch() const
940
 
  {
941
 
                return ((_user_time.is_not_a_date_time() ? _start_timer : _user_time) - _epoch).total_seconds();
942
 
  }
943
 
 
944
 
  type::Time::epoch_t getCurrentTimestampEpoch(type::Time::usec_t &fraction_arg) const
945
 
  {
946
 
    if (not _user_time.is_not_a_date_time())
947
 
    {
948
 
      fraction_arg= 0;
949
 
      return (_user_time - _epoch).total_seconds();
950
 
    }
951
 
 
952
 
    fraction_arg= _start_timer.time_of_day().fractional_seconds() % 1000000;
953
 
    return (_start_timer - _epoch).total_seconds();
954
 
  }
955
 
 
956
816
  uint64_t found_rows() const
957
817
  {
958
818
    return limit_found_rows;
979
839
  void fatal_error();
980
840
  bool is_error() const;
981
841
 
982
 
  inline const charset_info_st *charset() { return default_charset_info; }
 
842
  static const charset_info_st *charset() { return default_charset_info; }
983
843
 
984
844
  /**
985
845
    Cleanup statement parse state (parse tree, lex) and execution
1098
958
  bool checkUser(const std::string &passwd, const std::string &db);
1099
959
 
1100
960
  /**
1101
 
   * Returns the timestamp (in microseconds) of when the Session
1102
 
   * connected to the server.
1103
 
   */
1104
 
  uint64_t getConnectMicroseconds() const
1105
 
  {
1106
 
    return (_connect_time - _epoch).total_microseconds();
1107
 
  }
1108
 
 
1109
 
  uint64_t getConnectSeconds() const
1110
 
  {
1111
 
    return (_connect_time - _epoch).total_seconds();
1112
 
  }
1113
 
 
1114
 
  /**
1115
961
   * Returns a pointer to the active Transaction message for this
1116
962
   * Session being managed by the ReplicationServices component, or
1117
963
   * NULL if no active message.
1376
1222
  identifier::user::mptr security_ctx;
1377
1223
  int32_t scoreboard_index;
1378
1224
  plugin::Client *client;
1379
 
  util::string::shared_ptr _schema;
1380
1225
};
1381
1226
 
1382
1227
#define ESCAPE_CHARS "ntrb0ZN" // keep synchronous with READ_INFO::unescape