21 #include "userInterface.h"
24 #include "ndb_schema.hpp"
25 #include "ndb_error.hpp"
31 startTransaction(
Ndb * pNDB,
33 const SubscriberNumber inNumber){
35 const int keyDataLenBytes =
sizeof(ServerId)+SUBSCRIBER_NUMBER_LENGTH;
36 const int keyDataLen_64Words = keyDataLenBytes >> 3;
38 Uint64 keyDataBuf[keyDataLen_64Words+1];
40 char * keyDataBuf_charP = (
char *)&keyDataBuf[0];
41 Uint32 * keyDataBuf_wo32P = (Uint32 *)&keyDataBuf[0];
44 keyDataBuf_wo32P[0] = inServerId;
46 memcpy(&keyDataBuf_charP[
sizeof(ServerId)], inNumber,
47 SUBSCRIBER_NUMBER_LENGTH);
52 void T1_Callback(
int result,
NdbConnection * pCon,
void * threadData);
53 void T2_Callback(
int result,
NdbConnection * pCon,
void * threadData);
54 void T3_Callback_1(
int result,
NdbConnection * pCon,
void * threadData);
55 void T3_Callback_2(
int result,
NdbConnection * pCon,
void * threadData);
56 void T3_Callback_3(
int result,
NdbConnection * pCon,
void * threadData);
57 void T4_Callback_1(
int result,
NdbConnection * pCon,
void * threadData);
58 void T4_Callback_2(
int result,
NdbConnection * pCon,
void * threadData);
59 void T4_Callback_3(
int result,
NdbConnection * pCon,
void * threadData);
60 void T5_Callback_1(
int result,
NdbConnection * pCon,
void * threadData);
61 void T5_Callback_2(
int result,
NdbConnection * pCon,
void * threadData);
62 void T5_Callback_3(
int result,
NdbConnection * pCon,
void * threadData);
80 DEBUG2(
"T1(%.*s): - Starting\n", SUBSCRIBER_NUMBER_LENGTH,
81 td->transactionData.number);
89 MyOp->
equal(IND_SUBSCRIBER_NUMBER,
90 td->transactionData.number);
91 MyOp->
setValue(IND_SUBSCRIBER_LOCATION,
92 (
char *)&td->transactionData.location);
93 MyOp->
setValue(IND_SUBSCRIBER_CHANGED_BY,
94 td->transactionData.changed_by);
95 MyOp->
setValue(IND_SUBSCRIBER_CHANGED_TIME,
96 td->transactionData.changed_time);
99 CHECK_NULL(MyOp,
"T1: getNdbOperation", pCON);
102 error_handler(
"T1-1: startTranscation",
103 pNDB->getNdbErrorString(),
109 T1_Callback(
int result,
NdbConnection * pCON,
void * threadData){
112 DEBUG2(
"T1(%.*s): - Completing\n", SUBSCRIBER_NUMBER_LENGTH,
113 td->transactionData.number);
115 CHECK_MINUS_ONE(result,
"T1: Commit",
138 DEBUG3(
"T2(%.*s, %p): - Starting\n", SUBSCRIBER_NUMBER_LENGTH,
139 td->transactionData.number,
140 td->transactionData.location);
147 error_handler(
"T2-1: startTransaction",
148 pNDB->getNdbErrorString(),
152 CHECK_NULL(MyOp,
"T2: getNdbOperation",
156 MyOp->equal(IND_SUBSCRIBER_NUMBER,
157 td->transactionData.number);
158 MyOp->getValue(IND_SUBSCRIBER_LOCATION,
159 (
char *)&td->transactionData.location);
160 MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
161 td->transactionData.changed_by);
162 MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
163 td->transactionData.changed_time);
164 MyOp->getValue(IND_SUBSCRIBER_NAME,
165 td->transactionData.name);
170 T2_Callback(
int result,
NdbConnection * pCON,
void * threadData){
172 DEBUG3(
"T2(%.*s, %p): - Completing\n", SUBSCRIBER_NUMBER_LENGTH,
173 td->transactionData.number,
174 td->transactionData.location);
176 CHECK_MINUS_ONE(result,
"T2: Commit", pCON);
201 DEBUG3(
"T3(%.*s, %.2d): - Starting\n", SUBSCRIBER_NUMBER_LENGTH,
202 td->transactionData.number,
203 td->transactionData.server_id);
209 td->transactionData.server_id,
210 td->transactionData.number);
212 error_handler(
"T3-1: startTranscation",
213 pNDB->getNdbErrorString(),
217 CHECK_NULL(MyOp,
"T3-1: getNdbOperation",
221 MyOp->equal(IND_SUBSCRIBER_NUMBER,
222 td->transactionData.number);
223 MyOp->getValue(IND_SUBSCRIBER_LOCATION,
224 (
char *)&td->transactionData.location);
225 MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
226 td->transactionData.changed_by);
227 MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
228 td->transactionData.changed_time);
229 MyOp->getValue(IND_SUBSCRIBER_GROUP,
230 (
char *)&td->transactionData.group_id);
231 MyOp->getValue(IND_SUBSCRIBER_SESSIONS,
232 (
char *)&td->transactionData.sessions);
237 T3_Callback_1(
int result,
NdbConnection * pCON,
void * threadData){
239 DEBUG3(
"T3(%.*s, %.2d): - Callback 1\n", SUBSCRIBER_NUMBER_LENGTH,
240 td->transactionData.number,
241 td->transactionData.server_id);
243 CHECK_MINUS_ONE(result,
"T3-1: NoCommit", pCON);
246 CHECK_NULL(MyOp,
"T3-2: getNdbOperation",
250 MyOp->
equal(IND_GROUP_ID,
251 (
char*)&td->transactionData.group_id);
252 MyOp->
getValue(IND_GROUP_ALLOW_READ,
253 (
char *)&td->transactionData.permission);
258 T3_Callback_2(
int result,
NdbConnection * pCON,
void * threadData){
261 CHECK_MINUS_ONE(result,
"T3-2: NoCommit", pCON);
263 Uint32 permission = td->transactionData.permission;
264 Uint32 sessions = td->transactionData.sessions;
265 Uint32 server_bit = td->transactionData.server_bit;
267 if(((permission & server_bit) == server_bit) &&
268 ((sessions & server_bit) == server_bit)){
270 memcpy(td->transactionData.suffix,
271 &td->transactionData.number
272 [SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH],
273 SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
274 DEBUG5(
"T3(%.*s, %.2d): - Callback 2 - reading(%.*s)\n",
275 SUBSCRIBER_NUMBER_LENGTH,
276 td->transactionData.number,
277 td->transactionData.server_id,
278 SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
279 td->transactionData.suffix);
283 CHECK_NULL(MyOp,
"T3-3: getNdbOperation",
287 MyOp->
equal(IND_SESSION_SUBSCRIBER,
288 (
char*)td->transactionData.number);
289 MyOp->
equal(IND_SESSION_SERVER,
290 (
char*)&td->transactionData.server_id);
292 (
char *)td->transactionData.session_details);
296 CHECK_NULL(MyOp,
"T3-4: getNdbOperation",
300 MyOp->
equal(IND_SERVER_ID,
301 (
char*)&td->transactionData.server_id);
302 MyOp->
equal(IND_SERVER_SUBSCRIBER_SUFFIX,
303 (
char*)td->transactionData.suffix);
304 MyOp->
incValue(IND_SERVER_READS, (uint32)1);
305 td->transactionData.branchExecuted = 1;
307 DEBUG3(
"T3(%.*s, %.2d): - Callback 2 - no read\n",
308 SUBSCRIBER_NUMBER_LENGTH,
309 td->transactionData.number,
310 td->transactionData.server_id);
311 td->transactionData.branchExecuted = 0;
317 T3_Callback_3(
int result,
NdbConnection * pCON,
void * threadData){
319 DEBUG3(
"T3(%.*s, %.2d): - Completing\n", SUBSCRIBER_NUMBER_LENGTH,
320 td->transactionData.number,
321 td->transactionData.server_id);
323 CHECK_MINUS_ONE(result,
"T3-3: Commit", pCON);
349 DEBUG3(
"T4(%.*s, %.2d): - Starting\n", SUBSCRIBER_NUMBER_LENGTH,
350 td->transactionData.number,
351 td->transactionData.server_id);
357 td->transactionData.server_id,
358 td->transactionData.number);
360 error_handler(
"T4-1: startTranscation",
361 pNDB->getNdbErrorString(),
365 CHECK_NULL(MyOp,
"T4-1: getNdbOperation",
368 MyOp->interpretedUpdateTuple();
369 MyOp->equal(IND_SUBSCRIBER_NUMBER,
370 td->transactionData.number);
371 MyOp->getValue(IND_SUBSCRIBER_LOCATION,
372 (
char *)&td->transactionData.location);
373 MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
374 td->transactionData.changed_by);
375 MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
376 td->transactionData.changed_time);
377 MyOp->getValue(IND_SUBSCRIBER_GROUP,
378 (
char *)&td->transactionData.group_id);
379 MyOp->getValue(IND_SUBSCRIBER_SESSIONS,
380 (
char *)&td->transactionData.sessions);
381 MyOp->incValue(IND_SUBSCRIBER_SESSIONS,
382 (uint32)td->transactionData.server_bit);
387 T4_Callback_1(
int result,
NdbConnection * pCON,
void * threadData){
388 CHECK_MINUS_ONE(result,
"T4-1: NoCommit", pCON);
391 DEBUG3(
"T4(%.*s, %.2d): - Callback 1\n",
392 SUBSCRIBER_NUMBER_LENGTH,
393 td->transactionData.number,
394 td->transactionData.server_id);
398 CHECK_NULL(MyOp,
"T4-2: getNdbOperation",
402 MyOp->
equal(IND_GROUP_ID,
403 (
char*)&td->transactionData.group_id);
404 MyOp->
getValue(IND_GROUP_ALLOW_INSERT,
405 (
char *)&td->transactionData.permission);
410 T4_Callback_2(
int result,
NdbConnection * pCON,
void * threadData){
411 CHECK_MINUS_ONE(result,
"T4-2: NoCommit", pCON);
414 Uint32 permission = td->transactionData.permission;
415 Uint32 sessions = td->transactionData.sessions;
416 Uint32 server_bit = td->transactionData.server_bit;
418 if(((permission & server_bit) == server_bit) &&
419 ((sessions & server_bit) == 0)){
421 memcpy(td->transactionData.suffix,
422 &td->transactionData.number
423 [SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH],
424 SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
426 DEBUG5(
"T4(%.*s, %.2d): - Callback 2 - inserting(%.*s)\n",
427 SUBSCRIBER_NUMBER_LENGTH,
428 td->transactionData.number,
429 td->transactionData.server_id,
430 SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
431 td->transactionData.suffix);
436 CHECK_NULL(MyOp,
"T4-3: getNdbOperation",
440 MyOp->
equal(IND_SESSION_SUBSCRIBER,
441 (
char*)td->transactionData.number);
442 MyOp->
equal(IND_SESSION_SERVER,
443 (
char*)&td->transactionData.server_id);
445 (
char *)td->transactionData.session_details);
450 CHECK_NULL(MyOp,
"T4-5: getNdbOperation",
454 MyOp->
equal(IND_SERVER_ID,
455 (
char*)&td->transactionData.server_id);
456 MyOp->
equal(IND_SERVER_SUBSCRIBER_SUFFIX,
457 (
char*)td->transactionData.suffix);
458 MyOp->
incValue(IND_SERVER_INSERTS, (uint32)1);
459 td->transactionData.branchExecuted = 1;
461 td->transactionData.branchExecuted = 0;
462 DEBUG5(
"T4(%.*s, %.2d): - Callback 2 - %s %s\n",
463 SUBSCRIBER_NUMBER_LENGTH,
464 td->transactionData.number,
465 td->transactionData.server_id,
466 ((permission & server_bit) ?
467 "permission - " :
"no permission - "),
468 ((sessions & server_bit) ?
469 "in session - " :
"no in session - "));
472 if(!td->transactionData.do_rollback && td->transactionData.branchExecuted){
480 T4_Callback_3(
int result,
NdbConnection * pCON,
void * threadData){
481 CHECK_MINUS_ONE(result,
"T4-3: Commit", pCON);
484 DEBUG3(
"T4(%.*s, %.2d): - Completing\n",
485 SUBSCRIBER_NUMBER_LENGTH,
486 td->transactionData.number,
487 td->transactionData.server_id);
512 DEBUG3(
"T5(%.*s, %.2d): - Starting\n", SUBSCRIBER_NUMBER_LENGTH,
513 td->transactionData.number,
514 td->transactionData.server_id);
521 error_handler(
"T5-1: startTranscation",
522 pNDB->getNdbErrorString(),
526 CHECK_NULL(MyOp,
"T5-1: getNdbOperation",
529 MyOp->interpretedUpdateTuple();
530 MyOp->equal(IND_SUBSCRIBER_NUMBER,
531 td->transactionData.number);
532 MyOp->getValue(IND_SUBSCRIBER_LOCATION,
533 (
char *)&td->transactionData.location);
534 MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
535 td->transactionData.changed_by);
536 MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
537 td->transactionData.changed_time);
538 MyOp->getValue(IND_SUBSCRIBER_GROUP,
539 (
char *)&td->transactionData.group_id);
540 MyOp->getValue(IND_SUBSCRIBER_SESSIONS,
541 (
char *)&td->transactionData.sessions);
542 MyOp->subValue(IND_SUBSCRIBER_SESSIONS,
543 (uint32)td->transactionData.server_bit);
548 T5_Callback_1(
int result,
NdbConnection * pCON,
void * threadData){
549 CHECK_MINUS_ONE(result,
"T5-1: NoCommit", pCON);
552 DEBUG3(
"T5(%.*s, %.2d): - Callback 1\n",
553 SUBSCRIBER_NUMBER_LENGTH,
554 td->transactionData.number,
555 td->transactionData.server_id);
558 CHECK_NULL(MyOp,
"T5-2: getNdbOperation",
562 MyOp->
equal(IND_GROUP_ID,
563 (
char*)&td->transactionData.group_id);
564 MyOp->
getValue(IND_GROUP_ALLOW_DELETE,
565 (
char *)&td->transactionData.permission);
570 T5_Callback_2(
int result,
NdbConnection * pCON,
void * threadData){
571 CHECK_MINUS_ONE(result,
"T5-2: NoCommit", pCON);
574 Uint32 permission = td->transactionData.permission;
575 Uint32 sessions = td->transactionData.sessions;
576 Uint32 server_bit = td->transactionData.server_bit;
578 if(((permission & server_bit) == server_bit) &&
579 ((sessions & server_bit) == server_bit)){
581 memcpy(td->transactionData.suffix,
582 &td->transactionData.number
583 [SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH],
584 SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
586 DEBUG5(
"T5(%.*s, %.2d): - Callback 2 - deleting(%.*s)\n",
587 SUBSCRIBER_NUMBER_LENGTH,
588 td->transactionData.number,
589 td->transactionData.server_id,
590 SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
591 td->transactionData.suffix);
595 CHECK_NULL(MyOp,
"T5-3: getNdbOperation",
599 MyOp->
equal(IND_SESSION_SUBSCRIBER,
600 (
char*)td->transactionData.number);
601 MyOp->
equal(IND_SESSION_SERVER,
602 (
char*)&td->transactionData.server_id);
607 CHECK_NULL(MyOp,
"T5-5: getNdbOperation",
611 MyOp->
equal(IND_SERVER_ID,
612 (
char*)&td->transactionData.server_id);
613 MyOp->
equal(IND_SERVER_SUBSCRIBER_SUFFIX,
614 (
char*)td->transactionData.suffix);
615 MyOp->
incValue(IND_SERVER_DELETES, (uint32)1);
616 td->transactionData.branchExecuted = 1;
618 td->transactionData.branchExecuted = 0;
620 DEBUG5(
"T5(%.*s, %.2d): - Callback 2 - no delete - %s %s\n",
621 SUBSCRIBER_NUMBER_LENGTH,
622 td->transactionData.number,
623 td->transactionData.server_id,
624 ((permission & server_bit) ?
625 "permission - " :
"no permission - "),
626 ((sessions & server_bit) ?
627 "in session - " :
"no in session - "));
630 if(!td->transactionData.do_rollback && td->transactionData.branchExecuted){
638 T5_Callback_3(
int result,
NdbConnection * pCON,
void * threadData){
639 CHECK_MINUS_ONE(result,
"T5-3: Commit", pCON);
642 DEBUG3(
"T5(%.*s, %.2d): - Completing\n",
643 SUBSCRIBER_NUMBER_LENGTH,
644 td->transactionData.number,
645 td->transactionData.server_id);