~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: Monty Taylor
  • Date: 2010-11-24 19:33:25 UTC
  • mto: (1953.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1955.
  • Revision ID: mordred@inaugust.com-20101124193325-7rxjg5jwto3lfms9
protobuf requires pthread. It's just the way it is.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "drizzled/util/storable.h"
38
38
#include "drizzled/my_hash.h"
39
39
#include "drizzled/pthread_globals.h"
 
40
 
40
41
#include <netdb.h>
41
 
#include <sys/time.h>
42
 
#include <sys/resource.h>
43
 
 
44
 
#include <algorithm>
 
42
#include <map>
 
43
#include <string>
45
44
#include <bitset>
46
45
#include <deque>
47
 
#include <map>
48
 
#include <string>
49
46
 
50
 
#include "drizzled/identifier.h"
 
47
#include "drizzled/internal/getrusage.h"
 
48
#include "drizzled/security_context.h"
51
49
#include "drizzled/open_tables_state.h"
52
50
#include "drizzled/internal_error_handler.h"
53
51
#include "drizzled/diagnostics_area.h"
59
57
#include <boost/thread/mutex.hpp>
60
58
#include <boost/thread/shared_mutex.hpp>
61
59
#include <boost/thread/condition_variable.hpp>
62
 
#include <boost/make_shared.hpp>
63
 
 
64
60
 
65
61
#define MIN_HANDSHAKE_SIZE      6
66
62
 
418
414
 
419
415
  void resetQueryString()
420
416
  {
421
 
    query.reset();
422
 
    _state.reset();
 
417
    return query.reset(new std::string);
423
418
  }
424
419
 
425
420
  /*
431
426
  {
432
427
    QueryString tmp_string(getQueryString());
433
428
 
434
 
    assert(tmp_string);
435
 
    if (not tmp_string)
436
 
    {
437
 
      length= 0;
438
 
      return 0;
439
 
    }
440
 
 
441
429
    length= tmp_string->length();
442
430
    char *to_return= strmake(tmp_string->c_str(), tmp_string->length());
443
431
    return to_return;
444
432
  }
445
433
 
446
 
  class State {
447
 
    std::vector <char> _query;
448
 
 
449
 
  public:
450
 
    typedef boost::shared_ptr<State> const_shared_ptr;
451
 
 
452
 
    State(const char *in_packet, size_t in_packet_length)
453
 
    {
454
 
      if (in_packet_length)
455
 
      {
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);
459
 
      }
460
 
      else
461
 
      {
462
 
        _query.resize(0);
463
 
      }
464
 
    }
465
 
 
466
 
    const char *query() const
467
 
    {
468
 
      if (_query.size())
469
 
        return &_query[0];
470
 
 
471
 
      return "";
472
 
    }
473
 
 
474
 
    const char *query(size_t &size) const
475
 
    {
476
 
      if (_query.size())
477
 
      {
478
 
        size= _query.size() -1;
479
 
        return &_query[0];
480
 
      }
481
 
 
482
 
      size= 0;
483
 
      return "";
484
 
    }
485
 
  protected:
486
 
    friend class Session;
487
 
    typedef boost::shared_ptr<State> shared_ptr;
488
 
  };
489
 
private:
490
 
  State::shared_ptr  _state; 
491
 
public:
492
 
 
493
 
  State::const_shared_ptr state()
494
 
  {
495
 
    return _state;
496
 
  }
497
 
 
498
434
  /**
499
435
    Name of the current (default) database.
500
436
 
507
443
    the Session of that thread); that thread is (and must remain, for now) the
508
444
    only responsible for freeing this member.
509
445
  */
510
 
private:
511
 
  util::string::shared_ptr _schema;
512
 
public:
 
446
  std::string db;
513
447
 
514
 
  util::string::const_shared_ptr schema() const
 
448
  const std::string &getSchema() const
515
449
  {
516
 
    if (_schema)
517
 
      return _schema;
518
 
 
519
 
    return util::string::const_shared_ptr(new std::string(""));
 
450
    return db;
520
451
  }
521
452
  std::string catalog;
522
453
  /* current cache key */
567
498
  char *thread_stack;
568
499
 
569
500
private:
570
 
  identifier::User::shared_ptr security_ctx;
 
501
  SecurityContext security_ctx;
571
502
 
572
503
  int32_t scoreboard_index;
573
504
 
576
507
    assert(this->dbug_sentry == Session_SENTRY_MAGIC);
577
508
  }
