~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Brian Aker
  • Date: 2010-10-25 18:51:55 UTC
  • mto: (1887.2.1 merge)
  • mto: This revision was merged to the branch mainline in revision 1888.
  • Revision ID: brian@tangent.org-20101025185155-619baeg8xv9xdrxr
Move unused out to its own class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
#include "drizzled/plugin/authorization.h"
56
56
#include "drizzled/table/temporary.h"
57
57
#include "drizzled/table/placeholder.h"
 
58
#include "drizzled/unused_tables.h"
58
59
 
59
60
using namespace std;
60
61
 
100
101
  return not (returnable == open_cache.end());
101
102
}
102
103
 
103
 
class UnusedTables {
104
 
  table::Concurrent *tables;                            /* Used by mysql_test */
105
 
 
106
 
  table::Concurrent *getTable() const
107
 
  {
108
 
    return tables;
109
 
  }
110
 
 
111
 
  table::Concurrent *setTable(Table *arg)
112
 
  {
113
 
    return tables= dynamic_cast<table::Concurrent *>(arg);
114
 
  }
115
 
 
116
 
public:
117
 
 
118
 
  void cull()
119
 
  {
120
 
    /* Free cache if too big */
121
 
    while (cached_open_tables() > table_cache_size && getTable())
122
 
      remove_table(getTable());
123
 
  }
124
 
 
125
 
  void cullByVersion()
126
 
  {
127
 
    while (getTable() && not getTable()->getShare()->getVersion())
128
 
      remove_table(getTable());
129
 
  }
130
 
  
131
 
  void link(table::Concurrent *table)
132
 
  {
133
 
    if (getTable())
134
 
    {
135
 
      table->setNext(getTable());               /* Link in last */
136
 
      table->setPrev(getTable()->getPrev());
137
 
      getTable()->setPrev(table);
138
 
      table->getPrev()->setNext(table);
139
 
    }
140
 
    else
141
 
    {
142
 
      table->setPrev(setTable(table));
143
 
      table->setNext(table->getPrev());
144
 
      assert(table->getNext() == table && table->getPrev() == table);
145
 
    }
146
 
  }
147
 
 
148
 
 
149
 
  void unlink(table::Concurrent *table)
150
 
  {
151
 
    table->unlink();
152
 
 
153
 
    /* Unlink the table from "unused_tables" list. */
154
 
    if (table == getTable())
155
 
    {  // First unused
156
 
      setTable(getTable()->getNext()); // Remove from link
157
 
      if (table == getTable())
158
 
        setTable(NULL);
159
 
    }
160
 
  }
161
 
 
162
 
/* move table first in unused links */
163
 
 
164
 
  void relink(table::Concurrent *table)
165
 
  {
166
 
    if (table != getTable())
167
 
    {
168
 
      table->unlink();
169
 
 
170
 
      table->setNext(getTable());                       /* Link in unused tables */
171
 
      table->setPrev(getTable()->getPrev());
172
 
      getTable()->getPrev()->setNext(table);
173
 
      getTable()->setPrev(table);
174
 
      setTable(table);
175
 
    }
176
 
  }
177
 
 
178
 
 
179
 
  void clear()
180
 
  {
181
 
    while (getTable())
182
 
      remove_table(getTable());
183
 
  }
184
 
 
185
 
  UnusedTables():
186
 
    tables(NULL)
187
 
  { }
188
 
 
189
 
  ~UnusedTables()
190
 
  { 
191
 
  }
192
 
};
193
 
 
194
 
static UnusedTables unused_tables;
195
 
 
196
104
unsigned char *table_cache_key(const unsigned char *record,
197
105
                               size_t *length,
198
106
                               bool );
220
128
{
221
129
  refresh_version++;                            // Force close of open tables
222
130
 
223
 
  unused_tables.clear();
 
131
  getUnused().clear();
224
132
  get_open_cache().clear();
225
133
}
226
134
 
295
203
  table->intern_close_table();
296
204
  if (not table->in_use)
297
205
  {
298
 
    unused_tables.unlink(table);
 
206
    getUnused().unlink(table);
299
207
  }
300
208
 
301
209
  delete table;
341
249
    {
342
250
      refresh_version++;                                // Force close of open tables
343
251
 
344
 
      unused_tables.clear();
 
252
      getUnused().clear();
345
253
 
346
254
      if (wait_for_refresh)
347
255
      {
525
433
    table->cursor->ha_reset();
526
434
    table->in_use= false;
527
435
 
528
 
    unused_tables.link(table);
 
436
    getUnused().link(table);
529
437
  }
530
438
 
531
439
  return found_old_table;
1267
1175
      }
1268
1176
      if (table)
1269
1177
      {
1270
 
        unused_tables.unlink(dynamic_cast<table::Concurrent *>(table));
 
1178
        getUnused().unlink(dynamic_cast<table::Concurrent *>(table));
1271
1179
        table->in_use= this;
1272
1180
      }
1273
1181
      else
1275
1183
        /* Insert a new Table instance into the open cache */
1276
1184
        int error;
1277
1185
        /* Free cache if too big */
1278
 
        unused_tables.cull();
 
1186
        getUnused().cull();
1279
1187
 
1280
1188
        if (table_list->isCreate())
1281
1189
        {
4186
4094
    {
4187
4095
      table->getMutableShare()->resetVersion();                 /* Free when thread is ready */
4188
4096
      if (not table->in_use)
4189
 
        unused_tables.relink(table);
 
4097
        getUnused().relink(table);
4190
4098
    }
4191
4099
  }
4192
4100
 
4193
 
  unused_tables.cullByVersion();
 
4101
  getUnused().cullByVersion();
4194
4102
}
4195
4103
 
4196
4104
 
4231
4139
      table->getMutableShare()->resetVersion();         /* Free when thread is ready */
4232
4140
      if (not (in_use= table->in_use))
4233
4141
      {
4234
 
        unused_tables.relink(table);
 
4142
        getUnused().relink(table);
4235
4143
      }
4236
4144
      else if (in_use != session)
4237
4145
      {
4269
4177
      }
4270
4178
    }
4271
4179
 
4272
 
    unused_tables.cullByVersion();
 
4180
    getUnused().cullByVersion();
4273
4181
 
4274
4182
    /* Remove table from table definition cache if it's not in use */
4275
4183
    TableShare::release(identifier);