~stewart/drizzle/use-catalog-for-path

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Monty Taylor
  • Date: 2011-04-06 21:23:45 UTC
  • mfrom: (2268.1.4 build)
  • Revision ID: mordred@inaugust.com-20110406212345-a7w7nkcuq60ybi4z
Merge Monty: Windows Fixes
Merge Olaf: open_table refactor

Show diffs side-by-side

added added

removed removed

Lines of Context:
301
301
      result= session->reopen_tables();
302
302
 
303
303
      /* Set version for table */
304
 
      for (Table *table= session->open_tables; table ; table= table->getNext())
 
304
      for (Table *table= session->open_tables.open_tables_; table ; table= table->getNext())
305
305
      {
306
306
        /*
307
307
          Preserve the version (0) of write locked tables so that a impending
335
335
 
336
336
  (void)scopedLock;
337
337
 
338
 
  table::Concurrent *table= static_cast<table::Concurrent *>(open_tables);
 
338
  table::Concurrent *table= static_cast<table::Concurrent *>(open_tables.open_tables_);
339
339
 
340
340
  safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle());
341
341
  assert(table->key_read == 0);
342
342
  assert(!table->cursor || table->cursor->inited == Cursor::NONE);
343
343
 
344
 
  open_tables= table->getNext();
 
344
  open_tables.open_tables_= table->getNext();
345
345
 
346
346
  if (table->needs_reopen_or_name_lock() ||
347
 
      version != refresh_version || !table->db_stat)
 
347
      open_tables.version != refresh_version || !table->db_stat)
348
348
  {
349
349
    table::remove_table(table);
350
350
    found_old_table= true;
384
384
 
385
385
  boost_unique_lock_t scoped_lock(table::Cache::singleton().mutex()); /* Close all open tables on Session */
386
386
 
387
 
  while (open_tables)
 
387
  while (open_tables.open_tables_)
388
388
  {
389
389
    found_old_table|= free_cached_table(scoped_lock);
390
390
  }
675
675
    Closing a MERGE child before the parent would be fatal if the
676
676
    other thread tries to abort the MERGE lock in between.
677
677
  */
678
 
  for (prev= &open_tables; *prev; )
 
678
  for (prev= &open_tables.open_tables_; *prev; )
679
679
  {
680
680
    Table *list= *prev;
681
681
 
722
722
{
723
723
  if (table->getShare()->getType())
724
724
  {
725
 
    close_temporary_table(table);
 
725
    open_tables.close_temporary_table(table);
726
726
  }
727
727
  else
728
728
  {
852
852
    return true;
853
853
  }
854
854
  (*table)->open_placeholder= true;
855
 
  (*table)->setNext(open_tables);
856
 
  open_tables= *table;
 
855
  (*table)->setNext(open_tables.open_tables_);
 
856
  open_tables.open_tables_= *table;
857
857
 
858
858
  return false;
859
859
}
922
922
    TODO -> move this block into a separate function.
923
923
  */
924
924
  bool reset= false;
925
 
  for (table= getTemporaryTables(); table ; table=table->getNext())
 
925
  for (table= open_tables.getTemporaryTables(); table ; table=table->getNext())
926
926
  {
927
927
    if (table->getShare()->getCacheKey() == key)
928
928
    {
960
960
 
961
961
      Note-> refresh_version is currently changed only during FLUSH TABLES.
962
962
    */
963
 
    if (!open_tables)
 
963
    if (!open_tables.open_tables_)
964
964
    {
965
 
      version= refresh_version;
 
965
      open_tables.version= refresh_version;
966
966
    }
967
 
    else if ((version != refresh_version) &&
 
967
    else if ((open_tables.version != refresh_version) &&
968
968
             ! (flags & DRIZZLE_LOCK_IGNORE_FLUSH))
969
969
    {
970
970
      /* Someone did a refresh while thread was opening tables */
1034
1034
          if (flags & DRIZZLE_LOCK_IGNORE_FLUSH)
1035
1035
          {
1036
1036
            /* Force close at once after usage */
1037
 
            version= table->getShare()->getVersion();
 
1037
            open_tables.version= table->getShare()->getVersion();
1038
1038
            continue;
1039
1039
          }
1040
1040
 
1124
1124
              by other trying to take name-lock.
1125
1125
            */
1126
1126
            table->open_placeholder= true;
1127
 
            table->setNext(open_tables);
1128
 
            open_tables= table;
 
1127
            table->setNext(open_tables.open_tables_);
 
1128
            open_tables.open_tables_= table;
1129
1129
 
1130
1130
            return table ;
1131
1131
          }
1149
1149
 
1150
1150
    if (refresh)
1151
1151
    {
1152
 
      table->setNext(open_tables); /* Link into simple list */
1153
 
      open_tables= table;
 
1152
      table->setNext(open_tables.open_tables_); /* Link into simple list */
 
1153
      open_tables.open_tables_= table;
1154
1154
    }
1155
1155
    table->reginfo.lock_type= TL_READ; /* Assume read */
1156
1156
 
1164
1164
  }
1165
1165
 
1166
1166
  /* These variables are also set in reopen_table() */
1167
 
  table->tablenr= current_tablenr++;
 
1167
  table->tablenr= open_tables.current_tablenr++;
1168
1168
  table->used_fields= 0;
1169
1169
  table->const_table= 0;
1170
1170
  table->null_row= false;
1208
1208
{
1209
1209
  safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle()); /* Adjust locks at the end of ALTER TABLEL */
1210
1210
 
1211
 
  if (lock)
 
1211
  if (open_tables.lock)
1212
1212
  {
1213
1213
    /*
1214
1214
      If we are not under LOCK TABLES we should have only one table
1215
1215
      open and locked so it makes sense to remove the lock at once.
1216
1216
    */
1217
 
    unlockTables(lock);
1218
 
    lock= 0;
 
1217
    unlockTables(open_tables.lock);
 
1218
    open_tables.lock= 0;
1219
1219
  }
1220
1220
 
1221
1221
  /*
1223
1223
    for target table name if we process ALTER Table ... RENAME.
1224
1224
    So loop below makes sense even if we are not under LOCK TABLES.
1225
1225
  */
1226
 
  for (Table *table= open_tables; table ; table=table->getNext())
 
1226
  for (Table *table= open_tables.open_tables_; table ; table=table->getNext())
1227
1227
  {
1228
1228
    if (table->getShare()->getCacheKey() == identifier.getKey())
1229
1229
    {
1264
1264
    DRIZZLE_LOCK_IGNORE_GLOBAL_READ_LOCK |
1265
1265
    DRIZZLE_LOCK_IGNORE_FLUSH;
1266
1266
 
1267
 
  if (open_tables == NULL)
 
1267
  if (open_tables.open_tables_ == NULL)
1268
1268
    return false;
1269
1269
 
1270
1270
  safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle());
1275
1275
    */
1276
1276
    uint32_t opens= 0;
1277
1277
 
1278
 
    for (table= open_tables; table ; table=table->getNext())
 
1278
    for (table= open_tables.open_tables_; table ; table=table->getNext())
1279
1279
    {
1280
1280
      opens++;
1281
1281
    }
1284
1284
 
1285
1285
  tables_ptr =tables;
1286
1286
 
1287
 
  prev= &open_tables;
1288
 
  for (table= open_tables; table ; table=next)
 
1287
  prev= &open_tables.open_tables_;
 
1288
  for (table= open_tables.open_tables_; table ; table=next)
1289
1289
  {
1290
1290
    next= table->getNext();
1291
1291
 
1347
1347
{
1348
1348
  bool found= send_refresh;
1349
1349
 
1350
 
  Table *table= open_tables;
 
1350
  Table *table= open_tables.open_tables_;
1351
1351
 
1352
1352
  for (; table ; table=table->getNext())
1353
1353
  {
1442
1442
Table *drop_locked_tables(Session *session, const drizzled::identifier::Table &identifier)
1443
1443
{
1444
1444
  Table *table,*next,**prev, *found= 0;
1445
 
  prev= &session->open_tables;
 
1445
  prev= &session->open_tables.open_tables_;
1446
1446
 
1447
1447
  /*
1448
1448
    Note that we need to hold table::Cache::singleton().mutex() while changing the
1451
1451
    Closing a MERGE child before the parent would be fatal if the
1452
1452
    other thread tries to abort the MERGE lock in between.
1453
1453
  */
1454
 
  for (table= session->open_tables; table ; table=next)
 
1454
  for (table= session->open_tables.open_tables_; table ; table=next)
1455
1455
  {
1456
1456
    next=table->getNext();
1457
1457
    if (table->getShare()->getCacheKey() == identifier.getKey())
1498
1498
void abort_locked_tables(Session *session, const drizzled::identifier::Table &identifier)
1499
1499
{
1500
1500
  Table *table;
1501
 
  for (table= session->open_tables; table ; table= table->getNext())
 
1501
  for (table= session->open_tables.open_tables_; table ; table= table->getNext())
1502
1502
  {
1503
1503
    if (table->getShare()->getCacheKey() == identifier.getKey())
1504
1504
    {
1547
1547
  /* Also used for indicating that prelocking is need */
1548
1548
  bool safe_to_ignore_table;
1549
1549
 
1550
 
  current_tablenr= 0;
 
1550
  open_tables.current_tablenr= 0;
1551
1551
restart:
1552
1552
  *counter= 0;
1553
1553
  set_proc_info("Opening tables");
1674
1674
  bool refresh;
1675
1675
 
1676
1676
  set_proc_info("Opening table");
1677
 
  current_tablenr= 0;
 
1677
  open_tables.current_tablenr= 0;
1678
1678
  while (!(table= openTable(table_list, &refresh)) && refresh) ;
1679
1679
 
1680
1680
  if (table)
1682
1682
    table_list->lock_type= lock_type;
1683
1683
    table_list->table=     table;
1684
1684
 
1685
 
    assert(lock == 0);  // You must lock everything at once
 
1685
    assert(open_tables.lock == 0);      // You must lock everything at once
1686
1686
    if ((table->reginfo.lock_type= lock_type) != TL_UNLOCK)
1687
1687
    {
1688
 
      if (not (lock= lockTables(&table_list->table, 1, 0)))
 
1688
      if (not (open_tables.lock= lockTables(&table_list->table, 1, 0)))
1689
1689
        table= NULL;
1690
1690
    }
1691
1691
  }
1737
1737
  if (tables == NULL)
1738
1738
    return 0;
1739
1739
 
1740
 
  assert(session->lock == 0);   // You must lock everything at once
 
1740
  assert(session->open_tables.lock == 0);       // You must lock everything at once
1741
1741
  Table **start,**ptr;
1742
1742
  uint32_t lock_flag= DRIZZLE_LOCK_NOTIFY_IF_NEED_REOPEN;
1743
1743
 
1750
1750
      *(ptr++)= table->table;
1751
1751
  }
1752
1752
 
1753
 
  if (not (session->lock= session->lockTables(start, (uint32_t) (ptr - start), lock_flag)))
 
1753
  if (not (session->open_tables.lock= session->lockTables(start, (uint32_t) (ptr - start), lock_flag)))
1754
1754
  {
1755
1755
    return -1;
1756
1756
  }
1779
1779
#  Table object
1780
1780
*/
1781
1781
 
1782
 
Table *Open_tables_state::open_temporary_table(const identifier::Table &identifier,
1783
 
                                               bool link_in_list)
 
1782
Table* Session::open_temporary_table(const identifier::Table &identifier, bool link_in_list)
1784
1783
{
1785
1784
  assert(identifier.isTmp());
1786
1785
 
1814
1813
  if (link_in_list)
1815
1814
  {
1816
1815
    /* growing temp list at the head */
1817
 
    new_tmp_table->setNext(this->temporary_tables);
 
1816
    new_tmp_table->setNext(open_tables.temporary_tables);
1818
1817
    if (new_tmp_table->getNext())
1819
1818
    {
1820
1819
      new_tmp_table->getNext()->setPrev(new_tmp_table);
1821
1820
    }
1822
 
    this->temporary_tables= new_tmp_table;
1823
 
    this->temporary_tables->setPrev(0);
 
1821
    open_tables.temporary_tables= new_tmp_table;
 
1822
    open_tables.temporary_tables->setPrev(0);
1824
1823
  }
1825
1824
  new_tmp_table->pos_in_table_list= 0;
1826
1825