~drizzle-developers/ubuntu/karmic/drizzle/ppa

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Monty Taylor
  • Date: 2010-11-24 18:44:57 UTC
  • mfrom: (1308.1.31 trunk)
  • Revision ID: mordred@inaugust.com-20101124184457-qd6jvoe2wgnvl3yq
Tags: 2010.11.04-0ubuntu1~karmic1
* New upstream release.
* Turn off -Werror for packaging builds. (Closes: #602662)

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#include "drizzled/global_charset_info.h"
42
42
#include "drizzled/charset.h"
43
43
 
 
44
#include "drizzled/definition/cache.h"
 
45
 
44
46
 
45
47
#include "drizzled/statement/alter_table.h"
46
48
#include "drizzled/sql_table.h"
105
107
    cursor
106
108
*/
107
109
 
108
 
void write_bin_log(Session *session,
109
 
                   char const *query)
 
110
void write_bin_log(Session *session, const std::string &query)
110
111
{
111
112
  TransactionServices &transaction_services= TransactionServices::singleton();
112
113
  transaction_services.rawStatement(session, query);
147
148
  int error= 0;
148
149
  bool foreign_key_error= false;
149
150
 
150
 
  LOCK_open.lock(); /* Part 2 of rm a table */
 
151
  table::Cache::singleton().mutex().lock(); /* Part 2 of rm a table */
151
152
 
152
153
  if (not drop_temporary && session->lock_table_names_exclusively(tables))
153
154
  {
154
 
    LOCK_open.unlock();
 
155
    table::Cache::singleton().mutex().unlock();
155
156
    return 1;
156
157
  }
157
158
 
239
240
    }
240
241
  }
241
242
  /*
242
 
    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
243
244
    on the table name.
244
245
  */
245
 
  LOCK_open.unlock();
 
246
  table::Cache::singleton().mutex().unlock();
246
247
  error= 0;
247
248
 
248
249
  if (wrong_tables.length())
259
260
    error= 1;
260
261
  }
261
262
 
262
 
  LOCK_open.lock(); /* final bit in rm table lock */
 
263
  table::Cache::singleton().mutex().lock(); /* final bit in rm table lock */
263
264
 
264
265
err_with_placeholders:
265
266
  tables->unlock_table_names();
266
 
  LOCK_open.unlock();
 
267
  table::Cache::singleton().mutex().unlock();
267
268
  session->no_warnings_for_error= 0;
268
269
 
269
270
  return error;
1335
1336
      /*
1336
1337
        @todo improve this error condition.
1337
1338
      */
1338
 
      if (TableShare::getShare(identifier))
 
1339
      if (definition::Cache::singleton().find(identifier.getKey()))
1339
1340
      {
1340
1341
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), identifier.getSQLPath().c_str());
1341
1342
        return error;
1444
1445
                                     &key_info_buffer, &key_count,
1445
1446
                                     select_field_count))
1446
1447
  {
1447
 
    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) */
1448
1449
    error= locked_create_event(session,
1449
1450
                               identifier,
1450
1451
                               create_info,
1510
1511
 
1511
1512
  if (name_lock)
1512
1513
  {
1513
 
    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 */
1514
1515
    session->unlink_open_table(name_lock);
1515
1516
  }
1516
1517
 
1664
1665
   the table is closed.
1665
1666
 
1666
1667
  PREREQUISITES
1667
 
    Lock on LOCK_open
 
1668
    Lock on table::Cache::singleton().mutex()
1668
1669
    Win32 clients must also have a WRITE LOCK on the table !
1669
1670
*/
1670
1671
 
1672
1673
                              enum ha_extra_function function)
1673
1674
{
1674
1675
 
1675
 
  safe_mutex_assert_owner(LOCK_open.native_handle());
 
1676
  safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle());
1676
1677
 
1677
1678
  table->cursor->extra(function);
1678
1679
  /* Mark all tables that are in use as 'old' */
1696
1697
    reopen the table.
1697
1698
 
1698
1699
  PREREQUISITES
1699
 
    Lock on LOCK_open
 
1700
    Lock on table::Cache::singleton().mutex()
1700
1701
    Win32 clients must also have a WRITE LOCK on the table !
1701
1702
*/
1702
1703
 
1713
1714
  /* Close all copies of 'table'.  This also frees all LOCK TABLES lock */
1714
1715
  unlink_open_table(table);
1715
1716
 
1716
 
  /* 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 */
1717
1718
  locking::broadcast_refresh();
1718
1719
}
1719
1720
 
1826
1827
    /* Close all instances of the table to allow repair to rename files */
1827
1828
    if (lock_type == TL_WRITE && table->table->getShare()->getVersion())
1828
1829
    {
1829
 
      LOCK_open.lock(); /* Lock type is TL_WRITE and we lock to repair the table */
1830
 
      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(),
1831
1832
                                                  "Waiting to get writelock");
1832
1833
      session->abortLock(table->table);
1833
1834
      TableIdentifier identifier(table->table->getShare()->getSchemaName(), table->table->getShare()->getTableName());
1931
1932
        }
1932
1933
        else
1933
1934
        {
1934
 
          boost::unique_lock<boost::mutex> lock(LOCK_open);
 
1935
          boost::unique_lock<boost::mutex> lock(table::Cache::singleton().mutex());
1935
1936
          TableIdentifier identifier(table->table->getShare()->getSchemaName(), table->table->getShare()->getTableName());
1936
1937
          table::Cache::singleton().removeTable(session, identifier, RTFC_NO_FLAG);
1937
1938
        }
1963
1964
    Altough exclusive name-lock on target table protects us from concurrent
1964
1965
    DML and DDL operations on it we still want to wrap .FRM creation and call
1965
1966
    to plugin::StorageEngine::createTable() in critical section protected by
1966
 
    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
1967
1968
    disregard name-locks, like I_S implementation, for example. This is a
1968
1969
    temporary and should not be copied. Instead we should fix our code to
1969
1970
    always honor name-locks.
1970
1971
 
1971
 
    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
1972
1973
    during the call to plugin::StorageEngine::createTable().
1973
1974
    See bug #28614 for more info.
1974
1975
  */
1979
1980
{
1980
1981
  int protoerr= EEXIST;
1981
1982
  message::Table new_proto;
1982
 
  message::Table src_proto;
 
1983
  message::table::shared_ptr src_proto;
1983
1984
 
1984
1985
  protoerr= plugin::StorageEngine::getTableDefinition(session,
1985
1986
                                                      src_table,
1986
1987
                                                      src_proto);
1987
 
  new_proto.CopyFrom(src_proto);
 
1988
  new_proto.CopyFrom(*src_proto);
1988
1989
 
1989
1990
  if (destination_identifier.isTmp())
1990
1991
  {
2116
2117
    {
2117
2118
      if (name_lock)
2118
2119
      {
2119
 
        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*/
2120
2121
        session->unlink_open_table(name_lock);
2121
2122
      }
2122
2123
 
2135
2136
    {
2136
2137
      bool was_created;
2137
2138
      {
2138
 
        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 */
2139
2140
        was_created= create_table_wrapper(*session, create_table_proto, destination_identifier,
2140
2141
                                               src_identifier, is_engine_set);
2141
2142
      }
2154
2155
 
2155
2156
    if (name_lock)
2156
2157
    {
2157
 
      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*/
2158
2159
      session->unlink_open_table(name_lock);
2159
2160
    }
2160
2161
  }