~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.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:
126
126
 
127
127
  do
128
128
  {
129
 
    boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex());
 
129
    boost::mutex::scoped_lock scopedLock(table::Cache::mutex());
130
130
 
131
131
    if (not drop_temporary && session->lock_table_names_exclusively(tables))
132
132
    {
157
157
      if (drop_temporary == false)
158
158
      {
159
159
        abort_locked_tables(session, tmp_identifier);
160
 
        table::Cache::singleton().removeTable(*session, tmp_identifier, RTFC_WAIT_OTHER_THREAD_FLAG | RTFC_CHECK_KILLED_FLAG);
 
160
        table::Cache::removeTable(*session, tmp_identifier, RTFC_WAIT_OTHER_THREAD_FLAG | RTFC_CHECK_KILLED_FLAG);
161
161
        /*
162
162
          If the table was used in lock tables, remember it so that
163
163
          unlock_table_names can free it
1338
1338
      /*
1339
1339
        @todo improve this error condition.
1340
1340
      */
1341
 
      if (definition::Cache::singleton().find(identifier.getKey()))
 
1341
      if (definition::Cache::find(identifier.getKey()))
1342
1342
      {
1343
1343
        my_error(ER_TABLE_EXISTS_ERROR, identifier);
1344
1344
 
1448
1448
                               &key_info_buffer, &key_count,
1449
1449
                               select_field_count))
1450
1450
  {
1451
 
    boost_unique_lock_t lock(table::Cache::singleton().mutex()); /* CREATE TABLE (some confussion on naming, double check) */
 
1451
    boost::mutex::scoped_lock lock(table::Cache::mutex()); /* CREATE TABLE (some confussion on naming, double check) */
1452
1452
    error= locked_create_event(session,
1453
1453
                               identifier,
1454
1454
                               create_info,
1514
1514
 
1515
1515
  if (name_lock)
1516
1516
  {
1517
 
    boost_unique_lock_t lock(table::Cache::singleton().mutex()); /* Lock for removing name_lock during table create */
 
1517
    boost::mutex::scoped_lock lock(table::Cache::mutex()); /* Lock for removing name_lock during table create */
1518
1518
    session->unlink_open_table(name_lock);
1519
1519
  }
1520
1520
 
1659
1659
   the table is closed.
1660
1660
 
1661
1661
  PREREQUISITES
1662
 
    Lock on table::Cache::singleton().mutex()
 
1662
    Lock on table::Cache::mutex()
1663
1663
    Win32 clients must also have a WRITE LOCK on the table !
1664
1664
*/
1665
1665
 
1667
1667
                              enum ha_extra_function function)
1668
1668
{
1669
1669
 
1670
 
  safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle());
 
1670
  safe_mutex_assert_owner(table::Cache::mutex().native_handle());
1671
1671
 
1672
1672
  table->cursor->extra(function);
1673
1673
  /* Mark all tables that are in use as 'old' */
1675
1675
 
1676
1676
  /* Wait until all there are no other threads that has this table open */
1677
1677
  identifier::Table identifier(table->getShare()->getSchemaName(), table->getShare()->getTableName());
1678
 
  table::Cache::singleton().removeTable(*session, identifier, RTFC_WAIT_OTHER_THREAD_FLAG);
 
1678
  table::Cache::removeTable(*session, identifier, RTFC_WAIT_OTHER_THREAD_FLAG);
1679
1679
}
1680
1680
 
1681
1681
/*
1691
1691
    reopen the table.
1692
1692
 
1693
1693
  PREREQUISITES
1694
 
    Lock on table::Cache::singleton().mutex()
 
1694
    Lock on table::Cache::mutex()
1695
1695
    Win32 clients must also have a WRITE LOCK on the table !
1696
1696
*/
1697
1697
 
1708
1708
  /* Close all copies of 'table'.  This also frees all LOCK TABLES lock */
1709
1709
  unlink_open_table(table);
1710
1710
 
1711
 
  /* When lock on table::Cache::singleton().mutex() is freed other threads can continue */
 
1711
  /* When lock on table::Cache::mutex() is freed other threads can continue */
1712
1712
  locking::broadcast_refresh();
1713
1713
}
1714
1714
 
1822
1822
    /* Close all instances of the table to allow repair to rename files */
