~ubuntu-branches/ubuntu/trusty/mysql-5.6/trusty

« back to all changes in this revision

Viewing changes to storage/ndb/test/ndbapi/ndb_user_transaction3.cpp

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-12 11:54:27 UTC
  • Revision ID: package-import@ubuntu.com-20140212115427-oq6tfsqxl1wuwehi
Tags: upstream-5.6.15
ImportĀ upstreamĀ versionĀ 5.6.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2003-2006 MySQL AB
 
3
    All rights reserved. Use is subject to license terms.
 
4
 
 
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.
 
8
 
 
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.
 
13
 
 
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
 
17
*/
 
18
 
 
19
//#define DEBUG_ON
 
20
 
 
21
extern "C" {
 
22
#include "user_transaction.h"
 
23
};
 
24
 
 
25
#include "macros.h"
 
26
#include "ndb_schema.hpp"
 
27
#include "ndb_error.hpp"
 
28
 
 
29
#include <time.h>
 
30
#include <NdbApi.hpp>
 
31
 
 
32
/**
 
33
 * Transaction 1 - T1 
 
34
 *
 
35
 * Update location and changed by/time on a subscriber
 
36
 *
 
37
 * Input: 
 
38
 *   SubscriberNumber,
 
39
 *   Location,
 
40
 *   ChangedBy,
 
41
 *   ChangedTime
 
42
 *
 
43
 * Output:
 
44
 */
 
45
int
 
46
T1(void * obj,
 
47
   const SubscriberNumber number, 
 
48
   const Location new_location, 
 
49
   const ChangedBy changed_by, 
 
50
   const ChangedTime changed_time,
 
51
   BenchmarkTime * transaction_time){
 
52
 
 
53
  Ndb * pNDB = (Ndb *) obj;
 
54
 
 
55
  BenchmarkTime start;
 
56
  get_time(&start);
 
57
 
 
58
  int check;
 
59
  NdbRecAttr * check2;
 
60
 
 
61
  NdbConnection * MyTransaction = pNDB->startTransaction();
 
62
  if (MyTransaction == NULL)      
 
63
    error_handler("T1: startTranscation", pNDB->getNdbErrorString(), 0);
 
64
  
 
65
  NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
 
66
  CHECK_NULL(MyOperation, "T1: getNdbOperation", MyTransaction);
 
67
  
 
68
  check = MyOperation->updateTuple();
 
69
  CHECK_MINUS_ONE(check, "T1: updateTuple", 
 
70
                  MyTransaction);
 
71
  
 
72
  check = MyOperation->equal(IND_SUBSCRIBER_NUMBER, 
 
73
                             number);
 
74
  CHECK_MINUS_ONE(check, "T1: equal subscriber",
 
75
                  MyTransaction);
 
76
 
 
77
  check = MyOperation->setValue(IND_SUBSCRIBER_LOCATION, 
 
78
                                (char *)&new_location);
 
79
  CHECK_MINUS_ONE(check, "T1: setValue location", 
 
80
                  MyTransaction);
 
81
 
 
82
  check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_BY, 
 
83
                                changed_by);
 
84
  CHECK_MINUS_ONE(check, "T1: setValue changed_by", 
 
85
                  MyTransaction);
 
86
 
 
87
  check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_TIME, 
 
88
                                changed_time);
 
89
  CHECK_MINUS_ONE(check, "T1: setValue changed_time", 
 
90
                  MyTransaction);
 
91
 
 
92
  check = MyTransaction->execute( Commit ); 
 
93
  CHECK_MINUS_ONE(check, "T1: Commit", 
 
94
                  MyTransaction);
 
95
  
 
96
  pNDB->closeTransaction(MyTransaction);
 
97
  
 
98
  get_time(transaction_time);
 
99
  time_diff(transaction_time, &start);
 
100
  return 0;
 
101
}
 
102
 
 
103
/**
 
104
 * Transaction 2 - T2
 
105
 *
 
106
 * Read from Subscriber:
 
107
 *
 
108
 * Input: 
 
109
 *   SubscriberNumber
 
110
 *
 
111
 * Output:
 
112
 *   Location
 
113
 *   Changed by
 
114
 *   Changed Timestamp
 
115
 *   Name
 
116
 */
 
117
int
 
