~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to drizzled/lock.cc

  • Committer: Padraig O'Sullivan
  • Date: 2010-03-15 14:05:26 UTC
  • mfrom: (1237.9.99 staging)
  • Revision ID: osullivan.padraig@gmail.com-20100315140526-opbgwdwn6tfecdkq
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
#include "drizzled/pthread_globals.h"
84
84
#include "drizzled/internal/my_sys.h"
85
85
 
 
86
#include <set>
 
87
#include <vector>
 
88
#include <algorithm>
 
89
#include <functional>
 
90
 
 
91
using namespace std;
 
92
 
86
93
namespace drizzled
87
94
{
88
95
 
172
179
{
173
180
  DRIZZLE_LOCK *sql_lock;
174
181
  Table *write_lock_used;
 
182
  vector<plugin::StorageEngine *> involved_engines;
175
183
  int rc;
176
184
 
177
185
  *need_reopen= false;
202
210
        goto retry;
203
211
      }
204
212
    }
205
 
 
206
 
    session->set_proc_info("System lock");
 
213
    
 
214
    session->set_proc_info("Notify start statement");
 
215
    /*
 
216
     * Here, we advise all storage engines involved in the
 
217
     * statement that we are starting a new statement
 
218
     */
 
219
    if (sql_lock->table_count)
 
220
    {
 
221
      size_t num_tables= sql_lock->table_count;
 
222
      plugin::StorageEngine *engine;
 
223
      set<size_t> involved_slots;
 
224
      for (size_t x= 1; x <= num_tables; x++, tables++)
 
225
      {
 
226
        engine= (*tables)->cursor->engine;
 
227
        if (involved_slots.count(engine->getId()) > 0)
 
228
          continue; /* already added to involved engines */
 
229
        involved_engines.push_back(engine);
 
230
        involved_slots.insert(engine->getId());
 
231
      }
 
232
 
 
233
      for_each(involved_engines.begin(),
 
234
               involved_engines.end(),
 
235
               bind2nd(mem_fun(&plugin::StorageEngine::startStatement), session));
 
236
    }
 
237
 
 
238
    session->set_proc_info("External lock");
 
239
    /*
 
240
     * Here, the call to lock_external() informs the
 
241
     * all engines for all tables used in this statement
 
242
     * of the type of lock that Drizzle intends to take on a 
 
243
     * specific table.
 
244
     */
207
245
    if (sql_lock->table_count && lock_external(session, sql_lock->table,
208
246
                                               sql_lock->table_count))
209
247
    {
263
301
      type for other tables preserved.
264
302
    */
265
303
    reset_lock_data_and_free(&sql_lock);
 
304
 
 
305
    /*
 
306
     * Notify all involved engines that the
 
307
     * SQL statement has ended
 
308
     */
 
309
    for_each(involved_engines.begin(),
 
310
             involved_engines.end(),
 
311
             bind2nd(mem_fun(&plugin::StorageEngine::endStatement), session));
266
312
retry:
267
313
    if (flags & DRIZZLE_LOCK_NOTIFY_IF_NEED_REOPEN)
268
314
    {
282
328
      sql_lock= NULL;
283
329
    }
284
330
  }
285
 
 
286
331
  session->set_time_after_lock();
287
332
  return (sql_lock);
288
333
}
483
528
  return result;
484
529
}
485
530
 
486
 
 
487
531
/** Unlock a set of external. */
488
532
 
489
533
static int unlock_external(Session *session, Table **table,uint32_t count)