~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/transactional_storage_engine.cc

  • Committer: Brian Aker
  • Date: 2010-02-19 16:34:09 UTC
  • mfrom: (1273.13.92 build)
  • Revision ID: brian@gaz-20100219163409-wh45g0p6fzdsed6r
Merge.

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
 *
 
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; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#include "config.h"
 
21
 
 
22
#include "drizzled/plugin/transactional_storage_engine.h"
 
23
#include "drizzled/resource_context.h"
 
24
#include "drizzled/session.h"
 
25
 
 
26
#include <vector>
 
27
#include <algorithm>
 
28
#include <functional>
 
29
 
 
30
using namespace std;
 
31
 
 
32
namespace drizzled
 
33
{
 
34
 
 
35
namespace plugin
 
36
{
 
37
 
 
38
static vector<TransactionalStorageEngine *> vector_of_transactional_engines;
 
39
 
 
40
TransactionalStorageEngine::TransactionalStorageEngine(const string name_arg,
 
41
                                     const bitset<HTON_BIT_SIZE> &flags_arg,
 
42
                                     bool two_phase_commit_arg)
 
43
    : StorageEngine(name_arg, flags_arg),
 
44
      two_phase_commit(two_phase_commit_arg)
 
45
{
 
46
}
 
47
 
 
48
TransactionalStorageEngine::~TransactionalStorageEngine()
 
49
{
 
50
}
 
51
 
 
52
void TransactionalStorageEngine::setTransactionReadWrite(Session& session)
 
53
{
 
54
  ResourceContext *resource_context= session.getResourceContext(this);
 
55
 
 
56
  /*
 
57
    When a storage engine method is called, the transaction must
 
58
    have been started, unless it's a DDL call, for which the
 
59
    storage engine starts the transaction internally, and commits
 
60
    it internally, without registering in the ha_list.
 
61
    Unfortunately here we can't know know for sure if the engine
 
62
    has registered the transaction or not, so we must check.
 
63
  */
 
64
  if (resource_context->isStarted())
 
65
  {
 
66
    resource_context->markModifiedData();
 
67
  }
 
68
}
 
69
 
 
70
/**
 
71
  @details
 
72
  This function should be called when MySQL sends rows of a SELECT result set
 
73
  or the EOF mark to the client. It releases a possible adaptive hash index
 
74
  S-latch held by session in InnoDB and also releases a possible InnoDB query
 
75
  FIFO ticket to enter InnoDB. To save CPU time, InnoDB allows a session to
 
76
  keep them over several calls of the InnoDB Cursor interface when a join
 
77
  is executed. But when we let the control to pass to the client they have
 
78
  to be released because if the application program uses mysql_use_result(),
 
79
  it may deadlock on the S-latch if the application on another connection
 
80
  performs another SQL query. In MySQL-4.1 this is even more important because
 
81
  there a connection can have several SELECT queries open at the same time.
 
82
 
 
83
  @param session           the thread handle of the current connection
 
84
 
 
85
  @return
 
86
    always 0
 
87
*/
 
88
int TransactionalStorageEngine::releaseTemporaryLatches(Session *session)
 
89
{
 
90
  for_each(vector_of_transactional_engines.begin(), vector_of_transactional_engines.end(),
 
91
           bind2nd(mem_fun(&TransactionalStorageEngine::doReleaseTemporaryLatches),session));
 
92
  return 0;
 
93
}
 
94
 
 
95
int TransactionalStorageEngine::startConsistentSnapshot(Session *session)
 
96
{
 
97
  for_each(vector_of_transactional_engines.begin(), vector_of_transactional_engines.end(),
 
98
           bind2nd(mem_fun(&TransactionalStorageEngine::doStartConsistentSnapshot),
 
99
                   session));
 
100
  return 0;
 
101
}
 
102
 
 
103
bool TransactionalStorageEngine::addPlugin(TransactionalStorageEngine *engine)
 
104
{
 
105
  vector_of_transactional_engines.push_back(engine);
 
106
 
 
107
  return StorageEngine::addPlugin(engine);
 
108
}
 
109
 
 
110
void TransactionalStorageEngine::removePlugin(TransactionalStorageEngine *)
 
111
{
 
112
  vector_of_transactional_engines.clear();
 
113
}
 
114
 
 
115
} /* namespace plugin */
 
116
} /* namespace drizzled */