118
T2(void * obj,
 
119
   const SubscriberNumber number, 
 
120
   Location * readLocation, 
 
121
   ChangedBy changed_by, 
 
122
   ChangedTime changed_time,
 
123
   SubscriberName subscriberName,
 
124
   BenchmarkTime * transaction_time){
 
125
 
 
126
  Ndb * pNDB = (Ndb *) obj;
 
127
 
 
128
  BenchmarkTime start;
 
129
  get_time(&start);
 
130
 
 
131
  int check;
 
132
  NdbRecAttr * check2;
 
133
 
 
134
  NdbConnection * MyTransaction = pNDB->startTransaction();
 
135
  if (MyTransaction == NULL)      
 
136
    error_handler("T2: startTranscation", pNDB->getNdbErrorString(), 0);
 
137
  
 
138
  NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
 
139
  CHECK_NULL(MyOperation, "T2: getNdbOperation", 
 
140
             MyTransaction);
 
141
  
 
142
  
 
143
  check = MyOperation->readTuple();
 
144
  CHECK_MINUS_ONE(check, "T2: readTuple", 
 
145
                  MyTransaction);
 
146
  
 
147
  check = MyOperation->equal(IND_SUBSCRIBER_NUMBER, 
 
148
                             number);
 
149
  CHECK_MINUS_ONE(check, "T2: equal subscriber",
 
150
                  MyTransaction);
 
151
 
 
152
  check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION, 
 
153
                                (char *)readLocation);
 
154
  CHECK_NULL(check2, "T2: getValue location", 
 
155
             MyTransaction);
 
156
 
 
157
  check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY, 
 
158
                                 changed_by);
 
159
  CHECK_NULL(check2, "T2: getValue changed_by", 
 
160
             MyTransaction);
 
161
 
 
162
  check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME, 
 
163
                                 changed_time);
 
164
  CHECK_NULL(check2, "T2: getValue changed_time",
 
165
             MyTransaction);
 
166
 
 
167
  check2 = MyOperation->getValue(IND_SUBSCRIBER_NAME, 
 
168
                                subscriberName);
 
169
  CHECK_NULL(check2, "T2: getValue name", 
 
170
             MyTransaction);
 
171
 
 
172
  check = MyTransaction->execute( Commit ); 
 
173
  CHECK_MINUS_ONE(check, "T2: Commit", 
 
174
                  MyTransaction);
 
175
  
 
176
  pNDB->closeTransaction(MyTransaction);
 
177
  
 
178
  get_time(transaction_time);
 
179
  time_diff(transaction_time, &start);
 
180
  return 0;
 
181
}
 
182
 
 
183
/**
 
184
 * Transaction 3 - T3
 
185
 *
 
186
 * Read session details
 
187
 *
 
188
 * Input:
 
189
 *   SubscriberNumber
 
190
 *   ServerId
 
191
 *   ServerBit
 
192
 *
 
193
 * Output:
 
194
 *   BranchExecuted
 
195
 *   SessionDetails
 
196
 *   ChangedBy
 
197
 *   ChangedTime
 
198
 *   Location
 
199
 */
 
200
int
 
201
T3(void * obj,
 
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){
 
212
  
 
213
  Ndb * pNDB = (Ndb *) obj;
 
214
 
 
215
  GroupId        groupId;
 
216
  ActiveSessions sessions;
 
217
  Permission     permission;
 
218
 
 
219
  BenchmarkTime start;
 
220
  get_time(&start);
 
221
 
 
222
  int check;
 
223
  NdbRecAttr * check2;
 
224
 
 
225
  NdbConnection * MyTransaction = pNDB->startTransaction();
 
226
  if (MyTransaction == NULL)      
 
227
    error_handler("T3-1: startTranscation", pNDB->getNdbErrorString(), 0);
 
228
  
 
229
  NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
 
230
  CHECK_NULL(MyOperation, "T3-1: getNdbOperation", 
 
231
             MyTransaction);
 
232
  
 
233
  
 
234
  check = MyOperation->readTuple();
 
235
  CHECK_MINUS_ONE(check, "T3-1: readTuple", 
 
236
                  MyTransaction);
 
237
  
 
238
  check = MyOperation->equal(IND_SUBSCRIBER_NUMBER, 
 
239
                             inNumber);
 
240
  CHECK_MINUS_ONE(check, "T3-1: equal subscriber",
 
241
                  MyTransaction);
 
242
 
 
243
  check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION, 
 
244
                                 (char *)outLocation);
 
245
  CHECK_NULL(check2, "T3-1: getValue location", 
 
246
             MyTransaction);
 
