~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Brian Aker
  • Date: 2010-10-19 08:17:10 UTC
  • mto: (1864.2.1 merge)
  • mto: This revision was merged to the branch mainline in revision 1864.
  • Revision ID: brian@tangent.org-20101019081710-hw13j03145h13pdg
Merge in a bit more strictness around table type.

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
  return open_cache;
71
71
}
72
72
 
73
 
static void free_cache_entry(Table *entry);
 
73
static void free_cache_entry(table::Concurrent *entry);
74
74
 
75
 
void remove_table(Table *arg)
 
75
void remove_table(table::Concurrent *arg)
76
76
{
77
77
  TableOpenCacheRange ppp;
78
78
  ppp= get_open_cache().equal_range(arg->getShare()->getCacheKey());
80
80
  for (TableOpenCache::const_iterator iter= ppp.first;
81
81
         iter != ppp.second; ++iter)
82
82
  {
83
 
    Table *found_table= (*iter).second;
 
83
    table::Concurrent *found_table= (*iter).second;
84
84
 
85
85
    if (found_table == arg)
86
86
    {
91
91
  }
92
92
}
93
93
 
94
 
static bool add_table(Table *arg)
 
94
static bool add_table(table::Concurrent *arg)
95
95
{
96
96
  TableOpenCache &open_cache(get_open_cache());
97
97
 
101
101
}
102
102
 
103
103
class UnusedTables {
104
 
  Table *tables;                                /* Used by mysql_test */
 
104
  table::Concurrent *tables;                            /* Used by mysql_test */
105
105
 
106
 
  Table *getTable() const
 
106
  table::Concurrent *getTable() const
107
107
  {
108
108
    return tables;
109
109
  }
110
110
 
111
 
  Table *setTable(Table *arg)
 
111
  table::Concurrent *setTable(Table *arg)
112
112
  {
113
 
    return tables= arg;
 
113
    return tables= dynamic_cast<table::Concurrent *>(arg);
114
114
  }
115
115
 
116
116
public:
128
128
      remove_table(getTable());
129
129
  }
130
130
  
131
 
  void link(Table *table)
 
131
  void link(table::Concurrent *table)
132
132
  {
133
133
    if (getTable())
134
134
    {
146
146
  }
147
147
 
148
148
 
149
 
  void unlink(Table *table)
 
149
  void unlink(table::Concurrent *table)
150
150
  {
151
151
    table->unlink();
152
152
 
161
161
 
162
162
/* move table first in unused links */
163
163
 
164
 
  void relink(Table *table)
 
164
  void relink(table::Concurrent *table)
165
165
  {
166
166
    if (table != getTable())
167
167
    {
295
295
  We need to have a lock on LOCK_open when calling this
296
296
*/
297
297
 
298
 
void free_cache_entry(Table *table)
 
298
void free_cache_entry(table::Concurrent *table)
299
299
{
300
300
  table->intern_close_table();
301
301
  if (not table->in_use)
504
504
bool Session::free_cached_table()
505
505
{
506
506
  bool found_old_table= false;
507
 
  Table *table= open_tables;
 
507
  table::Concurrent *table= dynamic_cast<table::Concurrent *>(open_tables);
508
508
 
509
509
  safe_mutex_assert_owner(LOCK_open.native_handle());
510
510
  assert(table->key_read == 0);
877
877
      *prev= list->getNext();
878
878
 
879
879
      /* Close table. */
880
 
      remove_table(list);
 
880
      remove_table(dynamic_cast<table::Concurrent *>(list));
881
881
    }
882
882
    else
883
883
    {
1384
1384
      }
1385
1385
      if (table)
1386
1386
      {
1387
 
        unused_tables.unlink(table);
 
1387
        unused_tables.unlink(dynamic_cast<table::Concurrent *>(table));
1388
1388
        table->in_use= this;
1389
1389
      }
1390
1390
      else
1424
1424
        }
1425
1425
 
1426
1426
        /* make a new table */
1427
 
        table= new Table;
1428
 
        if (table == NULL)
1429
1427
        {
1430
 
          LOCK_open.unlock();
1431
 
          return NULL;
1432
 
        }
 
1428
          table::Concurrent *new_table= new table::Concurrent;
 
1429
          table= new_table;
 
1430
          if (new_table == NULL)
 
1431
          {
 
1432
            LOCK_open.unlock();
 
1433
            return NULL;
 
1434
          }
1433
1435
 
1434
 
        error= open_unireg_entry(this, table, alias, identifier);
1435
 
        if (error != 0)
1436
 
        {
1437
 
          delete table;
1438
 
          LOCK_open.unlock();
1439
 
          return NULL;
 
1436
          error= open_unireg_entry(this, new_table, alias, identifier);
 
1437
          if (error != 0)
 
1438
          {
 
1439
            delete new_table;
 
1440
            LOCK_open.unlock();
 
1441
            return NULL;
 
1442
          }
 
1443
          (void)add_table(new_table);
1440
1444
        }
1441
 
        (void)add_table(table);
1442
1445
      }
1443
1446
 
1444
1447
      LOCK_open.unlock();
1591
1594
    next= table->getNext();
1592
1595
 
1593
1596
    my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->getAlias());
1594
 
    remove_table(table);
 
1597
    remove_table(dynamic_cast<table::Concurrent *>(table));
1595
1598
    error= 1;
1596
1599
  }
1597
1600
  *prev=0;
1843
1846
      else
1844
1847
      {
1845
1848
        /* We already have a name lock, remove copy */
1846
 
        remove_table(table);
 
1849
        remove_table(dynamic_cast<table::Concurrent *>(table));
1847
1850
      }
1848
1851
    }
1849
1852
    else
4399
4402
       iter != get_open_cache().end();
4400
4403
       iter++)
4401
4404
  {
4402
 
    Table *table= (*iter).second;
 
4405
    table::Concurrent *table= (*iter).second;
4403
4406
 
4404
4407
    if (not schema_identifier.getPath().compare(table->getShare()->getSchemaName()))
4405
4408
    {
4444
4447
    for (TableOpenCache::const_iterator iter= ppp.first;
4445
4448
         iter != ppp.second; ++iter)
4446
4449
    {
4447
 
      Table *table= (*iter).second;
 
4450
      table::Concurrent *table= (*iter).second;
4448
4451
      Session *in_use;
4449
4452
 
4450
4453
      table->getMutableShare()->resetVersion();         /* Free when thread is ready */
4451
 
      if (!(in_use=table->in_use))
 
4454
      if (not (in_use= table->in_use))
4452
4455
      {
4453
4456
        unused_tables.relink(table);
4454
4457
      }
4483
4486
        }
4484
4487
      }
4485
4488
      else
 
4489
      {
4486
4490
        result= result || (flags & RTFC_OWNED_BY_Session_FLAG);
 
4491
      }
4487
4492
    }
4488
4493
 
4489
4494
    unused_tables.cullByVersion();