~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Brian Aker
  • Date: 2010-11-23 02:01:23 UTC
  • mfrom: (1938.4.13 trunk)
  • mto: This revision was merged to the branch mainline in revision 1947.
  • Revision ID: brian@tangent.org-20101123020123-dillrqm8atzpkka7
Merge in lock encapsulation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
148
148
  int error= 0;
149
149
  bool foreign_key_error= false;
150
150
 
151
 
  LOCK_open.lock(); /* Part 2 of rm a table */
 
151
  table::Cache::singleton().mutex().lock(); /* Part 2 of rm a table */
152
152
 
153
153
  if (not drop_temporary && session->lock_table_names_exclusively(tables))
154
154
  {
155
 
    LOCK_open.unlock();
 
155
    table::Cache::singleton().mutex().unlock();
156
156
    return 1;
157
157
  }
158
158
 
240
240
    }
241
241
  }
242
242
  /*
243
 
    It's safe to unlock LOCK_open: we have an exclusive lock
 
243
    It's safe to unlock table::Cache::singleton().mutex(): we have an exclusive lock
244
244
    on the table name.
245
245
  */
246
 
  LOCK_open.unlock();
 
246
  table::Cache::singleton().mutex().unlock();
247
247
  error= 0;
248
248
 
249
249
  if (wrong_tables.length())
260
260
    error= 1;
261
261
  }
262
262
 
263
 
  LOCK_open.lock(); /* final bit in rm table lock */
 
263
  table::Cache::singleton().mutex().lock(); /* final bit in rm table lock */
264
264
 
265
265
err_with_placeholders:
266
266
  tables->unlock_table_names();
267
 
  LOCK_open.unlock();
 
267
  table::Cache::singleton().mutex().unlock();
268
268
  session->no_warnings_for_error= 0;
269
269
 
270
270
  return error;
1445
1445
                                     &key_info_buffer, &key_count,
1446
1446
                                     select_field_count))
1447
1447
  {
1448
 
    boost_unique_lock_t lock(LOCK_open); /* CREATE TABLE (some confussion on naming, double check) */
 
1448
    boost_unique_lock_t lock(table::Cache::singleton().mutex()); /* CREATE TABLE (some confussion on naming, double check) */
1449
1449
    error= locked_create_event(session,
1450
1450
                               identifier,
1451
1451
                               create_info,
1511
1511
 
1512
1512
  if (name_lock)
1513
1513
  {
1514
 
    boost_unique_lock_t lock(LOCK_open); /* Lock for removing name_lock during table create */
 
1514
    boost_unique_lock_t lock(table::Cache::singleton().mutex()); /* Lock for removing name_lock during table create */
1515
1515
    session->unlink_open_table(name_lock);
1516
1516
  }
1517
1517
 
1665
1665
   the table is closed.
1666
1666
 
1667
1667
  PREREQUISITES
1668
 
    Lock on LOCK_open
 
1668
    Lock on table::Cache::singleton().mutex()
1669
1669
    Win32 clients must also have a WRITE LOCK on the table !
1670
1670
*/
1671
1671
 
1673
1673
                              enum ha_extra_function function)
1674
1674
{
1675
1675
 
1676
 
  safe_mutex_assert_owner(LOCK_open.native_handle());
 
1676
  safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle());
1677
1677
 
1678
1678
  table->cursor->extra(function);
1679
1679
  /* Mark all tables that are in use as 'old' */
1697
1697
    reopen the table.
1698
1698
 
1699
1699
  PREREQUISITES
1700
 
    Lock on LOCK_open
 
1700
    Lock on table::Cache::singleton().mutex()
1701
1701
    Win32 clients must also have a WRITE LOCK on the table !
1702
1702
*/
1703
1703
 
1714
1714
  /* Close all copies of 'table'.  This also frees all LOCK TABLES lock */
1715
1715
  unlink_open_table(table);
1716
1716
 
1717
 
  /* When lock on LOCK_open is freed other threads can continue */
 
1717
  /* When lock on table::Cache::singleton().mutex() is freed other threads can continue */
1718
1718
  locking::broadcast_refresh();
1719
1719
}
1720
1720
 
