~drizzle-trunk/drizzle/development

1273.1.15 by Jay Pipes
This patch completes the first step in the splitting of
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
 *  Copyright (C) 2009-2010 Jay Pipes <jaypipes@gmail.com>
1273.1.15 by Jay Pipes
This patch completes the first step in the splitting of
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; version 2 of the License.
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/plugin/transactional_storage_engine.h"
24
#include "drizzled/resource_context.h"
25
#include "drizzled/session.h"
26
27
#include <vector>
28
#include <algorithm>
29
#include <functional>
30
31
namespace drizzled
32
{
33
34
namespace plugin
35
{
36
1966.2.6 by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing
37
static std::vector<TransactionalStorageEngine *> vector_of_transactional_engines;
1273.1.15 by Jay Pipes
This patch completes the first step in the splitting of
38
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
39
TransactionalStorageEngine::TransactionalStorageEngine(const std::string name_arg,
40
                                                       const std::bitset<HTON_BIT_SIZE> &flags_arg)
1273.1.30 by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager
41
    : StorageEngine(name_arg, flags_arg)
1273.1.15 by Jay Pipes
This patch completes the first step in the splitting of
42
{
43
}
44
45
TransactionalStorageEngine::~TransactionalStorageEngine()
46
{
47
}
48
49
void TransactionalStorageEngine::setTransactionReadWrite(Session& session)
50
{
51
  ResourceContext *resource_context= session.getResourceContext(this);
52
53
  /*
54
    When a storage engine method is called, the transaction must
55
    have been started, unless it's a DDL call, for which the
56
    storage engine starts the transaction internally, and commits
57
    it internally, without registering in the ha_list.
58
    Unfortunately here we can't know know for sure if the engine
59
    has registered the transaction or not, so we must check.
60
  */
61
  if (resource_context->isStarted())
62
  {
63
    resource_context->markModifiedData();
64
  }
65
}
66
67
/**
68
  @details
69
  This function should be called when MySQL sends rows of a SELECT result set
70
  or the EOF mark to the client. It releases a possible adaptive hash index
71
  S-latch held by session in InnoDB and also releases a possible InnoDB query
72
  FIFO ticket to enter InnoDB. To save CPU time, InnoDB allows a session to
73
  keep them over several calls of the InnoDB Cursor interface when a join
74
  is executed. But when we let the control to pass to the client they have
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
75
  to be released because if the application program uses use_result(),
1273.1.15 by Jay Pipes
This patch completes the first step in the splitting of
76
  it may deadlock on the S-latch if the application on another connection
77
  performs another SQL query. In MySQL-4.1 this is even more important because
78
  there a connection can have several SELECT queries open at the same time.
79
80
  @param session           the thread handle of the current connection
81
82
  @return
83
    always 0
84
*/
85
int TransactionalStorageEngine::releaseTemporaryLatches(Session *session)
86
{
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
87
  std::for_each(vector_of_transactional_engines.begin(), vector_of_transactional_engines.end(),
88
                std::bind2nd(std::mem_fun(&TransactionalStorageEngine::doReleaseTemporaryLatches),session));
1273.1.15 by Jay Pipes
This patch completes the first step in the splitting of
89
  return 0;
90
}
91
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
92
struct StartTransactionFunc :public std::unary_function<TransactionalStorageEngine *, int>
1273.1.27 by Jay Pipes
Completes the work of removing the weirdness around transaction
93
{
94
  Session *session;
95
  start_transaction_option_t options;
96
  StartTransactionFunc(Session *in_session, start_transaction_option_t in_options) :
97
    session(in_session),
98
    options(in_options)
99
  {}
100
  result_type operator()(argument_type engine) const
101
  {
102
    return engine->startTransaction(session, options);
103
  }
104
};
105
106
int TransactionalStorageEngine::notifyStartTransaction(Session *session, start_transaction_option_t options)
107
{
108
  if (vector_of_transactional_engines.empty())
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
109
  {
1273.1.27 by Jay Pipes
Completes the work of removing the weirdness around transaction
110
    return 0;
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
111
  }
1273.1.27 by Jay Pipes
Completes the work of removing the weirdness around transaction
112
  else
113
  {
114
    StartTransactionFunc functor(session, options);
1966.2.6 by Brian Aker
This is from the catalog patch (I'm pushing it up as its own little thing
115
    std::vector<int> results;
1273.1.27 by Jay Pipes
Completes the work of removing the weirdness around transaction
116
    results.reserve(vector_of_transactional_engines.size());
117
    transform(vector_of_transactional_engines.begin(),
118
              vector_of_transactional_engines.end(),
119
              results.begin(),
120
              functor);
1966.2.16 by Brian Aker
STD max_element
121
    return *std::max_element(results.begin(), results.end());
1273.1.27 by Jay Pipes
Completes the work of removing the weirdness around transaction
122
  }
1273.1.15 by Jay Pipes
This patch completes the first step in the splitting of
123
}
124
125
bool TransactionalStorageEngine::addPlugin(TransactionalStorageEngine *engine)
126
{
127
  vector_of_transactional_engines.push_back(engine);
128
129
  return StorageEngine::addPlugin(engine);
130
}
131
132
void TransactionalStorageEngine::removePlugin(TransactionalStorageEngine *)
133
{
134
  vector_of_transactional_engines.clear();
135
}
136
137
} /* namespace plugin */
138
} /* namespace drizzled */