~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table/cache.cc

  • Committer: Olaf van der Spek
  • Date: 2011-03-28 14:32:36 UTC
  • mto: (2257.1.1 build) (2276.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2258.
  • Revision ID: olafvdspek@gmail.com-20110328143236-4ge1d793iqaktfq0
Common fwd

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
 
21
#include <config.h>
22
22
 
23
23
#include <sys/types.h>
24
24
#include <sys/stat.h>
25
25
#include <fcntl.h>
26
26
 
27
 
 
28
 
#include "drizzled/identifier/table.h"
29
 
#include "drizzled/table.h"
30
 
#include "drizzled/session.h"
31
 
#include "drizzled/table/concurrent.h"
32
 
 
33
 
#include "drizzled/table/cache.h"
34
 
#include "drizzled/table/unused.h"
35
 
 
36
 
#include "drizzled/pthread_globals.h"
37
 
 
38
 
namespace drizzled
39
 
{
 
27
#include <drizzled/identifier.h>
 
28
#include <drizzled/table.h>
 
29
#include <drizzled/session.h>
 
30
#include <drizzled/sql_base.h>
 
31
#include <drizzled/table/concurrent.h>
 
32
#include <drizzled/table/cache.h>
 
33
#include <drizzled/table/unused.h>
 
34
#include <drizzled/pthread_globals.h>
 
35
#include <drizzled/sys_var.h>
 
36
 
 
37
namespace drizzled {
40
38
 
41
39
class Session;
42
40
 
43
 
namespace table
44
 
{
 
41
namespace table {
45
42
 
46
43
CacheMap &getCache(void)
47
44
{
67
64
    getUnused().unlink(table);
68
65
  }
69
66
 
70
 
  delete table;
 
67
  boost::checked_delete(table);
71
68
}
72
69
 
73
70
void remove_table(table::Concurrent *arg)
78
75
  for (CacheMap::const_iterator iter= ppp.first;
79
76
         iter != ppp.second; ++iter)
80
77
  {
81
 
    table::Concurrent *found_table= (*iter).second;
 
78
    table::Concurrent *found_table= iter->second;
82
79
 
83
80
    if (found_table == arg)
84
81
    {
99
96
{
100
97
  do
101
98
  {
102
 
    const TableIdentifier::Key &key(table->getShare()->getCacheKey());
 
99
    const identifier::Table::Key &key(table->getShare()->getCacheKey());
103
100
 
104
101
    table::CacheRange ppp= table::getCache().equal_range(key);
105
102
 
106
103
    for (table::CacheMap::const_iterator iter= ppp.first; iter != ppp.second; ++iter)
107
104
    {
108
 
      Table *search= (*iter).second;
 
105
      Table *search= iter->second;
109
106
      if (search->in_use == table->in_use)
110
107
        continue;                               // Name locked by this thread
111
108
      /*
136
133
and afterwards delete those marked unused.
137
134
*/
138
135
 
139
 
void Cache::removeSchema(const SchemaIdentifier &schema_identifier)
 
136
void Cache::removeSchema(const identifier::Schema &schema_identifier)
140
137
{
141
138
  boost::mutex::scoped_lock scopedLock(_mutex);
142
139
 
144
141
       iter != table::getCache().end();
145
142
       iter++)
146
143
  {
147
 
    table::Concurrent *table= (*iter).second;
 
144
    table::Concurrent *table= iter->second;
148
145
 
149
146
    if (not schema_identifier.getPath().compare(table->getShare()->getSchemaName()))
150
147
    {
172
169
  1  Table is in use by another thread
173
170
*/
174
171
 
175
 
bool Cache::removeTable(Session *session, TableIdentifier &identifier, uint32_t flags)
 
172
bool Cache::removeTable(Session *session, identifier::Table &identifier, uint32_t flags)
176
173
{
177
 
  const TableIdentifier::Key &key(identifier.getKey());
178
 
  bool result= false; 
 
174
  const identifier::Table::Key &key(identifier.getKey());
 
175
  bool result= false;
179
176
  bool signalled= false;
180
177
 
181
178
  for (;;)
188
185
    for (table::CacheMap::const_iterator iter= ppp.first;
189
186
         iter != ppp.second; ++iter)
190
187
    {
191
 
      table::Concurrent *table= (*iter).second;
 
188
      table::Concurrent *table= iter->second;
192
189
      Session *in_use;
193
190
 
194
191
      table->getMutableShare()->resetVersion();         /* Free when thread is ready */
235
232
    table::getUnused().cullByVersion();
236
233
 
237
234
    /* Remove table from table definition cache if it's not in use */
238
 
    TableShare::release(identifier);
 
235
    table::instance::release(identifier);
239
236
 
240
237
    if (result && (flags & RTFC_WAIT_OTHER_THREAD_FLAG))
241
238
    {
265
262
            and then we retry another loop in the
266
263
            table::Cache::singleton().removeTable routine.
267
264
          */
268
 
          boost::xtime xt; 
269
 
          xtime_get(&xt, boost::TIME_UTC); 
270
 
          xt.sec += 10; 
 
265
          boost::xtime xt;
 
266
          xtime_get(&xt, boost::TIME_UTC);
 
267
          xt.sec += 10;
271
268
          boost_unique_lock_t scoped(table::Cache::singleton().mutex(), boost::adopt_lock_t());
272
269
          COND_refresh.timed_wait(scoped, xt);
273
270
          scoped.release();
286
283
bool Cache::insert(table::Concurrent *arg)
287
284
{
288
285
  CacheMap::iterator returnable= cache.insert(std::make_pair(arg->getShare()->getCacheKey(), arg));
289
 
 
290
 
  return not (returnable == cache.end());
 
286
        assert(returnable != cache.end());
 
287
  return returnable != cache.end();
291
288
}
292
289
 
293
290
} /* namespace table */