1827
1827
    /* Close all instances of the table to allow repair to rename files */
1828
1828
    if (lock_type == TL_WRITE && table->table->getShare()->getVersion())
1829
1829
    {
1830
 
      LOCK_open.lock(); /* Lock type is TL_WRITE and we lock to repair the table */
1831
 
      const char *old_message=session->enter_cond(COND_refresh, LOCK_open,
 
1830
      table::Cache::singleton().mutex().lock(); /* Lock type is TL_WRITE and we lock to repair the table */
 
1831
      const char *old_message=session->enter_cond(COND_refresh, table::Cache::singleton().mutex(),
1832
1832
                                                  "Waiting to get writelock");
1833
1833
      session->abortLock(table->table);
1834
1834
      TableIdentifier identifier(table->table->getShare()->getSchemaName(), table->table->getShare()->getTableName());
1932
1932
        }
1933
1933
        else
1934
1934
        {
1935
 
          boost::unique_lock<boost::mutex> lock(LOCK_open);
 
1935
          boost::unique_lock<boost::mutex> lock(table::Cache::singleton().mutex());
1936
1936
          TableIdentifier identifier(table->table->getShare()->getSchemaName(), table->table->getShare()->getTableName());
1937
1937
          table::Cache::singleton().removeTable(session, identifier, RTFC_NO_FLAG);
1938
1938
        }
1964
1964
    Altough exclusive name-lock on target table protects us from concurrent
1965
1965
    DML and DDL operations on it we still want to wrap .FRM creation and call
1966
1966
    to plugin::StorageEngine::createTable() in critical section protected by
1967
 
    LOCK_open in order to provide minimal atomicity against operations which
 
1967
    table::Cache::singleton().mutex() in order to provide minimal atomicity against operations which
1968
1968
    disregard name-locks, like I_S implementation, for example. This is a
1969
1969
    temporary and should not be copied. Instead we should fix our code to
1970
1970
    always honor name-locks.
1971
1971
 
1972
 
    Also some engines (e.g. NDB cluster) require that LOCK_open should be held
 
1972
    Also some engines (e.g. NDB cluster) require that table::Cache::singleton().mutex() should be held
1973
1973
    during the call to plugin::StorageEngine::createTable().
1974
1974
    See bug #28614 for more info.
1975
1975
  */
2117
2117
    {
2118
2118
      if (name_lock)
2119
2119
      {
2120
 
        boost_unique_lock_t lock(LOCK_open); /* unlink open tables for create table like*/
 
2120
        boost_unique_lock_t lock(table::Cache::singleton().mutex()); /* unlink open tables for create table like*/
2121
2121
        session->unlink_open_table(name_lock);
2122
2122
      }
2123
2123
 
2136
2136
    {
2137
2137
      bool was_created;
2138
2138
      {
2139
 
        boost_unique_lock_t lock(LOCK_open); /* We lock for CREATE TABLE LIKE to copy table definition */
 
2139
        boost_unique_lock_t lock(table::Cache::singleton().mutex()); /* We lock for CREATE TABLE LIKE to copy table definition */
2140
2140
        was_created= create_table_wrapper(*session, create_table_proto, destination_identifier,
2141
2141
                                               src_identifier, is_engine_set);
2142
2142
      }
2155
2155
 
2156
2156
    if (name_lock)
2157
2157
    {
2158
 
      boost_unique_lock_t lock(LOCK_open); /* unlink open tables for create table like*/
 
2158
      boost_unique_lock_t lock(table::Cache::singleton().mutex()); /* unlink open tables for create table like*/
2159
2159
      session->unlink_open_table(name_lock);
2160
2160
    }
2161
2161
  }