~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/xa_resource_manager.cc

  • Committer: Olaf van der Spek
  • Date: 2011-08-05 13:28:48 UTC
  • mto: This revision was merged to the branch mainline in revision 2395.
  • Revision ID: olafvdspek@gmail.com-20110805132848-vvwjg6pgwf56xnsd
Use const char* instead of str_ref

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
 
 
 
30
#include <drizzled/xid.h>
 
31
#include <drizzled/errmsg_print.h>
 
32
#include <drizzled/sys_var.h>
32
33
 
33
34
#include <string>
34
35
#include <vector>
35
36
#include <algorithm>
36
37
#include <functional>
37
38
 
38
 
namespace drizzled
39
 
{
40
 
 
41
 
namespace plugin
42
 
{
43
 
 
44
 
static std::vector<XaResourceManager *> xa_resource_managers;
 
39
namespace drizzled {
 
40
namespace plugin {
 
41
 
 
42
typedef std::vector<XaResourceManager*> xa_resource_managers_t;
 
43
static xa_resource_managers_t xa_resource_managers;
45
44
 
46
45
int XaResourceManager::commitOrRollbackXID(XID *xid, bool commit)
47
46
{
48
47
  std::vector<int> results;
49
 
  
50
 
  if (commit)
51
 
    transform(xa_resource_managers.begin(), xa_resource_managers.end(), results.begin(),
52
 
              std::bind2nd(std::mem_fun(&XaResourceManager::xaCommitXid), xid));
53
 
  else
54
 
    transform(xa_resource_managers.begin(), xa_resource_managers.end(), results.begin(),
55
 
              std::bind2nd(std::mem_fun(&XaResourceManager::xaRollbackXid), xid));
56
 
 
57
 
  if (std::find_if(results.begin(), results.end(), std::bind2nd(std::equal_to<int>(),0)) == results.end())
58
 
    return 1;
59
 
 
60
 
  return 0;
 
48
  BOOST_FOREACH(XaResourceManager* it, xa_resource_managers)
 
49
    results.push_back(commit ? it->xaCommitXid(xid) : it->xaRollbackXid(xid));
 
50
  return std::find(results.begin(), results.end(), 0) == results.end();
61
51
}
62
52
 
63
53
/**
87
77
public:
88
78
  XaRecover(XID *trans_list_arg, int trans_len_arg,
89
79
            const XaResourceManager::commit_list_set& commit_list_arg,
90
 
            bool dry_run_arg) 
 
80
            bool dry_run_arg)
91
81
    : trans_len(trans_len_arg), found_foreign_xids(0), found_my_xids(0),
92
82
      result(false),
93
83
      trans_list(trans_list_arg), commit_list(commit_list_arg),
94
84
      dry_run(dry_run_arg)
95
85
  {}
96
 
  
 
86
 
97
87
  int getForeignXIDs()
98
88
  {
99
 
    return found_foreign_xids; 
 
89
    return found_foreign_xids;
100
90
  }
101
91
 
102
92
  int getMyXIDs()
103
93
  {
104
 
    return found_my_xids; 
 
94
    return found_my_xids;
105
95
  }
106
96
 
107
97
  result_type operator() (argument_type resource_manager)
108
98
  {
109
 
  
 
99
 
110
100
    int got;
111
 
  
 
101
 
112
102
    while ((got= resource_manager->xaRecover(trans_list, trans_len)) > 0 )
113
103
    {
114
104
      errmsg_printf(error::INFO,
119
109
        my_xid x=trans_list[i].get_my_xid();
120
110
        if (!x) // not "mine" - that is generated by external TM
121
111
        {
122
 
          xid_cache_insert(trans_list+i, XA_PREPARED);
123
112
          found_foreign_xids++;
124
113
          continue;
125
114
        }
175
164
  if (!trans_list)
176
165
  {
177
166
    errmsg_printf(error::ERROR, ER(ER_OUTOFMEMORY), trans_len*sizeof(XID));
178
 
    return(1);
 
167
    return 1;
179
168
  }
180
169
 
181
170
  if (commit_list.size())
186
175
                xa_resource_managers.end(),
187
176
                recover_func);
188
177
  free(trans_list);
189
 
 
 
178
 
190
179
  if (recover_func.getForeignXIDs())
191
180
    errmsg_printf(error::WARN,
192
181
                  _("Found %d prepared XA transactions"),
202
191
                    "drizzled with the --tc-heuristic-recover switch to "
203
192
                    "commit or rollback pending transactions."),
204
193
                    recover_func.getMyXIDs(), opt_tc_log_file);
205
 
    return(1);
 
194
    return 1;
206
195
  }
207
196
 
208
197
  if (commit_list.size())
209
198
    errmsg_printf(error::INFO, _("Crash recovery finished."));
210
199
 
211
 
  return(0);
 
200
  return 0;
212
201
}
213
202
 
214
203
bool XaResourceManager::addPlugin(XaResourceManager *resource_manager)