~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Brian Aker
  • Date: 2010-06-29 22:50:01 UTC
  • Revision ID: brian@gaz-20100629225001-ydkct4qt2zz85gxu
Encapsulate HASH for open_cache

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
  @{
68
68
*/
69
69
 
70
 
HASH open_cache;                                /* Used by mysql_test */
 
70
 
 
71
HASH &get_open_cache()
 
72
{
 
73
  static HASH open_cache;                               /* Used by mysql_test */
 
74
 
 
75
  return open_cache;
 
76
}
71
77
 
72
78
class UnusedTables {
73
79
  Table *tables;                                /* Used by mysql_test */
87
93
  void cull()
88
94
  {
89
95
    /* Free cache if too big */
90
 
    while (open_cache.records > table_cache_size && getTable())
91
 
      hash_delete(&open_cache,(unsigned char*) getTable());
 
96
    while (get_open_cache().records > table_cache_size && getTable())
 
97
      hash_delete(&get_open_cache(), (unsigned char*) getTable());
92
98
  }
93
99
 
94
100
  void cullByVersion()
95
101
  {
96
102
    while (getTable() && not getTable()->getShare()->getVersion())
97
 
      hash_delete(&open_cache,(unsigned char*) getTable());
 
103
      hash_delete(&get_open_cache(), (unsigned char*) getTable());
98
104
  }
99
105
  
100
106
  void link(Table *table)
148
154
  void clear()
149
155
  {
150
156
    while (getTable())
151
 
      hash_delete(&open_cache, (unsigned char*) getTable());
 
157
      hash_delete(&get_open_cache(), (unsigned char*) getTable());
152
158
  }
153
159
 
154
160
  UnusedTables():
183
189
  return (unsigned char*) &entry->getShare()->getCacheKey()[0];
184
190
}
185
191
 
186
 
HASH *get_open_cache()
187
 
{
188
 
  return &open_cache;
189
 
}
190
 
 
191
 
 
192
192
bool table_cache_init(void)
193
193
{
194
 
  return hash_init(&open_cache, &my_charset_bin,
 
194
  return hash_init(&get_open_cache(), &my_charset_bin,
195
195
                   (size_t) table_cache_size+16,
196
196
                   0, 0, table_cache_key,
197
197
                   free_cache_entry, 0);
203
203
 
204
204
  unused_tables.clear();
205
205
 
206
 
  if (not open_cache.records)                   // Safety first
207
 
    hash_free(&open_cache);
 
206
  if (not get_open_cache().records)                     // Safety first
 
207
    hash_free(&get_open_cache());
208
208
}
209
209
 
210
210
uint32_t cached_open_tables(void)
211
211
{
212
 
  return open_cache.records;
 
212
  return get_open_cache().records;
213
213
}
214
214
 
215
215
 
381
381
        after the call to Session::close_old_data_files() i.e. after removal of
382
382
        current thread locks.
383
383
      */
384
 
      for (uint32_t idx=0 ; idx < open_cache.records ; idx++)
 
384
      for (uint32_t idx=0 ; idx < get_open_cache().records ; idx++)
385
385
      {
386
 
        Table *table=(Table*) hash_element(&open_cache,idx);
 
386
        Table *table=(Table*) hash_element(&get_open_cache(),idx);
387
387
        if (table->in_use)
388
388
          table->in_use->some_tables_deleted= false;
389
389
      }
422
422
    while (found && ! session->killed)
423
423
    {
424
424
      found= false;
425
 
      for (uint32_t idx=0 ; idx < open_cache.records ; idx++)
 
425
      for (uint32_t idx=0 ; idx < get_open_cache().records ; idx++)
426
426
      {
427
 
        Table *table=(Table*) hash_element(&open_cache,idx);
 
427
        Table *table=(Table*) hash_element(&get_open_cache(), idx);
428
428
        /* Avoid a self-deadlock. */
429
429
        if (table->in_use == session)
430
430
          continue;
503
503
  if (table->needs_reopen_or_name_lock() ||
504
504
      version != refresh_version || !table->db_stat)
505
505
  {
506
 
    hash_delete(&open_cache,(unsigned char*) table);
 
506
    hash_delete(&get_open_cache(), (unsigned char*) table);
507
507
    found_old_table= true;
508
508
  }
509
509
  else
867
867
      *prev= list->getNext();
868
868
 
869
869
      /* Close table. */
870
 
      hash_delete(&open_cache,(unsigned char*) list); // Close table
 
870
      hash_delete(&get_open_cache(),(unsigned char*) list); // Close table
871
871
    }
872
872
    else
873
873
    {
1076
1076
  TableIdentifier identifier(db_name, table_name, message::Table::INTERNAL);
1077
1077
  TablePlaceholder *table= new TablePlaceholder(this, identifier);
1078
1078
 
1079
 
  if (my_hash_insert(&open_cache, (unsigned char*)table))
 
1079
  if (my_hash_insert(&get_open_cache(), (unsigned char*)table))
1080
1080
  {
1081
1081
    delete table;
1082
1082
 
1123
1123
 
1124
1124
  pthread_mutex_lock(&LOCK_open); /* Obtain a name lock even though table is not in cache (like for create table)  */
1125
1125
 
1126
 
  if (hash_search(&open_cache, (unsigned char *)key, key_length))
 
1126
  if (hash_search(&get_open_cache(), (unsigned char *)key, key_length))
1127
1127
  {
1128
1128
    pthread_mutex_unlock(&LOCK_open);
1129
1129
    *table= 0;
1292
1292
    an implicit "pending locks queue" - see
1293
1293
    wait_for_locked_table_names for details.
1294
1294
  */
1295
 
  for (table= (Table*) hash_first(&open_cache, (unsigned char*) &key[0], key_length,
 
1295
  for (table= (Table*) hash_first(&get_open_cache(), (unsigned char*) &key[0], key_length,
1296
1296
                                  &state);
1297
1297
       table && table->in_use ;
1298
 
       table= (Table*) hash_next(&open_cache, (unsigned char*) &key[0], key_length,
 
1298
       table= (Table*) hash_next(&get_open_cache(), (unsigned char*) &key[0], key_length,
1299
1299
                                 &state))
1300
1300
  {
1301
1301
    /*
1434
1434
      pthread_mutex_unlock(&LOCK_open);
1435
1435
      return NULL;
1436
1436
    }
1437
 
    my_hash_insert(&open_cache, (unsigned char*) table);
 
1437
    my_hash_insert(&get_open_cache(), (unsigned char*) table);
1438
1438
  }
1439
1439
 
1440
1440
  pthread_mutex_unlock(&LOCK_open);
1683
1683
    next= table->getNext();
1684
1684
 
1685
1685
    my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->alias);
1686
 
    hash_delete(&open_cache,(unsigned char*) table);
 
1686
    hash_delete(&get_open_cache(),(unsigned char*) table);
1687
1687
    error= 1;
1688
1688
  }
1689
1689
  *prev=0;
1822
1822
    const TableIdentifier::Key &key(table->getShare()->getCacheKey());
1823
1823
 
1824
1824
    HASH_SEARCH_STATE state;
1825
 
    for (Table *search= (Table*) hash_first(&open_cache, (unsigned char*) &key[0],
 
1825
    for (Table *search= (Table*) hash_first(&get_open_cache(), (unsigned char*) &key[0],
1826
1826
                                            key.size(), &state);
1827
1827
         search ;
1828
 
         search= (Table*) hash_next(&open_cache, (unsigned char*) &key[0],
 
1828
         search= (Table*) hash_next(&get_open_cache(), (unsigned char*) &key[0],
1829
1829
                                    key.size(), &state))
1830
1830
    {
1831
1831
      if (search->in_use == table->in_use)
1935
1935
      else
1936
1936
      {
1937
1937
        /* We already have a name lock, remove copy */
1938
 
        hash_delete(&open_cache,(unsigned char*) table);
 
1938
        hash_delete(&get_open_cache(),(unsigned char*) table);
1939
1939
      }
1940
1940
    }
1941
1941
    else
4492
4492
{
4493
4493
  safe_mutex_assert_owner(&LOCK_open);
4494
4494
 
4495
 
  for (uint32_t idx=0 ; idx < open_cache.records ; idx++)
 
4495
  for (uint32_t idx=0 ; idx < get_open_cache().records ; idx++)
4496
4496
  {
4497
 
    Table *table=(Table*) hash_element(&open_cache,idx);
 
4497
    Table *table=(Table*) hash_element(&get_open_cache(),idx);
4498
4498
    if (not schema_identifier.getPath().compare(table->getMutableShare()->getSchemaName()))
4499
4499
    {
4500
4500
      table->getMutableShare()->resetVersion();                 /* Free when thread is ready */
4536
4536
    Table *table;
4537
4537
    result= signalled= false;
4538
4538
 
4539
 
    for (table= (Table*) hash_first(&open_cache, (unsigned char*) &key[0], key_length,
 
4539
    for (table= (Table*) hash_first(&get_open_cache(), (unsigned char*) &key[0], key_length,
4540
4540
                                    &state);
4541
4541
         table;
4542
 
         table= (Table*) hash_next(&open_cache, (unsigned char*) &key[0], key_length,
 
4542
         table= (Table*) hash_next(&get_open_cache(), (unsigned char*) &key[0], key_length,
4543
4543
                                   &state))
4544
4544
    {
4545
4545
      Session *in_use;