~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/xa_resource_manager.cc

  • Committer: lbieber
  • Date: 2010-09-11 16:33:45 UTC
  • mfrom: (1757.1.2 build)
  • Revision ID: lbieber@orisndriz03-20100911163345-na1t8m18at9thsjl
Merge Vijay - added utf 8 tamil test case suite and test case for creating a database in tamil
Merge Brian - Small set of refactoring (includes one case of memset on a table object).

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.
5
 
 *  Copyright (C) 2010 Jay Pipes <jaypipes@gmail.com>
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *  Copyright (c) 2010 Jay Pipes <jaypipes@gmail.com>
6
6
 *
7
7
 *  This program is free software; you can redistribute it and/or modify
8
8
 *  it under the terms of the GNU General Public License as published by
35
35
#include <algorithm>
36
36
#include <functional>
37
37
 
 
38
using namespace std;
 
39
 
38
40
namespace drizzled
39
41
{
40
42
 
41
43
namespace plugin
42
44
{
43
45
 
44
 
static std::vector<XaResourceManager *> xa_resource_managers;
 
46
static vector<XaResourceManager *> xa_resource_managers;
45
47
 
46
48
int XaResourceManager::commitOrRollbackXID(XID *xid, bool commit)
47
49
{
48
 
  std::vector<int> results;
 
50
  vector<int> results;
49
51
  
50
52
  if (commit)
51
53
    transform(xa_resource_managers.begin(), xa_resource_managers.end(), results.begin(),
52
 
              std::bind2nd(std::mem_fun(&XaResourceManager::xaCommitXid), xid));
 
54
              bind2nd(mem_fun(&XaResourceManager::xaCommitXid), xid));
53
55
  else
54
56
    transform(xa_resource_managers.begin(), xa_resource_managers.end(), results.begin(),
55
 
              std::bind2nd(std::mem_fun(&XaResourceManager::xaRollbackXid), xid));
 
57
              bind2nd(mem_fun(&XaResourceManager::xaRollbackXid), xid));
56
58
 
57
 
  if (std::find_if(results.begin(), results.end(), std::bind2nd(std::equal_to<int>(),0)) == results.end())
 
59
  if (find_if(results.begin(), results.end(), bind2nd(equal_to<int>(),0))
 
60
         == results.end())
58
61
    return 1;
59
 
 
60
62
  return 0;
61
63
}
62
64
 
76
78
    in this case commit_list.size()==0, tc_heuristic_recover == 0
77
79
    there should be no prepared transactions in this case.
78
80
*/
79
 
class XaRecover : std::unary_function<XaResourceManager *, void>
 
81
class XaRecover : unary_function<XaResourceManager *, void>
80
82
{
81
83
private:
82
84
  int trans_len, found_foreign_xids, found_my_xids;
111
113
  
112
114
    while ((got= resource_manager->xaRecover(trans_list, trans_len)) > 0 )
113
115
    {
114
 
      errmsg_printf(error::INFO,
 
116
      errmsg_printf(ERRMSG_LVL_INFO,
115
117
                    _("Found %d prepared transaction(s) in resource manager."),
116
118
                    got);
117
119
      for (int i=0; i < got; i ++)
174
176
  }
175
177
  if (!trans_list)
176
178
  {
177
 
    errmsg_printf(error::ERROR, ER(ER_OUTOFMEMORY), trans_len*sizeof(XID));
 
179
    errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_OUTOFMEMORY), trans_len*sizeof(XID));
178
180
    return(1);
179
181
  }
180
182
 
181
183
  if (commit_list.size())
182
 
    errmsg_printf(error::INFO, _("Starting crash recovery..."));
 
184
    errmsg_printf(ERRMSG_LVL_INFO, _("Starting crash recovery..."));
183
185
 
184
186
  XaRecover recover_func(trans_list, trans_len, commit_list, dry_run);
185
 
  std::for_each(xa_resource_managers.begin(),
186
 
                xa_resource_managers.end(),
187
 
                recover_func);
 
187
  for_each(xa_resource_managers.begin(),
 
188
           xa_resource_managers.end(),
 
189
           recover_func);
188
190
  free(trans_list);
189
191
 
190
192
  if (recover_func.getForeignXIDs())
191
 
    errmsg_printf(error::WARN,
 
193
    errmsg_printf(ERRMSG_LVL_WARN,
192
194
                  _("Found %d prepared XA transactions"),
193
195
                  recover_func.getForeignXIDs());
194
 
 
195
196
  if (dry_run && recover_func.getMyXIDs())
196
197
  {
197
 
    errmsg_printf(error::ERROR,
 
198
    errmsg_printf(ERRMSG_LVL_ERROR,
198
199
                  _("Found %d prepared transactions! It means that drizzled "
199
200
                    "was not shut down properly last time and critical "
200
201
                    "recovery information (last binlog or %s file) was "
204
205
                    recover_func.getMyXIDs(), opt_tc_log_file);
205
206
    return(1);
206
207
  }
207
 
 
208
208
  if (commit_list.size())
209
 
    errmsg_printf(error::INFO, _("Crash recovery finished."));
210
 
 
 
209
    errmsg_printf(ERRMSG_LVL_INFO, _("Crash recovery finished."));
211
210
  return(0);
212
211
}
213
212