~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/logging.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
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
 
20
#include "config.h"
21
21
#include <drizzled/plugin/logging.h>
22
22
#include <drizzled/gettext.h>
23
 
#include <drizzled/errmsg_print.h>
 
23
#include "drizzled/plugin/registry.h"
24
24
 
25
25
#include <vector>
26
 
#include <algorithm>
27
26
 
28
27
class Session;
29
28
 
 
29
using namespace std;
 
30
 
30
31
namespace drizzled
31
32
{
32
33
 
33
 
std::vector<plugin::Logging *> all_loggers;
 
34
vector<plugin::Logging *> all_loggers;
34
35
 
35
36
 
36
37
bool plugin::Logging::addPlugin(plugin::Logging *handler)
43
44
void plugin::Logging::removePlugin(plugin::Logging *handler)
44
45
{
45
46
  if (handler != NULL)
46
 
    all_loggers.erase(std::find(all_loggers.begin(), all_loggers.end(), handler));
 
47
    all_loggers.erase(find(all_loggers.begin(), all_loggers.end(), handler));
47
48
}
48
49
 
49
50
 
50
 
class PreIterate : public std::unary_function<plugin::Logging *, bool>
 
51
class PreIterate : public unary_function<plugin::Logging *, bool>
51
52
{
52
53
  Session *session;
53
54
public:
54
55
  PreIterate(Session *session_arg) :
55
 
    std::unary_function<plugin::Logging *, bool>(),
 
56
    unary_function<plugin::Logging *, bool>(),
56
57
    session(session_arg) {}
57
58
 
58
59
  inline result_type operator()(argument_type handler)
61
62
    {
62
63
      /* TRANSLATORS: The leading word "logging" is the name
63
64
         of the plugin api, and so should not be translated. */
64
 
      errmsg_printf(error::ERROR,
 
65
      errmsg_printf(ERRMSG_LVL_ERROR,
65
66
                    _("logging '%s' pre() failed"),
66
67
                    handler->getName().c_str());
67
68
      return true;
71
72
};
72
73
 
73
74
 
74
 
class PostIterate : public std::unary_function<plugin::Logging *, bool>
 
75
class PostIterate : public unary_function<plugin::Logging *, bool>
75
76
{
76
77
  Session *session;
77
78
public:
78
79
  PostIterate(Session *session_arg) :
79
 
    std::unary_function<plugin::Logging *, bool>(),
 
80
    unary_function<plugin::Logging *, bool>(),
80
81
    session(session_arg) {}
81
82
 
82
83
  /* This gets called once for each loaded logging plugin */
86
87
    {
87
88
      /* TRANSLATORS: The leading word "logging" is the name
88
89
         of the plugin api, and so should not be translated. */
89
 
      errmsg_printf(error::ERROR,
 
90
      errmsg_printf(ERRMSG_LVL_ERROR,
90
91
                    _("logging '%s' post() failed"),
91
92
                    handler->getName().c_str());
92
93
      return true;
95
96
  }
96
97
};
97
98
 
98
 
class PostEndIterate : public std::unary_function<plugin::Logging *, bool>
99
 
{
100
 
  Session *session;
101
 
public:
102
 
  PostEndIterate(Session *session_arg) :
103
 
    std::unary_function<plugin::Logging *, bool>(),
104
 
    session(session_arg) {}
105
 
 
106
 
  /* This gets called once for each loaded logging plugin */
107
 
  inline result_type operator()(argument_type handler)
108
 
  {
109
 
    if (handler->postEnd(session))
110
 
    {
111
 
      /* TRANSLATORS: The leading word "logging" is the name
112
 
         of the plugin api, and so should not be translated. */
113
 
      errmsg_printf(error::ERROR,
114
 
                    _("logging '%s' postEnd() failed"),
115
 
                    handler->getName().c_str());
116
 
      return true;
117
 
    }
118
 
    return false;
119
 
  }
120
 
};
121
 
 
122
 
class ResetIterate : public std::unary_function<plugin::Logging *, bool>
123
 
{
124
 
  Session *session;
125
 
public:
126
 
  ResetIterate(Session *session_arg) :
127
 
    std::unary_function<plugin::Logging *, bool>(),
128
 
    session(session_arg) {}
129
 
 
130
 
  inline result_type operator()(argument_type handler)
131
 
  {
132
 
    if (handler->resetGlobalScoreboard())
133
 
    {
134
 
      /* TRANSLATORS: The leading word "logging" is the name
135
 
         of the plugin api, and so should not be translated. */
136
 
      errmsg_printf(error::ERROR,
137
 
                    _("logging '%s' resetCurrentScoreboard() failed"),
138
 
                    handler->getName().c_str());
139
 
      return true;
140
 
    }
141
 
    return false;
142
 
  }
143
 
};
144
 
 
145
99
 
146
100
/* This is the Logging::preDo entry point.
147
101
   This gets called by the rest of the Drizzle server code */
148
102
bool plugin::Logging::preDo(Session *session)
149
103
{
150
104
  /* Use find_if instead of foreach so that we can collect return codes */
151
 
  std::vector<plugin::Logging *>::iterator iter=
152
 
    std::find_if(all_loggers.begin(), all_loggers.end(),
153
 
                 PreIterate(session)); 
 
105
  vector<plugin::Logging *>::iterator iter=
 
106
    find_if(all_loggers.begin(), all_loggers.end(),
 
107
            PreIterate(session)); 
154
108
  /* If iter is == end() here, that means that all of the plugins returned
155
109
   * false, which in this case means they all succeeded. Since we want to 
156
110
   * return false on success, we return the value of the two being != 
163
117
bool plugin::Logging::postDo(Session *session)
164
118
{
165
119
  /* Use find_if instead of foreach so that we can collect return codes */
166
 
  std::vector<plugin::Logging *>::iterator iter=
167
 
    std::find_if(all_loggers.begin(), all_loggers.end(),
168
 
                 PostIterate(session)); 
 
120
  vector<plugin::Logging *>::iterator iter=
 
121
    find_if(all_loggers.begin(), all_loggers.end(),
 
122
            PostIterate(session)); 
169
123
  /* If iter is == end() here, that means that all of the plugins returned
170
124
   * false, which in this case means they all succeeded. Since we want to 
171
125
   * return false on success, we return the value of the two being != 
173
127
  return iter != all_loggers.end();
174
128
}
175
129
 
176
 
/* This gets called in the session destructor */
177
 
bool plugin::Logging::postEndDo(Session *session)
178
 
{
179
 
  /* Use find_if instead of foreach so that we can collect return codes */
180
 
  std::vector<plugin::Logging *>::iterator iter=
181
 
    std::find_if(all_loggers.begin(), all_loggers.end(),
182
 
                 PostEndIterate(session));
183
 
  /* If iter is == end() here, that means that all of the plugins returned
184
 
   * false, which in this case means they all succeeded. Since we want to
185
 
   * return false on success, we return the value of the two being !=
186
 
   */
187
 
  return iter != all_loggers.end();
188
 
}
189
 
 
190
 
/* Resets global stats for logging plugin */
191
 
bool plugin::Logging::resetStats(Session *session)
192
 
{
193
 
  std::vector<plugin::Logging *>::iterator iter=
194
 
    std::find_if(all_loggers.begin(), all_loggers.end(),
195
 
                 ResetIterate(session));
196
 
 
197
 
  return iter != all_loggers.end();
198
 
}
199
 
 
200
130
} /* namespace drizzled */