~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/table/cache.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
#include <config.h>
 
22
#include <drizzled/table/cache.h>
22
23
 
23
24
#include <sys/types.h>
24
25
#include <sys/stat.h>
25
26
#include <fcntl.h>
26
27
 
27
 
 
28
28
#include <drizzled/identifier.h>
29
 
#include <drizzled/table.h>
 
29
#include <drizzled/open_tables_state.h>
 
30
#include <drizzled/pthread_globals.h>
30
31
#include <drizzled/session.h>
31
32
#include <drizzled/sql_base.h>
 
33
#include <drizzled/sys_var.h>
 
34
#include <drizzled/table.h>
32
35
#include <drizzled/table/concurrent.h>
33
 
 
34
 
#include <drizzled/table/cache.h>
35
36
#include <drizzled/table/unused.h>
36
37
 
37
 
#include <drizzled/pthread_globals.h>
38
 
 
39
 
namespace drizzled
40
 
{
41
 
 
42
 
class Session;
43
 
 
44
 
namespace table
45
 
{
46
 
 
47
 
CacheMap &getCache(void)
48
 
{
49
 
  return Cache::singleton().getCache();
 
38
namespace drizzled {
 
39
namespace table {
 
40
 
 
41
CacheMap Cache::cache;
 
42
boost::mutex Cache::_mutex;
 
43
 
 
44
CacheMap& getCache()
 
45
{
 
46
  return Cache::getCache();
50
47
}
51
48
 
52
49
/*
57
54
  entry         Table to remove
58
55
 
59
56
  NOTE
60
 
  We need to have a lock on table::Cache::singleton().mutex() when calling this
 
57
  We need to have a lock on table::Cache::mutex() when calling this
61
58
*/
62
59
 
63
60
static void free_cache_entry(table::Concurrent *table)
165
162
  close_thread_tables() is called.
166
163
 
167
164
  PREREQUISITES
168
 
  Lock on table::Cache::singleton().mutex()()
 
165
  Lock on table::Cache::mutex()()
169
166
 
170
167
  RETURN
171
168
  0  This thread now have exclusive access to this table and no other thread
173
170
  1  Table is in use by another thread
174
171
*/
175
172
 
176
 
bool Cache::removeTable(Session *session, identifier::Table &identifier, uint32_t flags)
 
173
bool Cache::removeTable(Session& session, const identifier::Table &identifier, uint32_t flags)
177
174
{
178
175
  const identifier::Table::Key &key(identifier.getKey());
179
176
  bool result= false;
197
194
      {
198
195
        table::getUnused().relink(table);
199
196
      }
200
 
      else if (in_use != session)
 
197
      else if (in_use != &session)
201
198
      {
202
199
        /*
203
200
          Mark that table is going to be deleted from cache. This will
204
201
          force threads that are in lockTables() (but not yet
205
202
          in thr_multi_lock()) to abort it's locks, close all tables and retry
206
203
        */
207
 
        in_use->some_tables_deleted= true;
208
204
        if (table->is_name_opened())
209
205
        {
210
206
          result= true;
212
208
        /*
213
209
          Now we must abort all tables locks used by this thread
214
210
          as the thread may be waiting to get a lock for another table.
215
 
          Note that we need to hold table::Cache::singleton().mutex() while going through the
 
211
          Note that we need to hold table::Cache::mutex() while going through the
216
212
          list. So that the other thread cannot change it. The other
217
 
          thread must also hold table::Cache::singleton().mutex() whenever changing the
 
213
          thread must also hold table::Cache::mutex() whenever changing the
218
214
          open_tables list. Aborting the MERGE lock after a child was
219
215
          closed and before the parent is closed would be fatal.
220
216
        */
221
 
        for (Table *session_table= in_use->open_tables;
 
217
        for (Table *session_table= in_use->open_tables.open_tables_;
222
218
             session_table ;
223
219
             session_table= session_table->getNext())
224
220
        {
225
221
          /* Do not handle locks of MERGE children. */
226
222
          if (session_table->db_stat)   // If table is open
227
 
            signalled|= session->abortLockForThread(session_table);
 
223
            signalled|= session.abortLockForThread(session_table);
228
224
        }
229
225
      }
230
226
      else
245
241
        reopen their tables
246
242
      */
247
243
      locking::broadcast_refresh();
248
 
      if (not (flags & RTFC_CHECK_KILLED_FLAG) || not session->getKilled())
 
244
      if (not (flags & RTFC_CHECK_KILLED_FLAG) || not session.getKilled())
249
245
      {
250
246
        dropping_tables++;
251
247
        if (likely(signalled))
252
248
        {
253
 
          boost_unique_lock_t scoped(table::Cache::singleton().mutex(), boost::adopt_lock_t());
 
249
          boost::mutex::scoped_lock scoped(table::Cache::mutex(), boost::adopt_lock_t());
254
250
          COND_refresh.wait(scoped);
255
251
          scoped.release();
256
252
        }
264
260
            ensure that the thread actually hears our signal
265
261
            before we go to sleep. Thus we wait for a short time
266
262
            and then we retry another loop in the
267
 
            table::Cache::singleton().removeTable routine.
 
263
            table::Cache::removeTable routine.
268
264
          */
269
265
          boost::xtime xt;
270
266
          xtime_get(&xt, boost::TIME_UTC);
271
267
          xt.sec += 10;
272
 
          boost_unique_lock_t scoped(table::Cache::singleton().mutex(), boost::adopt_lock_t());
 
268
          boost::mutex::scoped_lock scoped(table::Cache::mutex(), boost::adopt_lock_t());
273
269
          COND_refresh.timed_wait(scoped, xt);
274
270
          scoped.release();
275
271
        }
284
280
}
285
281
 
286
282
 
287
 
bool Cache::insert(table::Concurrent *arg)
 
283
void Cache::insert(table::Concurrent* arg)
288
284
{
289
285
  CacheMap::iterator returnable= cache.insert(std::make_pair(arg->getShare()->getCacheKey(), arg));
290
 
 
291
 
  return not (returnable == cache.end());
 
286
        assert(returnable != cache.end());
292
287
}
293
288
 
294
289
} /* namespace table */