~thomir-deactivatedaccount/drizzle/drizzle-fix-bug653747

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Brian Aker
  • Date: 2010-10-10 02:07:52 UTC
  • mfrom: (1827.2.3 staging)
  • Revision ID: brian@tangent.org-20101010020752-ktv73isay5dxtvp3
Merge in switch on table_share_instance inheritance.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
#include "drizzled/internal/iocache.h"
54
54
#include "drizzled/drizzled.h"
55
55
#include "drizzled/plugin/authorization.h"
56
 
#include "drizzled/table/temporary.h"
57
 
#include "drizzled/table/placeholder.h"
 
56
#include "drizzled/table_placeholder.h"
58
57
 
59
58
using namespace std;
60
59
 
248
247
 
249
248
void close_handle_and_leave_table_as_lock(Table *table)
250
249
{
 
250
  TableShare *share, *old_share= table->getMutableShare();
251
251
  assert(table->db_stat);
252
252
  assert(table->getShare()->getType() == message::Table::STANDARD);
253
253
 
258
258
  */
259
259
  TableIdentifier identifier(table->getShare()->getSchemaName(), table->getShare()->getTableName(), message::Table::INTERNAL);
260
260
  const TableIdentifier::Key &key(identifier.getKey());
261
 
  TableShare *share= new TableShare(identifier.getType(),
262
 
                                    identifier,
263
 
                                    const_cast<char *>(&key[0]),  static_cast<uint32_t>(table->getShare()->getCacheKeySize()));
 
261
  share= new TableShare(identifier.getType(),
 
262
                        identifier,
 
263
                        const_cast<char *>(&key[0]),  static_cast<uint32_t>(old_share->getCacheKeySize()));
264
264
 
265
265
  table->cursor->close();
266
266
  table->db_stat= 0;                            // Mark cursor closed
456
456
                                                     (table->open_placeholder && wait_for_placeholders)))