1823
1823
    if (lock_type == TL_WRITE && table->table->getShare()->getVersion())
1824
1824
    {
1825
 
      table::Cache::singleton().mutex().lock(); /* Lock type is TL_WRITE and we lock to repair the table */
1826
 
      const char *old_message=session->enter_cond(COND_refresh, table::Cache::singleton().mutex(),
 
1825
      table::Cache::mutex().lock(); /* Lock type is TL_WRITE and we lock to repair the table */
 
1826
      const char *old_message=session->enter_cond(COND_refresh, table::Cache::mutex(),
1827
1827
                                                  "Waiting to get writelock");
1828
1828
      session->abortLock(table->table);
1829
1829
      identifier::Table identifier(table->table->getShare()->getSchemaName(), table->table->getShare()->getTableName());
1830
 
      table::Cache::singleton().removeTable(*session, identifier, RTFC_WAIT_OTHER_THREAD_FLAG | RTFC_CHECK_KILLED_FLAG);
 
1830
      table::Cache::removeTable(*session, identifier, RTFC_WAIT_OTHER_THREAD_FLAG | RTFC_CHECK_KILLED_FLAG);
1831
1831
      session->exit_cond(old_message);
1832
1832
      if (session->getKilled())
1833
1833
        goto err;
1927
1927
        }
1928
1928
        else
1929
1929
        {
1930
 
          boost::unique_lock<boost::mutex> lock(table::Cache::singleton().mutex());
 
1930
          boost::unique_lock<boost::mutex> lock(table::Cache::mutex());
1931
1931
          identifier::Table identifier(table->table->getShare()->getSchemaName(), table->table->getShare()->getTableName());
1932
 
          table::Cache::singleton().removeTable(*session, identifier, RTFC_NO_FLAG);
 
1932
          table::Cache::removeTable(*session, identifier, RTFC_NO_FLAG);
1933
1933
        }
1934
1934
      }
1935
1935
    }
1959
1959
    Altough exclusive name-lock on target table protects us from concurrent
1960
1960
    DML and DDL operations on it we still want to wrap .FRM creation and call
1961
1961
    to plugin::StorageEngine::createTable() in critical section protected by
1962
 
    table::Cache::singleton().mutex() in order to provide minimal atomicity against operations which
 
1962
    table::Cache::mutex() in order to provide minimal atomicity against operations which
1963
1963
    disregard name-locks, like I_S implementation, for example. This is a
1964
1964
    temporary and should not be copied. Instead we should fix our code to
1965
1965
    always honor name-locks.
1966
1966
 
1967
 
    Also some engines (e.g. NDB cluster) require that table::Cache::singleton().mutex() should be held
 
1967
    Also some engines (e.g. NDB cluster) require that table::Cache::mutex() should be held
1968
1968
    during the call to plugin::StorageEngine::createTable().
1969
1969
    See bug #28614 for more info.
1970
1970
  */
2110
2110
    {
2111
2111
      if (name_lock)
2112
2112
      {
2113
 
        boost_unique_lock_t lock(table::Cache::singleton().mutex()); /* unlink open tables for create table like*/
 
2113
        boost::mutex::scoped_lock lock(table::Cache::mutex()); /* unlink open tables for create table like*/
2114
2114
        session->unlink_open_table(name_lock);
2115
2115
      }
2116
2116
 
2129
2129
    {
2130
2130
      bool was_created;
2131
2131
      {
2132
 
        boost_unique_lock_t lock(table::Cache::singleton().mutex()); /* We lock for CREATE TABLE LIKE to copy table definition */
 
2132
        boost::mutex::scoped_lock lock(table::Cache::mutex()); /* We lock for CREATE TABLE LIKE to copy table definition */
2133
2133
        was_created= create_table_wrapper(*session, create_table_proto, destination_identifier,
2134
2134
                                          source_identifier, is_engine_set);
2135
2135
      }
2148
2148
 
2149
2149
    if (name_lock)
2150
2150
    {
2151
 
      boost_unique_lock_t lock(table::Cache::singleton().mutex()); /* unlink open tables for create table like*/
 
2151
      boost::mutex::scoped_lock lock(table::Cache::mutex()); /* unlink open tables for create table like*/
2152
2152
      session->unlink_open_table(name_lock);
2153
2153
    }
2154
2154
  }