247
 
 
248
  check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY, 
 
249
                                 outChangedBy);
 
250
  CHECK_NULL(check2, "T3-1: getValue changed_by", 
 
251
             MyTransaction);
 
252
 
 
253
  check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME, 
 
254
                                 outChangedTime);
 
255
  CHECK_NULL(check2, "T3-1: getValue changed_time",
 
256
             MyTransaction);
 
257
 
 
258
  check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
 
259
                                 (char *)&groupId);
 
260
  CHECK_NULL(check2, "T3-1: getValue group", 
 
261
             MyTransaction);
 
262
 
 
263
  check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
 
264
                                 (char *)&sessions);
 
265
  CHECK_NULL(check2, "T3-1: getValue sessions", 
 
266
             MyTransaction);
 
267
  
 
268
  check = MyTransaction->execute( NoCommit ); 
 
269
  CHECK_MINUS_ONE(check, "T3-1: NoCommit", 
 
270
                  MyTransaction);
 
271
  
 
272
    /* Operation 2 */
 
273
 
 
274
  MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
 
275
  CHECK_NULL(MyOperation, "T3-2: getNdbOperation", 
 
276
             MyTransaction);
 
277
  
 
278
  
 
279
  check = MyOperation->readTuple();
 
280
  CHECK_MINUS_ONE(check, "T3-2: readTuple", 
 
281
                  MyTransaction);
 
282
  
 
283
  check = MyOperation->equal(IND_GROUP_ID,
 
284
                     (char*)&groupId);
 
285
  CHECK_MINUS_ONE(check, "T3-2: equal group",
 
286
                  MyTransaction);
 
287
  
 
288
  check2 = MyOperation->getValue(IND_GROUP_ALLOW_READ, 
 
289
                                 (char *)&permission);
 
290
  CHECK_NULL(check2, "T3-2: getValue allow_read", 
 
291
             MyTransaction);
 
292
 
 
293
  check = MyTransaction->execute( NoCommit ); 
 
294
  CHECK_MINUS_ONE(check, "T3-2: NoCommit", 
 
295
                  MyTransaction);
 
296
  
 
297
  DEBUG3("T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
 
298
 
 
299
  if(((permission & inServerBit) == inServerBit) &&
 
300
     ((sessions   & inServerBit) == inServerBit)){
 
301
    
 
302
    DEBUG("reading - ");
 
303
 
 
304
    /* Operation 3 */
 
305
 
 
306
    MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
 
307
    CHECK_NULL(MyOperation, "T3-3: getNdbOperation", 
 
308
               MyTransaction);
 
309
    
 
310
    check = MyOperation->readTuple();
 
311
    CHECK_MINUS_ONE(check, "T3-3: readTuple", 
 
312
                    MyTransaction);
 
313
    
 
314
    check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
 
315
                               (char*)inNumber);
 
316
    CHECK_MINUS_ONE(check, "T3-3: equal number",
 
317
                    MyTransaction);
 
318
 
 
319
    check = MyOperation->equal(IND_SESSION_SERVER,
 
320
                               (char*)&inServerId);
 
321
    CHECK_MINUS_ONE(check, "T3-3: equal server id",
 
322
                    MyTransaction);
 
323
    
 
324
    check2 = MyOperation->getValue(IND_SESSION_DATA, 
 
325
                                   (char *)outSessionDetails);
 
326
    CHECK_NULL(check2, "T3-3: getValue session details", 
 
327
               MyTransaction);
 
328
    
 
329
    /* Operation 4 */
 
330
 
 
331
    MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
 
332
    CHECK_NULL(MyOperation, "T3-4: getNdbOperation", 
 
333
               MyTransaction);
 
334
    
 
335
    check = MyOperation->interpretedUpdateTuple();
 
336
    CHECK_MINUS_ONE(check, "T3-4: interpretedUpdateTuple", 
 
337
                    MyTransaction);
 
338
    
 
339
    check = MyOperation->equal(IND_SERVER_ID,
 
340
                               (char*)&inServerId);
 
341
    CHECK_MINUS_ONE(check, "T3-4: equal serverId",
 
342
                    MyTransaction);
 
343
 
 
344
    check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
 
345
                               (char*)inSuffix);
 
346
    CHECK_MINUS_ONE(check, "T3-4: equal suffix",
 
347
                    MyTransaction);
 
