~linuxjedi/drizzle/drizzle-bug-597905

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Brian Aker
  • Date: 2010-06-28 16:17:36 UTC
  • mfrom: (1637.4.1 drizzle)
  • Revision ID: brian@gaz-20100628161736-eormhb2mnd551i2h
MergeĀ unused

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
  @defgroup Data_Dictionary Data Dictionary
67
67
  @{
68
68
*/
69
 
Table *unused_tables;                           /* Used by mysql_test */
 
69
 
70
70
HASH open_cache;                                /* Used by mysql_test */
 
71
 
 
72
class UnusedTables {
 
73
  Table *tables;                                /* Used by mysql_test */
 
74
 
 
75
  Table *getTable() const
 
76
  {
 
77
    return tables;
 
78
  }
 
79
 
 
80
  Table *setTable(Table *arg)
 
81
  {
 
82
    return tables= arg;
 
83
  }
 
84
 
 
85
public:
 
86
 
 
87
  void cull()
 
88
  {
 
89
    /* Free cache if too big */
 
90
    while (open_cache.records > table_cache_size && getTable())
 
91
      hash_delete(&open_cache,(unsigned char*) getTable());
 
92
  }
 
93
 
 
94
  void cullByVersion()
 
95
  {
 
96
    while (getTable() && not getTable()->getShare()->getVersion())
 
97
      hash_delete(&open_cache,(unsigned char*) getTable());
 
98
  }
 
99
  
 
100
  void link(Table *table)
 
101
  {
 
102
    if (getTable())
 
103
    {
 
104
      table->setNext(getTable());               /* Link in last */
 
105
      table->setPrev(getTable()->getPrev());
 
106
      getTable()->setPrev(table);
 
107
      table->getPrev()->setNext(table);
 
108
    }
 
109
    else
 
110
    {
 
111
      table->setPrev(setTable(table));
 
112
      table->setNext(table->getPrev());
 
113
      assert(table->getNext() == table && table->getPrev() == table);
 
114
    }
 
115
  }
 
116
 
 
117
 
 
118
  void unlink(Table *table)
 
119
  {
 
120
    table->unlink();
 
121
 
 
122
    /* Unlink the table from "unused_tables" list. */
 
123
    if (table == getTable())
 
124
    {  // First unused
 
125
      setTable(getTable()->getNext()); // Remove from link
 
126
      if (table == getTable())
 
127
        setTable(NULL);
 
128
    }
 
129
  }
 
130
 
 
131
/* move table first in unused links */
 
132
 
 
133
  void relink(Table *table)
 
134
  {
 
135
    if (table != getTable())
 
136
    {
 
137
      table->unlink();
 
138
 
 
139
      table->setNext(getTable());                       /* Link in unused tables */
 
140
      table->setPrev(getTable()->getPrev());
 
141
      getTable()->getPrev()->setNext(table);
 
142
      getTable()->setPrev(table);
 
143
      setTable(table);
 
144
    }
 
145
  }
 
146
 
 
147
 
 
148
  void clear()
 
149
  {
 
150
    while (getTable())
 
151
      hash_delete(&open_cache, (unsigned char*) getTable());
 
152
  }
 
153
 
 
154
  UnusedTables():
 
155
    tables(NULL)
 
156
  { }
 
157
 
 
158
  ~UnusedTables()
 
159
  { 
 
160
  }
 
161
};
 
162
 
 
163
static UnusedTables unused_tables;
71
164
static int open_unireg_entry(Session *session,
72
165
                             Table *entry,
73
166
                             const char *alias,
108
201
{
109
202
  refresh_version++;                            // Force close of open tables
110
203
 
111
 
  while (unused_tables)
112
 
    hash_delete(&open_cache, (unsigned char*) unused_tables);
 
204
  unused_tables.clear();
113
205
 
114
206
  if (not open_cache.records)                   // Safety first
115
207
    hash_free(&open_cache);
196
288
  table->intern_close_table();
197
289
  if (not table->in_use)
198
290
  {
199
 
    table->getNext()->setPrev(table->getPrev());                /* remove from used chain */
200
 
    table->getPrev()->setNext(table->getNext());
201
 
    if (table == unused_tables)
202
 
    {
203
 
      unused_tables= unused_tables->getNext();
204
 
      if (table == unused_tables)
205
 
        unused_tables= NULL;
206
 
    }
 
291
    unused_tables.unlink(table);
207
292
  }
208
293
 
209
294
  if (table->isPlaceHolder())
254
339
  if (tables == NULL)
255
340
  {
256
341
    refresh_version++;                          // Force close of open tables
257
 
    while (unused_tables)
258
 
    {
259
 
      hash_delete(&open_cache,(unsigned char*) unused_tables);
260
 
    }
 
342
 
 
343
    unused_tables.clear();
261
344
 
262
345
    if (wait_for_refresh)
263
346
    {
435
518
    table->cursor->ha_reset();
436
519
    table->in_use= false;
437
520
 
438
 
    if (unused_tables)
439
 
    {
440
 
      table->setNext(unused_tables);            /* Link in last */
441
 
      table->setPrev(unused_tables->getPrev());
442
 
      unused_tables->setPrev(table);
443
 
      table->getPrev()->setNext(table);
444
 
    }
445
 
    else
446
 
    {
447
 
      table->setPrev(unused_tables= table);
448
 
      table->setNext(table->getPrev());
449
 
    }
 
521
    unused_tables.link(table);
450
522
  }
451
523
 
452
524
  return found_old_table;
761
833
}
762
834
 
763
835
 
764
 
/* move table first in unused links */
765
 
 
766
 
static void relink_unused(Table *table)
767
 
{
768
 
  if (table != unused_tables)
769
 
  {
770
 
    table->getPrev()->setNext(table->getNext());                /* Remove from unused list */
771
 
    table->getNext()->setPrev(table->getPrev());
772
 
    table->setNext(unused_tables);                      /* Link in unused tables */
773
 
    table->setPrev(unused_tables->getPrev());
774
 
    unused_tables->getPrev()->setNext(table);
775
 
    unused_tables->setPrev(table);
776
 
    unused_tables= table;
777
 
  }
778
 
}
779
 
 
780
 
 
781
836
/**
782
837
  Remove all instances of table from thread's open list and
783
838
  table cache.
1324
1379
  }
1325
1380
  if (table)
1326
1381
  {
1327
 
    /* Unlink the table from "unused_tables" list. */
1328
 
    if (table == unused_tables)
1329
 
    {  // First unused
1330
 
      unused_tables= unused_tables->getNext(); // Remove from link
1331
 
      if (table == unused_tables)
1332
 
        unused_tables= NULL;
1333
 
    }
1334
 
    table->getPrev()->setNext(table->getNext()); /* Remove from unused list */
1335
 
    table->getNext()->setPrev(table->getPrev());
 
1382
    unused_tables.unlink(table);
1336
1383
    table->in_use= this;
1337
1384
  }
1338
1385
  else
1340
1387
    /* Insert a new Table instance into the open cache */
1341
1388
    int error;
1342
1389
    /* Free cache if too big */
1343
 
    while (open_cache.records > table_cache_size && unused_tables)
1344
 
      hash_delete(&open_cache,(unsigned char*) unused_tables);
 
1390
    unused_tables.cull();
1345
1391
 
1346
1392
    if (table_list->create)
1347
1393
    {
4453
4499
    {
4454
4500
      table->getMutableShare()->resetVersion();                 /* Free when thread is ready */
4455
4501
      if (not table->in_use)
4456
 
        relink_unused(table);
 
4502
        unused_tables.relink(table);
4457
4503
    }
4458
4504
  }
4459
 
  while (unused_tables && !unused_tables->getShare()->getVersion())
4460
 
    hash_delete(&open_cache,(unsigned char*) unused_tables);
 
4505
 
 
4506
  unused_tables.cullByVersion();
4461
4507
}
4462
4508
 
4463
4509
 
4501
4547
      table->getMutableShare()->resetVersion();         /* Free when thread is ready */
4502
4548
      if (!(in_use=table->in_use))
4503
4549
      {
4504
 
        relink_unused(table);
 
4550
        unused_tables.relink(table);
4505
4551
      }
4506
4552
      else if (in_use != session)
4507
4553
      {
4536
4582
      else
4537
4583
        result= result || (flags & RTFC_OWNED_BY_Session_FLAG);
4538
4584
    }
4539
 
    while (unused_tables && !unused_tables->getShare()->getVersion())
4540
 
      hash_delete(&open_cache,(unsigned char*) unused_tables);
 
4585
 
 
4586
    unused_tables.cullByVersion();
4541
4587
 
4542
4588
    /* Remove table from table definition cache if it's not in use */
4543
4589
    TableShare::release(identifier);