~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Lee Bieber
  • Date: 2011-04-14 16:20:43 UTC
  • mfrom: (2277.1.3 build)
  • Revision ID: kalebral@gmail.com-20110414162043-2khq8mql7gvodnzn
Merge Olaf - Refactor Session Cache and Remove table::Cache::singleton()
Merge Olaf - Refactor Thread
Merge Olaf - remove unused functions

Show diffs side-by-side

added added

removed removed

Lines of Context:
160
160
 
161
161
  @param session Thread context (may be NULL)
162
162
  @param tables List of tables to remove from the cache
163
 
  @param have_lock If table::Cache::singleton().mutex() is locked
 
163
  @param have_lock If table::Cache::mutex() is locked
164
164
  @param wait_for_refresh Wait for a impending flush
165
165
  @param wait_for_placeholders Wait for tables being reopened so that the GRL
166
166
  won't proceed while write-locked tables are being reopened by other
176
176
  Session *session= this;
177
177
 
178
178
  {
179
 
    boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex()); /* Optionally lock for remove tables from open_cahe if not in use */
 
179
    boost::mutex::scoped_lock scopedLock(table::Cache::mutex()); /* Optionally lock for remove tables from open_cahe if not in use */
180
180
 
181
181
    if (tables == NULL)
182
182
    {
213
213
          again. There they will wait until we update all tables version
214
214
          below.
215
215
 
216
 
          Setting some_tables_deleted is done by table::Cache::singleton().removeTable()
 
216
          Setting some_tables_deleted is done by table::Cache::removeTable()
217
217
          in the other branch.
218
218
 
219
219
          In other words (reviewer suggestion): You need this setting of
235
235
      bool found= false;
236
236
      for (TableList *table= tables; table; table= table->next_local)
237
237
      {
238
 
        if (table::Cache::singleton().removeTable(*session, identifier::Table(table->getSchemaName(), table->getTableName()), RTFC_OWNED_BY_Session_FLAG))
 
238
        if (table::Cache::removeTable(*session, identifier::Table(table->getSchemaName(), table->getTableName()), RTFC_OWNED_BY_Session_FLAG))
239
239
        {
240
240
          found= true;
241
241
        }
250
250
        If there is any table that has a lower refresh_version, wait until
251
251
        this is closed (or this thread is killed) before returning
252
252
      */
253
 
      session->mysys_var->current_mutex= &table::Cache::singleton().mutex();
 
253
      session->mysys_var->current_mutex= &table::Cache::mutex();
254
254
      session->mysys_var->current_cond= &COND_refresh;
255
255
      session->set_proc_info("Flushing tables");
256
256
 
314
314
 
315
315
  if (wait_for_refresh)
316
316
  {
317
 
    boost_unique_lock_t scopedLock(session->mysys_var->mutex);
 
317
    boost::mutex::scoped_lock scopedLock(session->mysys_var->mutex);
318
318
    session->mysys_var->current_mutex= 0;
319
319
    session->mysys_var->current_cond= 0;
320
320
    session->set_proc_info(0);
336
336
 
337
337
  table::Concurrent *table= static_cast<table::Concurrent *>(open_tables.open_tables_);
338
338
 
339
 
  safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle());
 
339
  safe_mutex_assert_owner(table::Cache::mutex().native_handle());
340
340
  assert(table->key_read == 0);
341
341
  assert(!table->cursor || table->cursor->inited == Cursor::NONE);
342
342
 
379
379
{
380
380
  bool found_old_table= false;
381
381
 
382
 
  safe_mutex_assert_not_owner(table::Cache::singleton().mutex().native_handle());
 
382
  safe_mutex_assert_not_owner(table::Cache::mutex().native_handle());
383
383
 
384
 
  boost_unique_lock_t scoped_lock(table::Cache::singleton().mutex()); /* Close all open tables on Session */
 
384
  boost::mutex::scoped_lock scoped_lock(table::Cache::mutex()); /* Close all open tables on Session */
385
385
 
386
386
  while (open_tables.open_tables_)
387
387
  {
662
662
{
663
663
  const identifier::Table::Key find_key(find->getShare()->getCacheKey());
664
664
  Table **prev;
665
 
  safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle());
 
665
  safe_mutex_assert_owner(table::Cache::mutex().native_handle());
666
666
 
667
667
  /*
668
 
    Note that we need to hold table::Cache::singleton().mutex() while changing the
 
668
    Note that we need to hold table::Cache::mutex() while changing the
669
669
    open_tables list. Another thread may work on it.
670
 
    (See: table::Cache::singleton().removeTable(), wait_completed_table())
 
670
    (See: table::Cache::removeTable(), wait_completed_table())
671
671
    Closing a MERGE child before the parent would be fatal if the
672
672
    other thread tries to abort the MERGE lock in between.
673
673
  */
722
722
  }
723
723
  else
724
724
  {
725
 
    boost_unique_lock_t scoped_lock(table::Cache::singleton().mutex()); /* Close and drop a table (AUX routine) */
 
725
    boost::mutex::scoped_lock scoped_lock(table::Cache::mutex()); /* Close and drop a table (AUX routine) */
726
726
    /*
727
727
      unlink_open_table() also tells threads waiting for refresh or close
728
728
      that something has happened.
763
763
      condition variables that are guranteed to not disapper (freed) even if this
764
764
      mutex is unlocked
765
765
    */
766
 
    boost_unique_lock_t scopedLock(mutex, boost::adopt_lock_t());
 
766
    boost::mutex::scoped_lock scopedLock(mutex, boost::adopt_lock_t());
767
767
    if (not getKilled())
768
768
    {
769
769
      cond.wait(scopedLock);
770
770
    }
771
771
  }
772
 
  boost_unique_lock_t mysys_scopedLock(mysys_var->mutex);
 
772
  boost::mutex::scoped_lock mysys_scopedLock(mysys_var->mutex);
773
773
  mysys_var->current_mutex= 0;
774
774
  mysys_var->current_cond= 0;
775
775
  set_proc_info(saved_proc_info);
791
791
 
792
792
table::Placeholder *Session::table_cache_insert_placeholder(const drizzled::identifier::Table &arg)
793
793
{
794
 
  safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle());
 
794
  safe_mutex_assert_owner(table::Cache::mutex().native_handle());
795
795
 
796
796
  /*
797
797
    Create a table entry with the right key and with an old refresh version
798
798
  */
799
799
  identifier::Table identifier(arg.getSchemaName(), arg.getTableName(), message::Table::INTERNAL);
800
800
  table::Placeholder *table= new table::Placeholder(this, identifier);
801
 
  table::Cache::singleton().insert(table);
 
801
  table::Cache::insert(table);
802
802
  return table; // return ref
803
803
}
804
804
 
828
828
{
829
829
  const identifier::Table::Key &key(identifier.getKey());
830
830
 
831
 
  boost_unique_lock_t scope_lock(table::Cache::singleton().mutex()); /* Obtain a name lock even though table is not in cache (like for create table)  */
 
831
  boost::mutex::scoped_lock scope_lock(table::Cache::mutex()); /* Obtain a name lock even though table is not in cache (like for create table)  */
832
832
 
833
833
  if (find_ptr(table::getCache(), key))
834
834
  {
973
973
      until no one holds a name lock on the table.
974
974
      - if there is no such Table in the name cache, read the table definition
975
975
      and insert it into the cache.
976
 
      We perform all of the above under table::Cache::singleton().mutex() which currently protects
 
976
      We perform all of the above under table::Cache::mutex() which currently protects
977
977
      the open cache (also known as table cache) and table definitions stored
978
978
      on disk.
979
979
    */
980
980
 
981
981
    {
982
 
      boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex());
 
982
      boost::mutex::scoped_lock scopedLock(table::Cache::mutex());
983
983
 
984
984
      /*
985
985
        Actually try to find the table in the open_cache.
1062
1062
          */
1063
1063
          if (table->in_use != this)
1064
1064
          {
1065
 
            /* wait_for_conditionwill unlock table::Cache::singleton().mutex() for us */
1066
 
            wait_for_condition(table::Cache::singleton().mutex(), COND_refresh);
 
1065
            /* wait_for_conditionwill unlock table::Cache::mutex() for us */
 
1066
            wait_for_condition(table::Cache::mutex(), COND_refresh);
1067
1067
            scopedLock.release();
1068
1068
          }
1069
1069
          else
1131
1131
            delete new_table;
1132
1132
            return NULL;
1133
1133
          }
1134
 
          (void)table::Cache::singleton().insert(new_table);
 
1134
          (void)table::Cache::insert(new_table);
1135
1135
        }
1136
1136
      }
1137
1137
    }