348
 
 
349
    check = MyOperation->incValue(IND_SERVER_READS, (uint32)1);
 
350
    CHECK_MINUS_ONE(check, "T3-4: inc value",
 
351
                    MyTransaction);
 
352
    
 
353
    (* outBranchExecuted) = 1;
 
354
  } else {
 
355
    (* outBranchExecuted) = 0;
 
356
  }
 
357
  DEBUG("commit\n");
 
358
  check = MyTransaction->execute( Commit ); 
 
359
  CHECK_MINUS_ONE(check, "T3: Commit", 
 
360
                  MyTransaction);
 
361
  
 
362
  pNDB->closeTransaction(MyTransaction);
 
363
  
 
364
  get_time(outTransactionTime);
 
365
  time_diff(outTransactionTime, &start);
 
366
  return 0;
 
367
}
 
368
 
 
369
 
 
370
/**
 
371
 * Transaction 4 - T4
 
372
 * 
 
373
 * Create session
 
374
 *
 
375
 * Input:
 
376
 *   SubscriberNumber
 
377
 *   ServerId
 
378
 *   ServerBit
 
379
 *   SessionDetails,
 
380
 *   DoRollback
 
381
 * Output:
 
382
 *   ChangedBy
 
383
 *   ChangedTime
 
384
 *   Location
 
385
 *   BranchExecuted
 
386
 */
 
387
int
 
388
T4(void * obj,
 
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){
 
400
 
 
401
  Ndb * pNDB = (Ndb *) obj;  
 
402
 
 
403
  GroupId        groupId;
 
404
  ActiveSessions sessions;
 
405
  Permission     permission;
 
406
 
 
407
  BenchmarkTime start;
 
408
  get_time(&start);
 
409
 
 
410
  int check;
 
411
  NdbRecAttr * check2;
 
412
 
 
413
  NdbConnection * MyTransaction = pNDB->startTransaction();
 
414
  if (MyTransaction == NULL)      
 
415
    error_handler("T4-1: startTranscation", pNDB->getNdbErrorString(), 0);
 
416
 
 
417
  DEBUG3("T4(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
 
418
 
 
419
  NdbOperation * MyOperation = 0;
 
420
 
 
421
  MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
 
422
  CHECK_NULL(MyOperation, "T4-1: getNdbOperation", 
 
423
             MyTransaction);
 
424
  
 
425
  check = MyOperation->readTupleExclusive();
 
426
  CHECK_MINUS_ONE(check, "T4-1: readTuple", 
 
427
                  MyTransaction);
 
428
  
 
429
  check = MyOperation->equal(IND_SUBSCRIBER_NUMBER, 
 
430
                             inNumber);
 
431
  CHECK_MINUS_ONE(check, "T4-1: equal subscriber",
 
432
                  MyTransaction);
 
433
 
 
434
  check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION, 
 
435
                                 (char *)outLocation);
 
436
  CHECK_NULL(check2, "T4-1: getValue location", 
 
437
             MyTransaction);
 
438
 
 
439
  check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY, 
 
440
                                 outChangedBy);
 
441
  CHECK_NULL(check2, "T4-1: getValue changed_by", 
 
442
             MyTransaction);
 
443
 
 
444
  check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME, 
 
445
                                 outChangedTime);
 
446
  CHECK_NULL(check2, "T4-1: getValue changed_time",
 
447
             MyTransaction);
 
448
 
 
449
  check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
 
450
                                 (char *)&groupId);
 
451
  CHECK_NULL(check2, "T4-1: getValue group", 
 
452
             MyTransaction);
 
453
 
 
454
  check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
 
455
                                 (char *)&sessions);
 
456
  CHECK_NULL(check2, "T4-1: getValue sessions", 
 
457
             MyTransaction);
 
458
  
 
459
  check = MyTransaction->execute( NoCommit ); 
 
460
  CHECK_MINUS_ONE(check, "T4-1: NoCommit", 
 
461
                  MyTransaction);
 
462
 
 
463
    /* Operation 2 */
 
464
  MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
 
465
  CHECK_NULL(MyOperation, "T4-2: getNdbOperation", 
 
466
             MyTransaction);
 
467
  
 
468
  check = MyOperation->readTuple();
 
469
  CHECK_MINUS_ONE(check, "T4-2: readTuple", 
 
470
                  MyTransaction);
 
471
  
 
472
  check = MyOperation->equal(IND_GROUP_ID,
 
473
                     (char*)&groupId);
 
