~drizzle-developers/ubuntu/natty/drizzle/natty

« back to all changes in this revision

Viewing changes to drizzled/plugin/transactional_storage_engine.cc

  • Committer: Monty Taylor
  • Date: 2010-03-03 19:27:30 UTC
  • mto: (1308.1.2 trunk)
  • mto: This revision was merged to the branch mainline in revision 1278.
  • Revision ID: mordred@inaugust.com-20100303192730-o2o3nmp0lzhuatbe
Tags: upstream-2010.03.1317
ImportĀ upstreamĀ versionĀ 2010.03.1317

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) 2008 Sun Microsystems
 
5
 *  Copyright (c) 2009-2010 Jay Pipes <jaypipes@gmail.com>
 
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
using namespace std;
 
32
 
 
33
namespace drizzled
 
34
{
 
35
 
 
36
namespace plugin
 
37
{
 
38
 
 
39
static vector<TransactionalStorageEngine *> vector_of_transactional_engines;
 
40
 
 
41
TransactionalStorageEngine::TransactionalStorageEngine(const string name_arg,
 
42
                                     const bitset<HTON_BIT_SIZE> &flags_arg,
 
43
                                     bool two_phase_commit_arg)
 
44
    : StorageEngine(name_arg, flags_arg),
 
45
      two_phase_commit(two_phase_commit_arg)
 
46
{
 
47
}
 
48
 
 
49
TransactionalStorageEngine::~TransactionalStorageEngine()
 
50
{
 
51
}
 
52
 
 
53
void TransactionalStorageEngine::setTransactionReadWrite(Session& session)
 
54
{
 
55
  ResourceContext *resource_context= session.getResourceContext(this);
 
56
 
 
57
  /*
 
58
    When a storage engine method is called, the transaction must
 
59
    have been started, unless it's a DDL call, for which the
 
60
    storage engine starts the transaction internally, and commits
 
61
    it internally, without registering in the ha_list.
 
62
    Unfortunately here we can't know know for sure if the engine
 
63
    has registered the transaction or not, so we must check.
 
64
  */
 
65
  if (resource_context->isStarted())
 
66
  {
 
67
    resource_context->markModifiedData();
 
68
  }
 
69
}
 
70
 
 
71
/**
 
72
  @details
 
73
  This function should be called when MySQL sends rows of a SELECT result set
 
74
  or the EOF mark to the client. It releases a possible adaptive hash index
 
75
  S-latch held by session in InnoDB and also releases a possible InnoDB query
 
76
  FIFO ticket to enter InnoDB. To save CPU time, InnoDB allows a session to
 
77
  keep them over several calls of the InnoDB Cursor interface when a join
 
78
  is executed. But when we let the control to pass to the client they have
 
79
  to be released because if the application program uses mysql_use_result(),
 
80
  it may deadlock on the S-latch if the application on another connection
 
81
  performs another SQL query. In MySQL-4.1 this is even more important because
 
82
  there a connection can have several SELECT queries open at the same time.
 
83
 
 
84
  @param session           the thread handle of the current connection
 
85
 
 
86
  @return
 
87
    always 0
 
88
*/
 
89
int TransactionalStorageEngine::releaseTemporaryLatches(Session *session)
 
90
{
 
91
  for_each(vector_of_transactional_engines.begin(), vector_of_transactional_engines.end(),
 
92
           bind2nd(mem_fun(&TransactionalStorageEngine::doReleaseTemporaryLatches),session));
 
93
  return 0;
 
94
}
 
95
 
 
96
struct StartTransactionFunc :public unary_function<TransactionalStorageEngine *, int>
 
97
{
 
98
  Session *session;
 
99
  start_transaction_option_t options;
 
100
  StartTransactionFunc(Session *in_session, start_transaction_option_t in_options) :
 
101
    session(in_session),
 
102
    options(in_options)
 
103
  {}
 
104
  result_type operator()(argument_type engine) const
 
105
  {
 
106
    return engine->startTransaction(session, options);
 
107
  }
 
108
};
 
109
 
 
110
int TransactionalStorageEngine::notifyStartTransaction(Session *session, start_transaction_option_t options)
 
111
{
 
112
  if (vector_of_transactional_engines.empty())
 
113
    return 0;
 
114
  else
 
115
  {
 
116
    StartTransactionFunc functor(session, options);
 
117
    vector<int> results;
 
118
    results.reserve(vector_of_transactional_engines.size());
 
119
    transform(vector_of_transactional_engines.begin(),
 
120
              vector_of_transactional_engines.end(),
 
121
              results.begin(),
 
122
              functor);
 
123
    return *max_element(results.begin(), results.end());
 
124
  }
 
125
}
 
126
 
 
127
bool TransactionalStorageEngine::addPlugin(TransactionalStorageEngine *engine)
 
128
{
 
129
  vector_of_transactional_engines.push_back(engine);
 
130
 
 
131
  return StorageEngine::addPlugin(engine);
 
132
}
 
133
 
 
134
void TransactionalStorageEngine::removePlugin(TransactionalStorageEngine *)
 
135
{
 
136
  vector_of_transactional_engines.clear();
 
137
}
 
138
 
 
139
} /* namespace plugin */
 
140
} /* namespace drizzled */