0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #include <stdio.h>
0035 #include <stdlib.h>
0036 #include <string.h>
0037 #include <errno.h>
0038 #include <regex.h>
0039 #include <utlist.h>
0040
0041 #include <ndebug.h>
0042 #include <atmi.h>
0043 #include <atmi_int.h>
0044 #include <typed_buf.h>
0045 #include <ndrstandard.h>
0046 #include <ubf.h>
0047 #include <Exfields.h>
0048 #include <tperror.h>
0049 #include <exnet.h>
0050 #include <ndrxdcmn.h>
0051
0052 #include "tmsrv.h"
0053 #include "../libatmisrv/srv_int.h"
0054 #include <xa_cmn.h>
0055 #include <atmi_int.h>
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 expublic int tm_prepare_local(UBFH *p_ub, atmi_xa_tx_info_t *p_xai, long btid)
0073 {
0074 int ret = EXSUCCEED;
0075 int lev = log_error;
0076
0077
0078 if (EXSUCCEED!=(ret = atmi_xa_prepare_entry(atmi_xa_get_branch_xid(p_xai, btid),
0079 0)))
0080 {
0081
0082 if (XA_RDONLY==atmi_xa_get_reason())
0083 {
0084 lev=log_debug;
0085 }
0086
0087 NDRX_LOG(lev, "Failed to prepare local transaction btid=%ld!", btid);
0088 if (NULL!=p_ub)
0089 {
0090 atmi_xa_set_error_fmt(p_ub, tperrno, atmi_xa_get_reason(),
0091 "Failed to prepare local transaction, "
0092 "btid %ld, xa error: %d [%s]", btid, ret, atmi_xa_geterrstr(ret));
0093 }
0094
0095 goto out;
0096 }
0097
0098 out:
0099 return ret;
0100 }
0101
0102
0103
0104
0105
0106
0107
0108 expublic int tm_prepare_remote_call(atmi_xa_tx_info_t *p_xai, short rmid, long btid)
0109 {
0110 UBFH* p_ub;
0111
0112
0113
0114
0115
0116 p_ub=atmi_xa_call_tm_generic(ATMI_XA_TMPREPARE, EXTRUE, rmid, p_xai, 0L, btid);
0117
0118 if (NULL==p_ub)
0119 return EXFAIL;
0120 else
0121 {
0122 tpfree((char *)p_ub);
0123 return EXSUCCEED;
0124 }
0125 }
0126
0127
0128
0129
0130
0131 expublic int tm_prepare_combined(atmi_xa_tx_info_t *p_xai, short rmid, long btid)
0132 {
0133 int ret = EXSUCCEED;
0134
0135
0136 if (rmid == G_atmi_env.xa_rmid)
0137 {
0138 ret = tm_prepare_local(NULL, p_xai, btid);
0139 }
0140 else
0141 {
0142 ret = tm_prepare_remote_call(p_xai, rmid, btid);
0143 }
0144
0145 out:
0146 return ret;
0147 }
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158 expublic int tm_rollback_local(UBFH *p_ub, atmi_xa_tx_info_t *p_xai, long btid)
0159 {
0160 int ret = EXSUCCEED;
0161
0162
0163 if (EXSUCCEED!=(ret = atmi_xa_rollback_entry(atmi_xa_get_branch_xid(p_xai, btid),
0164 0)))
0165 {
0166 NDRX_LOG(log_error, "Failed to abort transaction, btid: %ld!", btid);
0167 if (NULL!=p_ub)
0168 {
0169 atmi_xa_set_error_fmt(p_ub, tperrno, atmi_xa_get_reason(),
0170 "Failed to abort transaction, "
0171 "btid %ld, xa error: %d [%s]", btid, ret, atmi_xa_geterrstr(ret));
0172 }
0173
0174 goto out;
0175 }
0176
0177 out:
0178 return ret;
0179 }
0180
0181
0182
0183
0184
0185
0186 expublic int tm_rollback_remote_call(atmi_xa_tx_info_t *p_xai, short rmid, long btid)
0187 {
0188 UBFH* p_ub;
0189
0190
0191
0192
0193 p_ub=atmi_xa_call_tm_generic(ATMI_XA_TMABORT, EXTRUE, rmid, p_xai, 0L, btid);
0194
0195 if (NULL==p_ub)
0196 return EXFAIL;
0197 else
0198 {
0199 tpfree((char *)p_ub);
0200 return EXSUCCEED;
0201 }
0202 }
0203
0204
0205
0206
0207
0208 expublic int tm_rollback_combined(atmi_xa_tx_info_t *p_xai, short rmid, long btid)
0209 {
0210 int ret = EXSUCCEED;
0211
0212
0213 if (rmid == G_atmi_env.xa_rmid)
0214 {
0215 ret = tm_rollback_local(NULL, p_xai, btid);
0216 }
0217 else
0218 {
0219 ret = tm_rollback_remote_call(p_xai, rmid, btid);
0220 }
0221
0222 out:
0223 return ret;
0224 }
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234 expublic int tm_forget_local(UBFH *p_ub, atmi_xa_tx_info_t *p_xai, long btid)
0235 {
0236 int ret = EXSUCCEED;
0237
0238
0239 if (EXSUCCEED!=(ret = atmi_xa_forget_entry(atmi_xa_get_branch_xid(p_xai, btid),
0240 0)))
0241 {
0242 NDRX_LOG(log_error, "Failed to abort transaction, btid: %ld!", btid);
0243 if (NULL!=p_ub)
0244 {
0245 atmi_xa_set_error_fmt(p_ub, tperrno, atmi_xa_get_reason(),
0246 "Failed to abort transaction, "
0247 "btid %ld, xa error: %d [%s]", btid, ret, atmi_xa_geterrstr(ret));
0248 }
0249
0250 goto out;
0251 }
0252
0253 out:
0254 return ret;
0255 }
0256
0257
0258
0259
0260
0261
0262 expublic int tm_forget_remote_call(atmi_xa_tx_info_t *p_xai, short rmid, long btid)
0263 {
0264 UBFH* p_ub;
0265
0266
0267
0268
0269 p_ub=atmi_xa_call_tm_generic(ATMI_XA_TMFORGET, EXTRUE, rmid, p_xai, 0L, btid);
0270
0271 if (NULL==p_ub)
0272 return EXFAIL;
0273 else
0274 {
0275 tpfree((char *)p_ub);
0276 return EXSUCCEED;
0277 }
0278 }
0279
0280
0281
0282
0283
0284 expublic int tm_forget_combined(atmi_xa_tx_info_t *p_xai, short rmid, long btid)
0285 {
0286 int ret = EXSUCCEED;
0287
0288
0289 if (rmid == G_atmi_env.xa_rmid)
0290 {
0291 ret = tm_forget_local(NULL, p_xai, btid);
0292 }
0293 else
0294 {
0295 ret = tm_forget_remote_call(p_xai, rmid, btid);
0296 }
0297
0298 out:
0299 return ret;
0300 }
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310 expublic int tm_commit_local(UBFH *p_ub, atmi_xa_tx_info_t *p_xai, long btid)
0311 {
0312 int ret = EXSUCCEED;
0313
0314
0315 if (EXSUCCEED!=(ret = atmi_xa_commit_entry(atmi_xa_get_branch_xid(p_xai, btid), 0)))
0316 {
0317 NDRX_LOG(log_error, "Failed to commit transaction btid %ld!", btid);
0318
0319 if (NULL!=p_ub)
0320 {
0321 atmi_xa_set_error_fmt(p_ub, tperrno, atmi_xa_get_reason(),
0322 "Failed to commit transaction, "
0323 "btid %ld, xa error: %d [%s]", btid, ret, atmi_xa_geterrstr(ret));
0324 }
0325
0326 goto out;
0327 }
0328
0329 out:
0330 return ret;
0331 }
0332
0333
0334
0335
0336
0337
0338 expublic int tm_commit_remote_call(atmi_xa_tx_info_t *p_xai, short rmid, long btid)
0339 {
0340 UBFH* p_ub;
0341
0342
0343
0344
0345 p_ub=atmi_xa_call_tm_generic(ATMI_XA_TMCOMMIT, EXTRUE, rmid, p_xai, 0L, btid);
0346
0347 if (NULL==p_ub)
0348 return EXFAIL;
0349 else
0350 {
0351 tpfree((char *)p_ub);
0352 return EXSUCCEED;
0353 }
0354 }
0355
0356
0357
0358
0359
0360 expublic int tm_commit_combined(atmi_xa_tx_info_t *p_xai, short rmid, long btid)
0361 {
0362 int ret = EXSUCCEED;
0363
0364
0365 if (rmid == G_atmi_env.xa_rmid)
0366 {
0367 ret = tm_commit_local(NULL, p_xai, btid);
0368 }
0369 else
0370 {
0371 ret = tm_commit_remote_call(p_xai, rmid, btid);
0372 }
0373
0374 out:
0375 return ret;
0376 }
0377