474
  CHECK_MINUS_ONE(check, "T4-2: equal group",
 
475
                  MyTransaction);
 
476
  
 
477
  check2 = MyOperation->getValue(IND_GROUP_ALLOW_INSERT, 
 
478
                                 (char *)&permission);
 
479
  CHECK_NULL(check2, "T4-2: getValue allow_insert", 
 
480
             MyTransaction);
 
481
 
 
482
  check = MyTransaction->execute( NoCommit ); 
 
483
  CHECK_MINUS_ONE(check, "T4-2: NoCommit", 
 
484
                  MyTransaction);
 
485
  
 
486
  if(((permission & inServerBit) == inServerBit) &&
 
487
     ((sessions   & inServerBit) == 0)){
 
488
 
 
489
    DEBUG("inserting - ");
 
490
  
 
491
    /* Operation 3 */
 
492
    MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
 
493
    CHECK_NULL(MyOperation, "T4-3: getNdbOperation", 
 
494
               MyTransaction);
 
495
    
 
496
    check = MyOperation->insertTuple();
 
497
    CHECK_MINUS_ONE(check, "T4-3: insertTuple", 
 
498
                    MyTransaction);
 
499
    
 
500
    check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
 
501
                               (char*)inNumber);
 
502
    CHECK_MINUS_ONE(check, "T4-3: equal number",
 
503
                    MyTransaction);
 
504
 
 
505
    check = MyOperation->equal(IND_SESSION_SERVER,
 
506
                               (char*)&inServerId);
 
507
    CHECK_MINUS_ONE(check, "T4-3: equal server id",
 
508
                    MyTransaction);
 
509
    
 
510
    check = MyOperation->setValue(SESSION_DATA, 
 
511
                                   (char *)inSessionDetails);
 
512
    CHECK_MINUS_ONE(check, "T4-3: setValue session details", 
 
513
               MyTransaction);
 
514
 
 
515
    /* Operation 4 */
 
516
    MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
 
517
    CHECK_NULL(MyOperation, "T4-4: getNdbOperation", 
 
518
               MyTransaction);
 
519
    
 
520
    check = MyOperation->interpretedUpdateTuple();
 
521
    CHECK_MINUS_ONE(check, "T4-4: interpretedUpdateTuple", 
 
522
                    MyTransaction);
 
523
    
 
524
    check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
 
525
                               (char*)inNumber);
 
526
    CHECK_MINUS_ONE(check, "T4-4: equal number",
 
527
                    MyTransaction);
 
528
 
 
529
    check = MyOperation->incValue(IND_SUBSCRIBER_SESSIONS, 
 
530
                                  (uint32)inServerBit);
 
531
    CHECK_MINUS_ONE(check, "T4-4: inc value",
 
532
                    MyTransaction);
 
533
 
 
534
    /* Operation 5 */
 
535
    MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
 
536
    CHECK_NULL(MyOperation, "T4-5: getNdbOperation", 
 
537
               MyTransaction);
 
538
    
 
539
    check = MyOperation->interpretedUpdateTuple();
 
540
    CHECK_MINUS_ONE(check, "T4-5: interpretedUpdateTuple", 
 
541
                    MyTransaction);
 
542
    
 
543
    check = MyOperation->equal(IND_SERVER_ID,
 
544
                               (char*)&inServerId);
 
545
    CHECK_MINUS_ONE(check, "T4-5: equal serverId",
 
546
                    MyTransaction);
 
547
 
 
548
    check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
 
549
                               (char*)inSuffix);
 
550
    CHECK_MINUS_ONE(check, "T4-5: equal suffix",
 
551
                    MyTransaction);
 
552
 
 
553
    check = MyOperation->incValue(IND_SERVER_INSERTS, (uint32)1);
 
554
    CHECK_MINUS_ONE(check, "T4-5: inc value",
 
555
                    MyTransaction);
 
556
        
 
557
    (* outBranchExecuted) = 1;
 
558
  } else {
 
559
    DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
 
560
    DEBUG1("%s", ((sessions   & inServerBit) ? "in session - " : "no in session - "));
 
561
    (* outBranchExecuted) = 0;
 
562
  }
 
