~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table/cache.cc

  • Committer: Brian Aker
  • Date: 2010-10-28 17:12:01 UTC
  • mfrom: (1887.1.3 merge)
  • Revision ID: brian@tangent.org-20101028171201-baj6l1bnntn1s4ad
Merge in POTFILES changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <fcntl.h>
26
26
 
27
27
 
28
 
#include "drizzled/identifier.h"
 
28
#include "drizzled/identifier/table.h"
29
29
#include "drizzled/table.h"
30
30
#include "drizzled/session.h"
31
31
#include "drizzled/table/concurrent.h"
56
56
  entry         Table to remove
57
57
 
58
58
  NOTE
59
 
  We need to have a lock on table::Cache::singleton().mutex() when calling this
 
59
  We need to have a lock on LOCK_open when calling this
60
60
*/
61
61
 
62
62
static void free_cache_entry(table::Concurrent *table)
67
67
    getUnused().unlink(table);
68
68
  }
69
69
 
70
 
  boost::checked_delete(table);
 
70
  delete table;
71
71
}
72
72
 
73
73
void remove_table(table::Concurrent *arg)
99
99
{
100
100
  do
101
101
  {
102
 
    const identifier::Table::Key &key(table->getShare()->getCacheKey());
 
102
    const TableIdentifier::Key &key(table->getShare()->getCacheKey());
103
103
 
104
104
    table::CacheRange ppp= table::getCache().equal_range(key);
105
105
 
136
136
and afterwards delete those marked unused.
137
137
*/
138
138
 
139
 
void Cache::removeSchema(const identifier::Schema &schema_identifier)
 
139
void Cache::removeSchema(const SchemaIdentifier &schema_identifier)
140
140
{
141
 
  boost::mutex::scoped_lock scopedLock(_mutex);
 
141
  //safe_mutex_assert_owner(LOCK_open.native_handle());
142
142
 
143
143
  for (table::CacheMap::const_iterator iter= table::getCache().begin();
144
144
       iter != table::getCache().end();
164
164
  close_thread_tables() is called.
165
165
 
166
166
  PREREQUISITES
167
 
  Lock on table::Cache::singleton().mutex()()
 
167
  Lock on LOCK_open()
168
168
 
169
169
  RETURN
170
170
  0  This thread now have exclusive access to this table and no other thread
172
172
  1  Table is in use by another thread
173
173
*/
174
174
 
175
 
bool Cache::removeTable(Session *session, identifier::Table &identifier, uint32_t flags)
 
175
bool Cache::removeTable(Session *session, TableIdentifier &identifier, uint32_t flags)
176
176
{
177
 
  const identifier::Table::Key &key(identifier.getKey());
 
177
  const TableIdentifier::Key &key(identifier.getKey());
178
178
  bool result= false; 
179
179
  bool signalled= false;
180
180
 
200
200
      {
201
201
        /*
202
202
          Mark that table is going to be deleted from cache. This will
203
 
          force threads that are in lockTables() (but not yet
 
203
          force threads that are in mysql_lock_tables() (but not yet
204
204
          in thr_multi_lock()) to abort it's locks, close all tables and retry
205
205
        */
206
206
        in_use->some_tables_deleted= true;
211
211
        /*
212
212
          Now we must abort all tables locks used by this thread
213
213
          as the thread may be waiting to get a lock for another table.
214
 
          Note that we need to hold table::Cache::singleton().mutex() while going through the
 
214
          Note that we need to hold LOCK_open while going through the
215
215
          list. So that the other thread cannot change it. The other
216
 
          thread must also hold table::Cache::singleton().mutex() whenever changing the
 
216
          thread must also hold LOCK_open whenever changing the
217
217
          open_tables list. Aborting the MERGE lock after a child was
218
218
          closed and before the parent is closed would be fatal.
219
219
        */
223
223
        {
224
224
          /* Do not handle locks of MERGE children. */
225
225
          if (session_table->db_stat)   // If table is open
226
 
            signalled|= session->abortLockForThread(session_table);
 
226
            signalled|= mysql_lock_abort_for_thread(session, session_table);
227
227
        }
228
228
      }
229
229
      else
235
235
    table::getUnused().cullByVersion();
236
236
 
237
237
    /* Remove table from table definition cache if it's not in use */
238
 
    table::instance::release(identifier);
 
238
    TableShare::release(identifier);
239
239
 
240
240
    if (result && (flags & RTFC_WAIT_OTHER_THREAD_FLAG))
241
241
    {
243
243
        Signal any thread waiting for tables to be freed to
244
244
        reopen their tables
245
245
      */
246
 
      locking::broadcast_refresh();
247
 
      if (not (flags & RTFC_CHECK_KILLED_FLAG) || not session->getKilled())
 
246
      broadcast_refresh();
 
247
      if (!(flags & RTFC_CHECK_KILLED_FLAG) || !session->killed)
248
248
      {
249
249
        dropping_tables++;
250
250
        if (likely(signalled))
251
251
        {
252
 
          boost_unique_lock_t scoped(table::Cache::singleton().mutex(), boost::adopt_lock_t());
 
252
          boost_unique_lock_t scoped(LOCK_open, boost::adopt_lock_t());
253
253
          COND_refresh.wait(scoped);
254
254
          scoped.release();
255
255
        }
268
268
          boost::xtime xt; 
269
269
          xtime_get(&xt, boost::TIME_UTC); 
270
270
          xt.sec += 10; 
271
 
          boost_unique_lock_t scoped(table::Cache::singleton().mutex(), boost::adopt_lock_t());
 
271
          boost_unique_lock_t scoped(LOCK_open, boost::adopt_lock_t());
272
272
          COND_refresh.timed_wait(scoped, xt);
273
273
          scoped.release();
274
274
        }
282
282
  return result;
283
283
}
284
284
 
285
 
 
286
 
bool Cache::insert(table::Concurrent *arg)
287
 
{
288
 
  CacheMap::iterator returnable= cache.insert(std::make_pair(arg->getShare()->getCacheKey(), arg));
289
 
 
290
 
  return not (returnable == cache.end());
291
 
}
292
 
 
293
285
} /* namespace table */
294
286
} /* namespace drizzled */