~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/insert_select.cc

This patch completes the first step in the splitting of
the XA resource manager API from the storage engine API,
as outlined in the specification here:

http://drizzle.org/wiki/XaStorageEngine

* Splits plugin::StorageEngine into a base StorageEngine
  class and two derived classes, TransactionalStorageEngine
  and XaStorageEngine.  XaStorageEngine derives from
  TransactionalStorageEngine and creates the XA Resource
  Manager API for storage engines.

  - The methods moved from StorageEngine to TransactionalStorageEngine
    include releaseTemporaryLatches(), startConsistentSnapshot(), 
    commit(), rollback(), setSavepoint(), releaseSavepoint(),
    rollbackToSavepoint() and hasTwoPhaseCommit()
  - The methods moved from StorageEngine to XaStorageEngine
    include recover(), commitXid(), rollbackXid(), and prepare()

* Places all static "EngineVector"s into their proper
  namespaces (typedefs belong in header files, not implementation files)
  and places all static methods corresponding
  to either only transactional engines or only XA engines
  into their respective files in /drizzled/plugin/

* Modifies the InnoDB "handler" files to extend plugin::XaStorageEngine
  and not plugin::StorageEngine

The next step, as outlined in the wiki spec page above, is to isolate
the XA Resource Manager API into its own plugin class and modify
plugin::XaStorageEngine to implement plugin::XaResourceManager via
composition.  This is necessary to enable building plugins which can
participate in an XA transaction *without having to have that plugin
implement the entire storage engine API*

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2009 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
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
#include <drizzled/show.h>
23
23
#include <drizzled/lock.h>
24
24
#include <drizzled/session.h>
25
25
#include <drizzled/probes.h>
26
26
#include <drizzled/statement/insert_select.h>
27
 
#include <drizzled/select_insert.h>
28
27
 
29
28
namespace drizzled
30
29
{
31
30
 
32
31
bool statement::InsertSelect::execute()
33
32
{
34
 
  TableList *first_table= (TableList *) getSession()->getLex()->select_lex.table_list.first;
35
 
  TableList *all_tables= getSession()->getLex()->query_tables;
 
33
  TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
 
34
  TableList *all_tables= session->lex->query_tables;
36
35
  assert(first_table == all_tables && first_table != 0);
37
 
  Select_Lex *select_lex= &getSession()->getLex()->select_lex;
38
 
  Select_Lex_Unit *unit= &getSession()->getLex()->unit;
 
36
  Select_Lex *select_lex= &session->lex->select_lex;
 
37
  Select_Lex_Unit *unit= &session->lex->unit;
39
38
  select_result *sel_result= NULL;
40
39
  bool res= false;
41
40
  bool need_start_waiting= false;
42
41
 
43
 
  if (insert_precheck(getSession(), all_tables))
 
42
  if (insert_precheck(session, all_tables))
44
43
  {
45
44
    return true;
46
45
  }
50
49
 
51
50
  unit->set_limit(select_lex);
52
51
 
53
 
  if (! (need_start_waiting= not getSession()->wait_if_global_read_lock(false, true)))
 
52
  if (! (need_start_waiting= ! wait_if_global_read_lock(session, 0, 1)))
54
53
  {
55
54
    return true;
56
55
  }
57
56
 
58
 
  if (! (res= getSession()->openTablesLock(all_tables)))
 
57
  if (! (res= session->openTablesLock(all_tables)))
59
58
  {
60
 
    DRIZZLE_INSERT_SELECT_START(getSession()->getQueryString()->c_str());
 
59
    DRIZZLE_INSERT_SELECT_START(session->query);
61
60
    /* Skip first table, which is the table we are inserting in */
62
61
    TableList *second_table= first_table->next_local;
63
62
    select_lex->table_list.first= (unsigned char*) second_table;
64
63
    select_lex->context.table_list=
65
64
      select_lex->context.first_name_resolution_table= second_table;
66
 
    res= insert_select_prepare(getSession());
 
65
    res= mysql_insert_select_prepare(session);
67
66
    if (! res && (sel_result= new select_insert(first_table,
68
67
                                                first_table->table,
69
 
                                                &getSession()->getLex()->field_list,
70
 
                                                &getSession()->getLex()->update_list,
71
 
                                                &getSession()->getLex()->value_list,
72
 
                                                getSession()->getLex()->duplicates,
73
 
                                                getSession()->getLex()->ignore)))
 
68
                                                &session->lex->field_list,
 
69
                                                &session->lex->update_list,
 
70
                                                &session->lex->value_list,
 
71
                                                session->lex->duplicates,
 
72
                                                session->lex->ignore)))
74
73
    {
75
 
      res= handle_select(getSession(), 
76
 
                         getSession()->getLex(), 
 
74
      res= handle_select(session, 
 
75
                         session->lex, 
77
76
                         sel_result, 
78
77
                         OPTION_SETUP_TABLES_DONE);
79
 
 
80
78
      /*
81
79
         Invalidate the table in the query cache if something changed
82
80
         after unlocking when changes become visible.
83
81
         TODO: this is a workaround. right way will be move invalidating in
84
82
         the unlock procedure.
85
83
       */
86
 
      if (first_table->lock_type == TL_WRITE_CONCURRENT_INSERT && getSession()->lock)
 
84
      if (first_table->lock_type == TL_WRITE_CONCURRENT_INSERT &&
 
85
          session->lock)
87
86
      {
88
87
        /* INSERT ... SELECT should invalidate only the very first table */
89
88
        TableList *save_table= first_table->next_local;
100
99
     Release the protection against the global read lock and wake
101
100
     everyone, who might want to set a global read lock.
102
101
   */
103
 
  getSession()->startWaitingGlobalReadLock();
 
102
  start_waiting_global_read_lock(session);
104
103
 
105
104
  return res;
106
105
}