563
 
 
564
  if(!inDoRollback){
 
565
    DEBUG("commit\n");
 
566
    check = MyTransaction->execute( Commit ); 
 
567
    CHECK_MINUS_ONE(check, "T4: Commit", 
 
568
                    MyTransaction);
 
569
  } else {
 
570
    DEBUG("rollback\n");
 
571
    check = MyTransaction->execute(Rollback);
 
572
    CHECK_MINUS_ONE(check, "T4:Rollback", 
 
573
                    MyTransaction);
 
574
    
 
575
  }
 
576
  
 
577
  pNDB->closeTransaction(MyTransaction);
 
578
  
 
579
  get_time(outTransactionTime);
 
580
  time_diff(outTransactionTime, &start);
 
581
  return 0;
 
582
}
 
583
 
 
584
 
 
585
/**
 
586
 * Transaction 5 - T5
 
587
 * 
 
588
 * Delete session
 
589
 *
 
590
 * Input:
 
591
 *   SubscriberNumber
 
592
 *   ServerId
 
593
 *   ServerBit
 
594
 *   DoRollback
 
595
 * Output:
 
596
 *   ChangedBy
 
597
 *   ChangedTime
 
598
 *   Location
 
599
 *   BranchExecuted
 
600
 */
 
601
int
 
602
T5(void * obj,
 
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){
 
613
  
 
614
  Ndb           * pNDB = (Ndb *) obj;  
 
615
  NdbConnection * MyTransaction = 0;
 
616
  NdbOperation  * MyOperation = 0;
 
617
 
 
618
  GroupId        groupId;
 
619
  ActiveSessions sessions;
 
620
  Permission     permission;
 
621
 
 
622
  BenchmarkTime start;
 
623
  get_time(&start);
 
624
 
 
625
  int check;
 
626
  NdbRecAttr * check2;
 
627
 
 
628
  MyTransaction = pNDB->startTransaction();
 
629
  if (MyTransaction == NULL)      
 
630
    error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), 0);
 
631
 
 
632
  MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
 
633
  CHECK_NULL(MyOperation, "T5-1: getNdbOperation", 
 
634
             MyTransaction);
 
635
  
 
636
  
 
637
  check = MyOperation->readTupleExclusive();
 
638
  CHECK_MINUS_ONE(check, "T5-1: readTuple", 
 
639
                  MyTransaction);
 
640
  
 
641
  check = MyOperation->equal(IND_SUBSCRIBER_NUMBER, 
 
642
                             inNumber);
 
643
  CHECK_MINUS_ONE(check, "T5-1: equal subscriber",
 
644
                  MyTransaction);
 
645
 
 
646
  check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION, 
 
647
                                 (char *)outLocation);
 
648
  CHECK_NULL(check2, "T5-1: getValue location", 
 
649
             MyTransaction);
 
650
 
 
651
  check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY, 
 
652
                                 outChangedBy);
 
653
  CHECK_NULL(check2, "T5-1: getValue changed_by", 
 
654
             MyTransaction);
 
655
 
 
656
  check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME, 
 
657
                                 outChangedTime);
 
658
  CHECK_NULL(check2, "T5-1: getValue changed_time",
 
659
             MyTransaction);
 
660
 
 
661
  check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
 
662
                                 (char *)&groupId);
 
663
  CHECK_NULL(check2, "T5-1: getValue group", 
 
664
             MyTransaction);
 
665
 
 
666
  check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
 
667
                                 (char *)&sessions);
 
668
  CHECK_NULL(check2, "T5-1: getValue sessions", 
 
669
             MyTransaction);
 
670
  
 
671
  check = MyTransaction->execute( NoCommit ); 
 
672
  CHECK_MINUS_ONE(check, "T5-1: NoCommit", 
 
673
                  MyTransaction);
 
674
  
 
675
    /* Operation 2 */
 
676
 
 
677
  MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
 
678
  CHECK_NULL(MyOperation, "T5-2: getNdbOperation", 
 
679
             MyTransaction);
 
680
  
 
681
  
 
682
  check = MyOperation->readTuple();
 
683
  CHECK_MINUS_ONE(check, "T5-2: readTuple", 
 
684
                  MyTransaction);
 
685
  
 
686
  check = MyOperation->equal(IND_GROUP_ID,
 
687
                     (char*)&groupId);
 
688
  CHECK_MINUS_ONE(check, "T5-2: equal group",
 
689
                  MyTransaction);
 
690
  
 
691
  check2 = MyOperation->getValue(IND_GROUP_ALLOW_DELETE, 
 
692
                                 (char *)&permission);
 
