2
Copyright (C) 2003-2006 MySQL AB
3
All rights reserved. Use is subject to license terms.
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include "user_transaction.h"
26
#include "ndb_schema.hpp"
27
#include "ndb_error.hpp"
35
* Update location and changed by/time on a subscriber
47
const SubscriberNumber number,
48
const Location new_location,
49
const ChangedBy changed_by,
50
const ChangedTime changed_time,
51
BenchmarkTime * transaction_time){
53
Ndb * pNDB = (Ndb *) obj;
61
NdbConnection * MyTransaction = pNDB->startTransaction();
62
if (MyTransaction == NULL)
63
error_handler("T1: startTranscation", pNDB->getNdbErrorString(), 0);
65
NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
66
CHECK_NULL(MyOperation, "T1: getNdbOperation", MyTransaction);
68
check = MyOperation->updateTuple();
69
CHECK_MINUS_ONE(check, "T1: updateTuple",
72
check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
74
CHECK_MINUS_ONE(check, "T1: equal subscriber",
77
check = MyOperation->setValue(IND_SUBSCRIBER_LOCATION,
78
(char *)&new_location);
79
CHECK_MINUS_ONE(check, "T1: setValue location",
82
check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_BY,
84
CHECK_MINUS_ONE(check, "T1: setValue changed_by",
87
check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_TIME,
89
CHECK_MINUS_ONE(check, "T1: setValue changed_time",
92
check = MyTransaction->execute( Commit );
93
CHECK_MINUS_ONE(check, "T1: Commit",
96
pNDB->closeTransaction(MyTransaction);
98
get_time(transaction_time);
99
time_diff(transaction_time, &start);
106
* Read from Subscriber:
119
const SubscriberNumber number,
120
Location * readLocation,
121
ChangedBy changed_by,
122
ChangedTime changed_time,
123
SubscriberName subscriberName,
124
BenchmarkTime * transaction_time){
126
Ndb * pNDB = (Ndb *) obj;
134
NdbConnection * MyTransaction = pNDB->startTransaction();
135
if (MyTransaction == NULL)
136
error_handler("T2: startTranscation", pNDB->getNdbErrorString(), 0);
138
NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
139
CHECK_NULL(MyOperation, "T2: getNdbOperation",
143
check = MyOperation->readTuple();
144
CHECK_MINUS_ONE(check, "T2: readTuple",
147
check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
149
CHECK_MINUS_ONE(check, "T2: equal subscriber",
152
check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
153
(char *)readLocation);
154
CHECK_NULL(check2, "T2: getValue location",
157
check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
159
CHECK_NULL(check2, "T2: getValue changed_by",
162
check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
164
CHECK_NULL(check2, "T2: getValue changed_time",
167
check2 = MyOperation->getValue(IND_SUBSCRIBER_NAME,
169
CHECK_NULL(check2, "T2: getValue name",
172
check = MyTransaction->execute( Commit );
173
CHECK_MINUS_ONE(check, "T2: Commit",
176
pNDB->closeTransaction(MyTransaction);
178
get_time(transaction_time);
179
time_diff(transaction_time, &start);
186
* Read session details
202
const SubscriberNumber inNumber,
203
const SubscriberSuffix inSuffix,
204
const ServerId inServerId,
205
const ServerBit inServerBit,
206
SessionDetails outSessionDetails,
207
ChangedBy outChangedBy,
208
ChangedTime outChangedTime,
209
Location * outLocation,
210
BranchExecuted * outBranchExecuted,
211
BenchmarkTime * outTransactionTime){
213
Ndb * pNDB = (Ndb *) obj;
216
ActiveSessions sessions;
217
Permission permission;
225
NdbConnection * MyTransaction = pNDB->startTransaction();
226
if (MyTransaction == NULL)
227
error_handler("T3-1: startTranscation", pNDB->getNdbErrorString(), 0);
229
NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
230
CHECK_NULL(MyOperation, "T3-1: getNdbOperation",
234
check = MyOperation->readTuple();
235
CHECK_MINUS_ONE(check, "T3-1: readTuple",
238
check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
240
CHECK_MINUS_ONE(check, "T3-1: equal subscriber",
243
check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
244
(char *)outLocation);
245
CHECK_NULL(check2, "T3-1: getValue location",
248
check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
250
CHECK_NULL(check2, "T3-1: getValue changed_by",
253
check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
255
CHECK_NULL(check2, "T3-1: getValue changed_time",
258
check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
260
CHECK_NULL(check2, "T3-1: getValue group",
263
check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
265
CHECK_NULL(check2, "T3-1: getValue sessions",
268
check = MyTransaction->execute( NoCommit );
269
CHECK_MINUS_ONE(check, "T3-1: NoCommit",
274
MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
275
CHECK_NULL(MyOperation, "T3-2: getNdbOperation",
279
check = MyOperation->readTuple();
280
CHECK_MINUS_ONE(check, "T3-2: readTuple",
283
check = MyOperation->equal(IND_GROUP_ID,
285
CHECK_MINUS_ONE(check, "T3-2: equal group",
288
check2 = MyOperation->getValue(IND_GROUP_ALLOW_READ,
289
(char *)&permission);
290
CHECK_NULL(check2, "T3-2: getValue allow_read",
293
check = MyTransaction->execute( NoCommit );
294
CHECK_MINUS_ONE(check, "T3-2: NoCommit",
297
DEBUG3("T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
299
if(((permission & inServerBit) == inServerBit) &&
300
((sessions & inServerBit) == inServerBit)){
306
MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
307
CHECK_NULL(MyOperation, "T3-3: getNdbOperation",
310
check = MyOperation->readTuple();
311
CHECK_MINUS_ONE(check, "T3-3: readTuple",
314
check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
316
CHECK_MINUS_ONE(check, "T3-3: equal number",
319
check = MyOperation->equal(IND_SESSION_SERVER,
321
CHECK_MINUS_ONE(check, "T3-3: equal server id",
324
check2 = MyOperation->getValue(IND_SESSION_DATA,
325
(char *)outSessionDetails);
326
CHECK_NULL(check2, "T3-3: getValue session details",
331
MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
332
CHECK_NULL(MyOperation, "T3-4: getNdbOperation",
335
check = MyOperation->interpretedUpdateTuple();
336
CHECK_MINUS_ONE(check, "T3-4: interpretedUpdateTuple",
339
check = MyOperation->equal(IND_SERVER_ID,
341
CHECK_MINUS_ONE(check, "T3-4: equal serverId",
344
check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
346
CHECK_MINUS_ONE(check, "T3-4: equal suffix",
349
check = MyOperation->incValue(IND_SERVER_READS, (uint32)1);
350
CHECK_MINUS_ONE(check, "T3-4: inc value",
353
(* outBranchExecuted) = 1;
355
(* outBranchExecuted) = 0;
358
check = MyTransaction->execute( Commit );
359
CHECK_MINUS_ONE(check, "T3: Commit",
362
pNDB->closeTransaction(MyTransaction);
364
get_time(outTransactionTime);
365
time_diff(outTransactionTime, &start);
389
const SubscriberNumber inNumber,
390
const SubscriberSuffix inSuffix,
391
const ServerId inServerId,
392
const ServerBit inServerBit,
393
const SessionDetails inSessionDetails,
394
ChangedBy outChangedBy,
395
ChangedTime outChangedTime,
396
Location * outLocation,
397
DoRollback inDoRollback,
398
BranchExecuted * outBranchExecuted,
399
BenchmarkTime * outTransactionTime){
401
Ndb * pNDB = (Ndb *) obj;
404
ActiveSessions sessions;
405
Permission permission;
413
NdbConnection * MyTransaction = pNDB->startTransaction();
414
if (MyTransaction == NULL)
415
error_handler("T4-1: startTranscation", pNDB->getNdbErrorString(), 0);
417
DEBUG3("T4(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
419
NdbOperation * MyOperation = 0;
421
MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
422
CHECK_NULL(MyOperation, "T4-1: getNdbOperation",
425
check = MyOperation->readTupleExclusive();
426
CHECK_MINUS_ONE(check, "T4-1: readTuple",
429
check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
431
CHECK_MINUS_ONE(check, "T4-1: equal subscriber",
434
check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
435
(char *)outLocation);
436
CHECK_NULL(check2, "T4-1: getValue location",
439
check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
441
CHECK_NULL(check2, "T4-1: getValue changed_by",
444
check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
446
CHECK_NULL(check2, "T4-1: getValue changed_time",
449
check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
451
CHECK_NULL(check2, "T4-1: getValue group",
454
check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
456
CHECK_NULL(check2, "T4-1: getValue sessions",
459
check = MyTransaction->execute( NoCommit );
460
CHECK_MINUS_ONE(check, "T4-1: NoCommit",
464
MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
465
CHECK_NULL(MyOperation, "T4-2: getNdbOperation",
468
check = MyOperation->readTuple();
469
CHECK_MINUS_ONE(check, "T4-2: readTuple",
472
check = MyOperation->equal(IND_GROUP_ID,
474
CHECK_MINUS_ONE(check, "T4-2: equal group",
477
check2 = MyOperation->getValue(IND_GROUP_ALLOW_INSERT,
478
(char *)&permission);
479
CHECK_NULL(check2, "T4-2: getValue allow_insert",
482
check = MyTransaction->execute( NoCommit );
483
CHECK_MINUS_ONE(check, "T4-2: NoCommit",
486
if(((permission & inServerBit) == inServerBit) &&
487
((sessions & inServerBit) == 0)){
489
DEBUG("inserting - ");
492
MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
493
CHECK_NULL(MyOperation, "T4-3: getNdbOperation",
496
check = MyOperation->insertTuple();
497
CHECK_MINUS_ONE(check, "T4-3: insertTuple",
500
check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
502
CHECK_MINUS_ONE(check, "T4-3: equal number",
505
check = MyOperation->equal(IND_SESSION_SERVER,
507
CHECK_MINUS_ONE(check, "T4-3: equal server id",
510
check = MyOperation->setValue(SESSION_DATA,
511
(char *)inSessionDetails);
512
CHECK_MINUS_ONE(check, "T4-3: setValue session details",
516
MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
517
CHECK_NULL(MyOperation, "T4-4: getNdbOperation",
520
check = MyOperation->interpretedUpdateTuple();
521
CHECK_MINUS_ONE(check, "T4-4: interpretedUpdateTuple",
524
check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
526
CHECK_MINUS_ONE(check, "T4-4: equal number",
529
check = MyOperation->incValue(IND_SUBSCRIBER_SESSIONS,
530
(uint32)inServerBit);
531
CHECK_MINUS_ONE(check, "T4-4: inc value",
535
MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
536
CHECK_NULL(MyOperation, "T4-5: getNdbOperation",
539
check = MyOperation->interpretedUpdateTuple();
540
CHECK_MINUS_ONE(check, "T4-5: interpretedUpdateTuple",
543
check = MyOperation->equal(IND_SERVER_ID,
545
CHECK_MINUS_ONE(check, "T4-5: equal serverId",
548
check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
550
CHECK_MINUS_ONE(check, "T4-5: equal suffix",
553
check = MyOperation->incValue(IND_SERVER_INSERTS, (uint32)1);
554
CHECK_MINUS_ONE(check, "T4-5: inc value",
557
(* outBranchExecuted) = 1;
559
DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
560
DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
561
(* outBranchExecuted) = 0;
566
check = MyTransaction->execute( Commit );
567
CHECK_MINUS_ONE(check, "T4: Commit",
571
check = MyTransaction->execute(Rollback);
572
CHECK_MINUS_ONE(check, "T4:Rollback",
577
pNDB->closeTransaction(MyTransaction);
579
get_time(outTransactionTime);
580
time_diff(outTransactionTime, &start);
603
const SubscriberNumber inNumber,
604
const SubscriberSuffix inSuffix,
605
const ServerId inServerId,
606
const ServerBit inServerBit,
607
ChangedBy outChangedBy,
608
ChangedTime outChangedTime,
609
Location * outLocation,
610
DoRollback inDoRollback,
611
BranchExecuted * outBranchExecuted,
612
BenchmarkTime * outTransactionTime){
614
Ndb * pNDB = (Ndb *) obj;
615
NdbConnection * MyTransaction = 0;
616
NdbOperation * MyOperation = 0;
619
ActiveSessions sessions;
620
Permission permission;
628
MyTransaction = pNDB->startTransaction();
629
if (MyTransaction == NULL)
630
error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), 0);
632
MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
633
CHECK_NULL(MyOperation, "T5-1: getNdbOperation",
637
check = MyOperation->readTupleExclusive();
638
CHECK_MINUS_ONE(check, "T5-1: readTuple",
641
check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
643
CHECK_MINUS_ONE(check, "T5-1: equal subscriber",
646
check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
647
(char *)outLocation);
648
CHECK_NULL(check2, "T5-1: getValue location",
651
check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
653
CHECK_NULL(check2, "T5-1: getValue changed_by",
656
check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
658
CHECK_NULL(check2, "T5-1: getValue changed_time",
661
check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
663
CHECK_NULL(check2, "T5-1: getValue group",
666
check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
668
CHECK_NULL(check2, "T5-1: getValue sessions",
671
check = MyTransaction->execute( NoCommit );
672
CHECK_MINUS_ONE(check, "T5-1: NoCommit",
677
MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
678
CHECK_NULL(MyOperation, "T5-2: getNdbOperation",
682
check = MyOperation->readTuple();
683
CHECK_MINUS_ONE(check, "T5-2: readTuple",
686
check = MyOperation->equal(IND_GROUP_ID,
688
CHECK_MINUS_ONE(check, "T5-2: equal group",
691
check2 = MyOperation->getValue(IND_GROUP_ALLOW_DELETE,
692
(char *)&permission);
693
CHECK_NULL(check2, "T5-2: getValue allow_delete",
696
check = MyTransaction->execute( NoCommit );
697
CHECK_MINUS_ONE(check, "T5-2: NoCommit",
700
DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
702
if(((permission & inServerBit) == inServerBit) &&
703
((sessions & inServerBit) == inServerBit)){
705
DEBUG("deleting - ");
708
MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
709
CHECK_NULL(MyOperation, "T5-3: getNdbOperation",
712
check = MyOperation->deleteTuple();
713
CHECK_MINUS_ONE(check, "T5-3: deleteTuple",
716
check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
718
CHECK_MINUS_ONE(check, "T5-3: equal number",
721
check = MyOperation->equal(IND_SESSION_SERVER,
723
CHECK_MINUS_ONE(check, "T5-3: equal server id",
727
MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
728
CHECK_NULL(MyOperation, "T5-4: getNdbOperation",
731
check = MyOperation->interpretedUpdateTuple();
732
CHECK_MINUS_ONE(check, "T5-4: interpretedUpdateTuple",
735
check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
737
CHECK_MINUS_ONE(check, "T5-4: equal number",
740
check = MyOperation->subValue(IND_SUBSCRIBER_SESSIONS,
741
(uint32)inServerBit);
742
CHECK_MINUS_ONE(check, "T5-4: dec value",
746
MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
747
CHECK_NULL(MyOperation, "T5-5: getNdbOperation",
751
check = MyOperation->interpretedUpdateTuple();
752
CHECK_MINUS_ONE(check, "T5-5: interpretedUpdateTuple",
755
check = MyOperation->equal(IND_SERVER_ID,
757
CHECK_MINUS_ONE(check, "T5-5: equal serverId",
760
check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
762
CHECK_MINUS_ONE(check, "T5-5: equal suffix",
765
check = MyOperation->incValue(IND_SERVER_DELETES, (uint32)1);
766
CHECK_MINUS_ONE(check, "T5-5: inc value",
769
(* outBranchExecuted) = 1;
771
DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
772
DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
773
(* outBranchExecuted) = 0;
778
check = MyTransaction->execute( Commit );
779
CHECK_MINUS_ONE(check, "T5: Commit",
783
check = MyTransaction->execute(Rollback);
784
CHECK_MINUS_ONE(check, "T5:Rollback",
789
pNDB->closeTransaction(MyTransaction);
791
get_time(outTransactionTime);
792
time_diff(outTransactionTime, &start);