drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
transactional_storage_engine.cc
1/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2008 Sun Microsystems, Inc.
5 * Copyright (C) 2009-2010 Jay Pipes <[email protected]>
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
31namespace drizzled {
32namespace plugin {
33
34static std::vector<TransactionalStorageEngine*> g_engines;
35
36TransactionalStorageEngine::TransactionalStorageEngine(const std::string &name_arg,
37 const std::bitset<HTON_BIT_SIZE> &flags_arg)
38 : StorageEngine(name_arg, flags_arg)
39{
40}
41
42void TransactionalStorageEngine::setTransactionReadWrite(Session& session)
43{
44 ResourceContext& resource_context= session.getResourceContext(*this);
45
46 /*
47 When a storage engine method is called, the transaction must
48 have been started, unless it's a DDL call, for which the
49 storage engine starts the transaction internally, and commits
50 it internally, without registering in the ha_list.
51 Unfortunately here we can't know know for sure if the engine
52 has registered the transaction or not, so we must check.
53 */
54 if (resource_context.isStarted())
55 resource_context.markModifiedData();
56}
57
77{
78 for (TransactionalStorageEngine* it : g_engines)
79 it->doReleaseTemporaryLatches(session);
80}
81
82int TransactionalStorageEngine::notifyStartTransaction(Session *session, start_transaction_option_t options)
83{
84 if (g_engines.empty())
85 return 0;
86 std::vector<int> results;
87 results.reserve(g_engines.size());
88 for (TransactionalStorageEngine* it : g_engines)
89 results.push_back(it->startTransaction(session, options));
90 return *std::max_element(results.begin(), results.end());
91}
92
93bool TransactionalStorageEngine::addPlugin(TransactionalStorageEngine &engine)
94{
95 g_engines.push_back(&engine);
96 return StorageEngine::addPlugin(engine);
97}
98
99void TransactionalStorageEngine::removePlugin(TransactionalStorageEngine&)
100{
101 g_engines.clear();
102}
103
104} /* namespace plugin */
105} /* namespace drizzled */
static int notifyStartTransaction(Session *session, start_transaction_option_t options)
TODO: Rename this file - func.h is stupid.