693
  CHECK_NULL(check2, "T5-2: getValue allow_delete", 
 
694
             MyTransaction);
 
695
  
 
696
  check = MyTransaction->execute( NoCommit ); 
 
697
  CHECK_MINUS_ONE(check, "T5-2: NoCommit", 
 
698
                  MyTransaction);
 
699
  
 
700
  DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
 
701
 
 
702
  if(((permission & inServerBit) == inServerBit) &&
 
703
     ((sessions   & inServerBit) == inServerBit)){
 
704
  
 
705
    DEBUG("deleting - ");
 
706
  
 
707
    /* Operation 3 */
 
708
    MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
 
709
    CHECK_NULL(MyOperation, "T5-3: getNdbOperation", 
 
710
               MyTransaction);
 
711
    
 
712
    check = MyOperation->deleteTuple();
 
713
    CHECK_MINUS_ONE(check, "T5-3: deleteTuple", 
 
714
                    MyTransaction);
 
715
    
 
716
    check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
 
717
                               (char*)inNumber);
 
718
    CHECK_MINUS_ONE(check, "T5-3: equal number",
 
719
                    MyTransaction);
 
720
 
 
721
    check = MyOperation->equal(IND_SESSION_SERVER,
 
722
                               (char*)&inServerId);
 
723
    CHECK_MINUS_ONE(check, "T5-3: equal server id",
 
724
                    MyTransaction);
 
725
    
 
726
    /* Operation 4 */
 
727
    MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
 
728
    CHECK_NULL(MyOperation, "T5-4: getNdbOperation", 
 
729
               MyTransaction);
 
730
    
 
731
    check = MyOperation->interpretedUpdateTuple();
 
732
    CHECK_MINUS_ONE(check, "T5-4: interpretedUpdateTuple", 
 
733
                    MyTransaction);
 
734
    
 
735
    check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
 
736
                               (char*)inNumber);
 
737
    CHECK_MINUS_ONE(check, "T5-4: equal number",
 
738
                    MyTransaction);
 
739
 
 
740
    check = MyOperation->subValue(IND_SUBSCRIBER_SESSIONS, 
 
741
                                  (uint32)inServerBit);
 
742
    CHECK_MINUS_ONE(check, "T5-4: dec value",
 
743
                    MyTransaction);
 
744
        
 
745
    /* Operation 5 */
 
746
    MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
 
747
    CHECK_NULL(MyOperation, "T5-5: getNdbOperation", 
 
748
               MyTransaction);
 
749
    
 
750
    
 
751
    check = MyOperation->interpretedUpdateTuple();
 
752
    CHECK_MINUS_ONE(check, "T5-5: interpretedUpdateTuple", 
 
753
                    MyTransaction);
 
754
    
 
755
    check = MyOperation->equal(IND_SERVER_ID,
 
756
                               (char*)&inServerId);
 
757
    CHECK_MINUS_ONE(check, "T5-5: equal serverId",
 
758
                    MyTransaction);
 
759
 
 
760
    check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
 
761
                               (char*)inSuffix);
 
762
    CHECK_MINUS_ONE(check, "T5-5: equal suffix",
 
763
                    MyTransaction);
 
764
 
 
765
    check = MyOperation->incValue(IND_SERVER_DELETES, (uint32)1);
 
766
    CHECK_MINUS_ONE(check, "T5-5: inc value",
 
767
                    MyTransaction);
 
768
 
 
769
    (* outBranchExecuted) = 1;
 
770
  } else {
 
771
    DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
 
772
    DEBUG1("%s", ((sessions   & inServerBit) ? "in session - " : "no in session - "));
 
773
    (* outBranchExecuted) = 0;
 
774
  }
 
775
 
 
776
  if(!inDoRollback){
 
777
    DEBUG("commit\n");
 
778
    check = MyTransaction->execute( Commit ); 
 
779
    CHECK_MINUS_ONE(check, "T5: Commit", 
 
780
                    MyTransaction);
 
781
  } else {
 
782
    DEBUG("rollback\n");
 
783
    check = MyTransaction->execute(Rollback);
 
784
    CHECK_MINUS_ONE(check, "T5:Rollback", 
 
785
                    MyTransaction);
 
786
    
 
787
  }
 
788
  
 
789
  pNDB->closeTransaction(MyTransaction);
 
790
  
 
791
  get_time(outTransactionTime);
 
792
  time_diff(outTransactionTime, &start);
 
793
  return 0;
 
794
}
 
795