35
36
#include <algorithm>
36
37
#include <functional>
44
static std::vector<XaResourceManager *> xa_resource_managers;
47
static vector<XaResourceManager *> xa_resource_managers;
46
49
int XaResourceManager::commitOrRollbackXID(XID *xid, bool commit)
48
std::vector<int> results;
51
54
transform(xa_resource_managers.begin(), xa_resource_managers.end(), results.begin(),
52
std::bind2nd(std::mem_fun(&XaResourceManager::xaCommitXid), xid));
55
bind2nd(mem_fun(&XaResourceManager::xaCommitXid), xid));
54
57
transform(xa_resource_managers.begin(), xa_resource_managers.end(), results.begin(),
55
std::bind2nd(std::mem_fun(&XaResourceManager::xaRollbackXid), xid));
58
bind2nd(mem_fun(&XaResourceManager::xaRollbackXid), xid));
57
if (std::find_if(results.begin(), results.end(), std::bind2nd(std::equal_to<int>(),0)) == results.end())
60
if (find_if(results.begin(), results.end(), bind2nd(equal_to<int>(),0))
67
70
there are three modes of operation:
68
71
- automatic recover after a crash
69
in this case commit_list.size() != 0, tc_heuristic_recover==0
72
in this case commit_list != 0, tc_heuristic_recover==0
70
73
all xids from commit_list are committed, others are rolled back
71
74
- manual (heuristic) recover
72
in this case commit_list.size()==0, tc_heuristic_recover != 0
75
in this case commit_list==0, tc_heuristic_recover != 0
73
76
DBA has explicitly specified that all prepared transactions should
74
77
be committed (or rolled back).
75
- no recovery (Drizzle did not detect a crash)
76
in this case commit_list.size()==0, tc_heuristic_recover == 0
78
- no recovery (MySQL did not detect a crash)
79
in this case commit_list==0, tc_heuristic_recover == 0
77
80
there should be no prepared transactions in this case.
79
class XaRecover : std::unary_function<XaResourceManager *, void>
82
class XaRecover : unary_function<XaResourceManager *, void>
82
84
int trans_len, found_foreign_xids, found_my_xids;
85
const XaResourceManager::commit_list_set &commit_list;
88
90
XaRecover(XID *trans_list_arg, int trans_len_arg,
89
const XaResourceManager::commit_list_set& commit_list_arg,
91
HASH *commit_list_arg, bool dry_run_arg)
91
92
: trans_len(trans_len_arg), found_foreign_xids(0), found_my_xids(0),
93
94
trans_list(trans_list_arg), commit_list(commit_list_arg),
132
if (commit_list.size() ?
133
commit_list.find(x) != commit_list.end() :
134
hash_search(commit_list, (unsigned char *)&x, sizeof(x)) != 0 :
134
135
tc_heuristic_recover == TC_HEURISTIC_RECOVER_COMMIT)
136
137
resource_manager->xaCommitXid(trans_list+i);
149
int XaResourceManager::recoverAllXids()
151
const XaResourceManager::commit_list_set empty_commit_set;
152
return recoverAllXids(empty_commit_set);
155
int XaResourceManager::recoverAllXids(const XaResourceManager::commit_list_set &commit_list)
150
int XaResourceManager::recoverAllXids(HASH *commit_list)
157
152
XID *trans_list= NULL;
158
153
int trans_len= 0;
160
bool dry_run= (commit_list.size() == 0 && tc_heuristic_recover==0);
155
bool dry_run= (commit_list==0 && tc_heuristic_recover==0);
162
157
/* commit_list and tc_heuristic_recover cannot be set both */
163
assert(commit_list.size() == 0 || tc_heuristic_recover == 0);
158
assert(commit_list==0 || tc_heuristic_recover==0);
165
160
if (xa_resource_managers.size() <= 1)
181
if (commit_list.size())
182
177
errmsg_printf(ERRMSG_LVL_INFO, _("Starting crash recovery..."));
184
179
XaRecover recover_func(trans_list, trans_len, commit_list, dry_run);
185
std::for_each(xa_resource_managers.begin(),
186
xa_resource_managers.end(),
180
for_each(xa_resource_managers.begin(),
181
xa_resource_managers.end(),
188
183
free(trans_list);
190
185
if (recover_func.getForeignXIDs())