457
457
          {
458
458
            found= true;
459
 
            boost_unique_lock_t scoped(LOCK_open, boost::adopt_lock_t());
 
459
            boost::mutex::scoped_lock scoped(LOCK_open, boost::adopt_lock_t());
460
460
            COND_refresh.wait(scoped);
461
461
            scoped.release();
462
462
            break;
487
487
 
488
488
  if (wait_for_refresh)
489
489
  {
490
 
    boost_unique_lock_t scopedLock(session->mysys_var->mutex);
 
490
    boost::mutex::scoped_lock scopedLock(session->mysys_var->mutex);
491
491
    session->mysys_var->current_mutex= 0;
492
492
    session->mysys_var->current_cond= 0;
493
493
    session->set_proc_info(0);
551
551
 
552
552
  safe_mutex_assert_not_owner(LOCK_open.native_handle());
553
553
 
554
 
  boost_unique_lock_t scoped_lock(LOCK_open); /* Close all open tables on Session */
 
554
  boost::mutex::scoped_lock scoped_lock(LOCK_open); /* Close all open tables on Session */
555
555
 
556
556
  while (open_tables)
557
557
  {
858
858
  Table *list, **prev;
859
859
  safe_mutex_assert_owner(LOCK_open.native_handle());
860
860
 
861
 
  memcpy(key, &find->getShare()->getCacheKey()[0], key_length);
 
861
  memcpy(key, &find->getMutableShare()->getCacheKey()[0], key_length);
862
862
  /*
863
863
    Note that we need to hold LOCK_open while changing the
864
864
    open_tables list. Another thread may work on it.
918
918
  }
919
919
  else
920
920
  {
921
 
    boost_unique_lock_t scoped_lock(LOCK_open); /* Close and drop a table (AUX routine) */
 
921
    boost::mutex::scoped_lock scoped_lock(LOCK_open); /* Close and drop a table (AUX routine) */
922
922
    /*
923
923
      unlink_open_table() also tells threads waiting for refresh or close
924
924
      that something has happened.
940
940
  cond  Condition to wait for
941
941
*/
942
942
 
943
 
void Session::wait_for_condition(boost::mutex &mutex, boost::condition_variable_any &cond)
 
943
void Session::wait_for_condition(boost::mutex &mutex, boost::condition_variable &cond)
944
944
{
945
945
  /* Wait until the current table is up to date */
946
946
  const char *saved_proc_info;
959
959
      condition variables that are guranteed to not disapper (freed) even if this
960
960
      mutex is unlocked
961
961
    */
962
 
    boost_unique_lock_t scopedLock(mutex, boost::adopt_lock_t());
 
962
    boost::mutex::scoped_lock scopedLock(mutex, boost::adopt_lock_t());
963
963
    if (not killed)
964
964
    {
965
965
      cond.wait(scopedLock);
966
966
    }
967
967
  }
968
 
  boost_unique_lock_t mysys_scopedLock(mysys_var->mutex);
 
968
  boost::mutex::scoped_lock (mysys_var->mutex);
969
969
  mysys_var->current_mutex= 0;
970
970
  mysys_var->current_cond= 0;
971
971
  set_proc_info(saved_proc_info);
998
998
bool Session::reopen_name_locked_table(TableList* table_list, bool link_in)
999
999
{
1000
1000
  Table *table= table_list->table;
 
1001
  TableShare *share;
1001
1002
  char *table_name= table_list->table_name;
1002
1003
  Table orig_table;
1003
1004
 
1022
1023
    return true;
1023
1024
  }
1024
1025
 
 
1026
  share= table->getMutableShare();
1025
1027
  /*
1026
1028
    We want to prevent other connections from opening this table until end
1027
1029
    of statement as it is likely that modifications of table's metadata are
1030
1032
    This also allows us to assume that no other connection will sneak in
1031
1033
    before we will get table-level lock on this table.
1032
1034
  */
1033
 
  table->getMutableShare()->resetVersion();
 
1035
  share->resetVersion();
1034
1036
  table->in_use = this;
1035
1037
 
1036
1038
  if (link_in)
1080
1082
    Create a table entry with the right key and with an old refresh version
1081
1083
  */
1082
1084
  TableIdentifier identifier(db_name, table_name, message::Table::INTERNAL);
1083
 
  table::Placeholder *table= new table::Placeholder(this, identifier);
 
1085
  TablePlaceholder *table= new TablePlaceholder(this, identifier);
1084
1086
 
1085
1087
  if (not add_table(table))
1086
1088
  {
1118
1120
{
1119
1121
  const TableIdentifier::Key &key(identifier.getKey());
1120
1122
 
1121
 
  boost_unique_lock_t scope_lock(LOCK_open); /* Obtain a name lock even though table is not in cache (like for create table)  */
 
1123
  boost::mutex::scoped_lock scope_lock(LOCK_open); /* Obtain a name lock even though table is not in cache (like for create table)  */
1122
1124
 
1123
1125
  TableOpenCache::iterator iter;
1124
1126
 
1334
1336
          if (table->open_placeholder && table->in_use == this)
1335
1337
          {
1336
1338
            LOCK_open.unlock();
1337
 
            my_error(ER_UPDATE_TABLE_USED, MYF(0), table->getShare()->getTableName());
 
1339
            my_error(ER_UPDATE_TABLE_USED, MYF(0), table->getMutableShare()->getTableName());
1338
1340
            return NULL;
1339
1341
          }
1340
1342
 
1762
1764
 
1763
1765
  session->set_proc_info("Waiting for tables");
1764
1766
  {
1765
 
    boost_unique_lock_t lock(LOCK_open);
 
1767
    boost::mutex::scoped_lock lock(LOCK_open);
1766
1768
    while (!session->killed)
1767
1769
    {
1768
1770
      session->some_tables_deleted= false;
1907
1909
                             TableIdentifier &identifier)
1908
1910
{
1909
1911
  int error;
1910
 
  TableSharePtr share;
 
1912
  TableShare *share;
1911
1913
  uint32_t discover_retry_count= 0;
1912
1914
 
1913
1915
  safe_mutex_assert_owner(LOCK_open.native_handle());
2257
2259
                        const_cast<char *>(identifier.getPath().c_str()), static_cast<uint32_t>(identifier.getPath().length()));
2258
2260
 
2259
2261
 
2260
 
  table::Temporary *new_tmp_table= new table::Temporary;
 
2262
  Table *new_tmp_table= new Table;
2261
2263
  if (not new_tmp_table)
2262
2264
    return NULL;
2263
2265
 
4401
4403
  {
4402
4404
    Table *table= (*iter).second;
4403
4405
 
4404
 
    if (not schema_identifier.getPath().compare(table->getShare()->getSchemaName()))
 
4406
    if (not schema_identifier.getPath().compare(table->getMutableShare()->getSchemaName()))
4405
4407
    {
4406
4408
      table->getMutableShare()->resetVersion();                 /* Free when thread is ready */
4407
4409
      if (not table->in_use)
4503
4505
        dropping_tables++;
4504
4506
        if (likely(signalled))
4505
4507
        {
4506
 
          boost_unique_lock_t scoped(LOCK_open, boost::adopt_lock_t());
 
4508
          boost::mutex::scoped_lock scoped(LOCK_open, boost::adopt_lock_t());
4507
4509
          COND_refresh.wait(scoped);
4508
4510
          scoped.release();
4509
4511
        }
4522
4524
          boost::xtime xt; 
4523
4525
          xtime_get(&xt, boost::TIME_UTC); 
4524
4526
          xt.sec += 10; 
4525
 
          boost_unique_lock_t scoped(LOCK_open, boost::adopt_lock_t());
 
4527
          boost::mutex::scoped_lock scoped(LOCK_open, boost::adopt_lock_t());
4526
4528
          COND_refresh.timed_wait(scoped, xt);
4527
4529
          scoped.release();
4528
4530
        }