~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/execute.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
 
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2010 Brian Aker
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
20
 
 
21
 
#include <config.h>
22
 
 
23
 
#include <drizzled/session.h>
24
 
#include <drizzled/user_var_entry.h>
25
 
#include <drizzled/plugin/client/concurrent.h>
26
 
#include <drizzled/catalog/local.h>
27
 
#include <drizzled/execute.h>
28
 
 
29
 
namespace drizzled
30
 
{
31
 
 
32
 
Execute::Execute(Session &arg, bool wait_arg) :
33
 
  wait(wait_arg),
34
 
  _session(arg)
35
 
{
36
 
}
37
 
 
38
 
Execute::~Execute()
39
 
{
40
 
}
41
 
 
42
 
void Execute::run(const char *arg, size_t length)
43
 
{
44
 
  std::string execution_string(arg, length);
45
 
  run(execution_string);
46
 
}
47
 
 
48
 
void Execute::run(std::string &execution_string)
49
 
{
50
 
  boost_thread_shared_ptr thread;
51
 
 
52
 
  if (_session.isConcurrentExecuteAllowed())
53
 
  {
54
 
    plugin::client::Concurrent *client= new plugin::client::Concurrent;
55
 
    client->pushSQL(execution_string);
56
 
    Session::shared_ptr new_session= Session::make_shared(client, catalog::local());
57
 
 
58
 
    // We set the current schema.  @todo do the same with catalog
59
 
    util::string::const_shared_ptr schema(_session.schema());
60
 
    if (not schema->empty())
61
 
      new_session->set_db(*schema);
62
 
 
63
 
    new_session->setConcurrentExecute(false);
64
 
 
65
 
    // Overwrite the context in the next session, with what we have in our
66
 
    // session. Eventually we will allow someone to change the effective
67
 
    // user.
68
 
    new_session->user()= _session.user();
69
 
 
70
 
    if (Session::schedule(new_session))
71
 
    {
72
 
      Session::unlink(new_session);
73
 
    }
74
 
    else if (wait)
75
 
    {
76
 
      thread= new_session->getThread();
77
 
    }
78
 
  }
79
 
  else
80
 
  {
81
 
    my_error(ER_WRONG_ARGUMENTS, MYF(0), "A Concurrent Execution Session can not launch another session.");
82
 
    return;
83
 
  }
84
 
 
85
 
  if (wait && thread && thread->joinable())
86
 
  {
87
 
    // We want to make sure that we can be killed
88
 
    if (_session.getThread())
89
 
    {
90
 
      boost::this_thread::restore_interruption dl(_session.getThreadInterupt());
91
 
 
92
 
      try {
93
 
        thread->join();
94
 
      }
95
 
      catch(boost::thread_interrupted const&)
96
 
      {
97
 
        // Just surpress and return the error
98
 
        my_error(drizzled::ER_QUERY_INTERRUPTED, MYF(0));
99
 
        return;
100
 
      }
101
 
    }
102
 
    else
103
 
    {
104
 
      thread->join();
105
 
    }
106
 
  }
107
 
}
108
 
 
109
 
} /* namespace drizzled */