~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/xa_resource_manager.cc

Merge Monty - Added inter-plugin dependencies for controlling plugin load order

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include <config.h>
 
21
#include "config.h"
22
22
 
23
 
#include <drizzled/cached_directory.h>
 
23
#include "drizzled/cached_directory.h"
24
24
 
25
25
#include <drizzled/definitions.h>
26
26
#include <drizzled/session.h>
27
27
#include <drizzled/error.h>
28
28
#include <drizzled/gettext.h>
29
29
#include <drizzled/plugin/xa_resource_manager.h>
30
 
#include <drizzled/xid.h>
31
 
#include <drizzled/errmsg_print.h>
32
 
#include <drizzled/sys_var.h>
 
30
#include "drizzled/xid.h"
 
31
 
33
32
 
34
33
#include <string>
35
34
#include <vector>
36
35
#include <algorithm>
37
36
#include <functional>
38
37
 
39
 
namespace drizzled {
40
 
namespace plugin {
 
38
namespace drizzled
 
39
{
 
40
 
 
41
namespace plugin
 
42
{
41
43
 
42
44
static std::vector<XaResourceManager *> xa_resource_managers;
43
45
 
44
46
int XaResourceManager::commitOrRollbackXID(XID *xid, bool commit)
45
47
{
46
48
  std::vector<int> results;
47
 
 
 
49
  
48
50
  if (commit)
49
51
    transform(xa_resource_managers.begin(), xa_resource_managers.end(), results.begin(),
50
52
              std::bind2nd(std::mem_fun(&XaResourceManager::xaCommitXid), xid));
85
87
public:
86
88
  XaRecover(XID *trans_list_arg, int trans_len_arg,
87
89
            const XaResourceManager::commit_list_set& commit_list_arg,
88
 
            bool dry_run_arg)
 
90
            bool dry_run_arg) 
89
91
    : trans_len(trans_len_arg), found_foreign_xids(0), found_my_xids(0),
90
92
      result(false),
91
93
      trans_list(trans_list_arg), commit_list(commit_list_arg),
92
94
      dry_run(dry_run_arg)
93
95
  {}
94
 
 
 
96
  
95
97
  int getForeignXIDs()
96
98
  {
97
 
    return found_foreign_xids;
 
99
    return found_foreign_xids; 
98
100
  }
99
101
 
100
102
  int getMyXIDs()
101
103
  {
102
 
    return found_my_xids;
 
104
    return found_my_xids; 
103
105
  }
104
106
 
105
107
  result_type operator() (argument_type resource_manager)
106
108
  {
107
 
 
 
109
  
108
110
    int got;
109
 
 
 
111
  
110
112
    while ((got= resource_manager->xaRecover(trans_list, trans_len)) > 0 )
111
113
    {
112
 
      errmsg_printf(error::INFO,
 
114
      errmsg_printf(ERRMSG_LVL_INFO,
113
115
                    _("Found %d prepared transaction(s) in resource manager."),
114
116
                    got);
115
117
      for (int i=0; i < got; i ++)
117
119
        my_xid x=trans_list[i].get_my_xid();
118
120
        if (!x) // not "mine" - that is generated by external TM
119
121
        {
 
122
          xid_cache_insert(trans_list+i, XA_PREPARED);
120
123
          found_foreign_xids++;
121
124
          continue;
122
125
        }
171
174
  }
172
175
  if (!trans_list)
173
176
  {
174
 
    errmsg_printf(error::ERROR, ER(ER_OUTOFMEMORY), trans_len*sizeof(XID));
 
177
    errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_OUTOFMEMORY), trans_len*sizeof(XID));
175
178
    return(1);
176
179
  }
177
180
 
178
181
  if (commit_list.size())
179
 
    errmsg_printf(error::INFO, _("Starting crash recovery..."));
 
182
    errmsg_printf(ERRMSG_LVL_INFO, _("Starting crash recovery..."));
180
183
 
181
184
  XaRecover recover_func(trans_list, trans_len, commit_list, dry_run);
182
185
  std::for_each(xa_resource_managers.begin(),
183
186
                xa_resource_managers.end(),
184
187
                recover_func);
185
188
  free(trans_list);
186
 
 
 
189
 
187
190
  if (recover_func.getForeignXIDs())
188
 
    errmsg_printf(error::WARN,
 
191
    errmsg_printf(ERRMSG_LVL_WARN,
189
192
                  _("Found %d prepared XA transactions"),
190
193
                  recover_func.getForeignXIDs());
191
 
 
192
194
  if (dry_run && recover_func.getMyXIDs())
193
195
  {
194
 
    errmsg_printf(error::ERROR,
 
196
    errmsg_printf(ERRMSG_LVL_ERROR,
195
197
                  _("Found %d prepared transactions! It means that drizzled "
196
198
                    "was not shut down properly last time and critical "
197
199
                    "recovery information (last binlog or %s file) was "
201
203
                    recover_func.getMyXIDs(), opt_tc_log_file);
202
204
    return(1);
203
205
  }
204
 
 
205
206
  if (commit_list.size())
206
 
    errmsg_printf(error::INFO, _("Crash recovery finished."));
207
 
 
 
207
    errmsg_printf(ERRMSG_LVL_INFO, _("Crash recovery finished."));
208
208
  return(0);
209
209
}
210
210