578
509
public:
579
 
  identifier::User::const_shared_ptr user() const
 
510
  const SecurityContext& getSecurityContext() const
580
511
  {
581
 
    if (security_ctx)
582
 
      return security_ctx;
583
 
 
584
 
    return identifier::User::const_shared_ptr();
 
512
    return security_ctx;
585
513
  }
586
514
 
587
 
  void setUser(identifier::User::shared_ptr arg)
 
515
  SecurityContext& getSecurityContext()
588
516
  {
589
 
    security_ctx= arg;
 
517
    return security_ctx;
590
518
  }
591
519
 
592
520
  int32_t getScoreboardIndex()
934
862
    return &_killed;
935
863
  }
936
864
 
937
 
  bool is_admin_connection;
938
865
  bool some_tables_deleted;
939
866
  bool no_errors;
940
867
  bool password;
1380
1307
    database usually involves other actions, like switching other database
1381
1308
    attributes including security context. In the future, this operation
1382
1309
    will be made private and more convenient interface will be provided.
 
1310
 
 
1311
    @return Operation status
 
1312
      @retval false Success
 
1313
      @retval true  Out-of-memory error
1383
1314
  */
1384
 
  void set_db(const std::string &new_db);
 
1315
  bool set_db(const std::string &new_db);
1385
1316
 
1386
1317
  /*
1387
1318
    Copy the current database to the argument. Use the current arena to
1672
1603
  void close_old_data_files(bool morph_locks= false,
1673
1604
                            bool send_refresh= false);
1674
1605
  void close_open_tables();
1675
 
  void close_data_files_and_morph_locks(const TableIdentifier &identifier);
 
1606
  void close_data_files_and_morph_locks(TableIdentifier &identifier);
1676
1607
 
1677
1608
private:
1678
1609
  bool free_cached_table();
1709
1640
  Table *openTable(TableList *table_list, bool *refresh, uint32_t flags= 0);
1710
1641
 
1711
1642
  void unlink_open_table(Table *find);
1712
 
  void drop_open_table(Table *table, const TableIdentifier &identifier);
 
1643
  void drop_open_table(Table *table, TableIdentifier &identifier);
1713
1644
  void close_cached_table(Table *table);
1714
1645
 
1715
1646
  /* Create a lock in the cache */
1716
1647
  table::Placeholder *table_cache_insert_placeholder(const TableIdentifier &identifier);
1717
 
  bool lock_table_name_if_not_cached(const TableIdentifier &identifier, Table **table);
 
1648
  bool lock_table_name_if_not_cached(TableIdentifier &identifier, Table **table);
1718
1649
 
1719
1650
  typedef boost::unordered_map<std::string, message::Table, util::insensitive_hash, util::insensitive_equal_to> TableMessageCache;
1720
1651
 
1890
1821
static const std::bitset<CF_BIT_SIZE> CF_SHOW_TABLE_COMMAND(1 << CF_BIT_SHOW_TABLE_COMMAND);
1891
1822
static const std::bitset<CF_BIT_SIZE> CF_WRITE_LOGS_COMMAND(1 << CF_BIT_WRITE_LOGS_COMMAND);
1892
1823
 
1893
 
namespace display  {
1894
 
const std::string &type(drizzled::Session::global_read_lock_t type);
1895
 
size_t max_string_length(drizzled::Session::global_read_lock_t type);
1896
 
} /* namespace display */
1897
 
 
1898
1824
} /* namespace drizzled */
1899
1825
 
1900
1826
#endif /* DRIZZLED_SESSION_H */