1195
1195
 
1196
1196
void Session::close_data_files_and_morph_locks(const identifier::Table &identifier)
1197
1197
{
1198
 
  safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle()); /* Adjust locks at the end of ALTER TABLEL */
 
1198
  safe_mutex_assert_owner(table::Cache::mutex().native_handle()); /* Adjust locks at the end of ALTER TABLEL */
1199
1199
 
1200
1200
  if (open_tables.lock)
1201
1201
  {
1238
1238
  combination when one needs tables to be reopened (for
1239
1239
  example see openTablesLock()).
1240
1240
 
1241
 
  @note One should have lock on table::Cache::singleton().mutex() when calling this.
 
1241
  @note One should have lock on table::Cache::mutex() when calling this.
1242
1242
 
1243
1243
  @return false in case of success, true - otherwise.
1244
1244
*/
1256
1256
  if (open_tables.open_tables_ == NULL)
1257
1257
    return false;
1258
1258
 
1259
 
  safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle());
 
1259
  safe_mutex_assert_owner(table::Cache::mutex().native_handle());
1260
1260
  {
1261
1261
    /*
1262
1262
      The ptr is checked later
1289
1289
    DrizzleLock *local_lock;
1290
1290
    /*
1291
1291
      We should always get these locks. Anyway, we must not go into
1292
 
      wait_for_tables() as it tries to acquire table::Cache::singleton().mutex(), which is
 
1292
      wait_for_tables() as it tries to acquire table::Cache::mutex(), which is
1293
1293
      already locked.
1294
1294
    */
1295
1295
    some_tables_deleted= false;
1434
1434
  prev= &session->open_tables.open_tables_;
1435
1435
 
1436
1436
  /*
1437
 
    Note that we need to hold table::Cache::singleton().mutex() while changing the
 
1437
    Note that we need to hold table::Cache::mutex() while changing the
1438
1438
    open_tables list. Another thread may work on it.
1439
 
    (See: table::Cache::singleton().removeTable(), wait_completed_table())
 
1439
    (See: table::Cache::removeTable(), wait_completed_table())
1440
1440
    Closing a MERGE child before the parent would be fatal if the
1441
1441
    other thread tries to abort the MERGE lock in between.
1442
1442
  */