~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/examples_cxx/TpcbExample.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*-
2
 
 * See the file LICENSE for redistribution information.
3
 
 *
4
 
 * Copyright (c) 1997-2002
5
 
 *      Sleepycat Software.  All rights reserved.
6
 
 *
7
 
 * $Id$
8
 
 */
9
 
 
10
 
#include <sys/types.h>
11
 
 
12
 
#include <errno.h>
13
 
#include <stdlib.h>
14
 
#include <string.h>
15
 
#include <time.h>
16
 
 
17
 
#include <iostream>
18
 
#include <iomanip>
19
 
#include <db_cxx.h>
20
 
 
21
 
using std::cout;
22
 
using std::cerr;
23
 
 
24
 
typedef enum { ACCOUNT, BRANCH, TELLER } FTYPE;
25
 
 
26
 
static int        invarg(int, char *);
27
 
u_int32_t random_id(FTYPE, u_int32_t, u_int32_t, u_int32_t);
28
 
u_int32_t random_int(u_int32_t, u_int32_t);
29
 
static int        usage(void);
30
 
 
31
 
int verbose;
32
 
const char *progname = "TpcbExample";                       // Program name.
33
 
 
34
 
class TpcbExample : public DbEnv
35
 
{
36
 
public:
37
 
        void populate(int, int, int, int);
38
 
        void run(int, int, int, int);
39
 
        int txn(Db *, Db *, Db *, Db *,
40
 
                int, int, int);
41
 
        void populateHistory(Db *, int, u_int32_t, u_int32_t, u_int32_t);
42
 
        void populateTable(Db *, u_int32_t, u_int32_t, int, const char *);
43
 
 
44
 
        // Note: the constructor creates a DbEnv(), which is
45
 
        // not fully initialized until the DbEnv::open() method
46
 
        // is called.
47
 
        //
48
 
        TpcbExample(const char *home, int cachesize,
49
 
                    int initializing, int flags);
50
 
 
51
 
private:
52
 
        static const char FileName[];
53
 
 
54
 
        // no need for copy and assignment
55
 
        TpcbExample(const TpcbExample &);
56
 
        void operator = (const TpcbExample &);
57
 
};
58
 
 
59
 
//
60
 
// This program implements a basic TPC/B driver program.  To create the
61
 
// TPC/B database, run with the -i (init) flag.  The number of records
62
 
// with which to populate the account, history, branch, and teller tables
63
 
// is specified by the a, s, b, and t flags respectively.  To run a TPC/B
64
 
// test, use the n flag to indicate a number of transactions to run (note
65
 
// that you can run many of these processes in parallel to simulate a
66
 
// multiuser test run).
67
 
//
68
 
#define TELLERS_PER_BRANCH      100
69
 
#define ACCOUNTS_PER_TELLER     1000
70
 
#define HISTORY_PER_BRANCH      2592000
71
 
 
72
 
/*
73
 
 * The default configuration that adheres to TPCB scaling rules requires
74
 
 * nearly 3 GB of space.  To avoid requiring that much space for testing,
75
 
 * we set the parameters much lower.  If you want to run a valid 10 TPS
76
 
 * configuration, define VALID_SCALING.
77
 
 */
78
 
#ifdef  VALID_SCALING
79
 
#define ACCOUNTS         1000000
80
 
#define BRANCHES              10
81
 
#define TELLERS              100
82
 
#define HISTORY         25920000
83
 
#endif
84
 
 
85
 
#ifdef  TINY
86
 
#define ACCOUNTS            1000
87
 
#define BRANCHES              10
88
 
#define TELLERS              100
89
 
#define HISTORY            10000
90
 
#endif
91
 
 
92
 
#if !defined(VALID_SCALING) && !defined(TINY)
93
 
#define ACCOUNTS          100000
94
 
#define BRANCHES              10
95
 
#define TELLERS              100
96
 
#define HISTORY           259200
97
 
#endif
98
 
 
99
 
#define HISTORY_LEN         100
100
 
#define RECLEN              100
101
 
#define BEGID           1000000
102
 
 
103
 
struct Defrec {
104
 
        u_int32_t   id;
105
 
        u_int32_t   balance;
106
 
        u_int8_t    pad[RECLEN - sizeof(u_int32_t) - sizeof(u_int32_t)];
107
 
};
108
 
 
109
 
struct Histrec {
110
 
        u_int32_t   aid;
111
 
        u_int32_t   bid;
112
 
        u_int32_t   tid;
113
 
        u_int32_t   amount;
114
 
        u_int8_t    pad[RECLEN - 4 * sizeof(u_int32_t)];
115
 
};
116
 
 
117
 
int
118
 
main(int argc, char *argv[])
119
 
{
120
 
        unsigned long seed;
121
 
        int accounts, branches, tellers, history;
122
 
        int iflag, mpool, ntxns, txn_no_sync;
123
 
        const char *home;
124
 
        char *endarg;
125
 
 
126
 
        home = "TESTDIR";
127
 
        accounts = branches = history = tellers = 0;
128
 
        txn_no_sync = 0;
129
 
        mpool = ntxns = 0;
130
 
        verbose = 0;
131
 
        iflag = 0;
132
 
        seed = (unsigned long)time(NULL);
133
 
 
134
 
        for (int i = 1; i < argc; ++i) {
135
 
 
136
 
                if (strcmp(argv[i], "-a") == 0) {
137
 
                        // Number of account records
138
 
                        if ((accounts = atoi(argv[++i])) <= 0)
139
 
                                return (invarg('a', argv[i]));
140
 
                }
141
 
                else if (strcmp(argv[i], "-b") == 0) {
142
 
                        // Number of branch records
143
 
                        if ((branches = atoi(argv[++i])) <= 0)
144
 
                                return (invarg('b', argv[i]));
145
 
                }
146
 
                else if (strcmp(argv[i], "-c") == 0) {
147
 
                        // Cachesize in bytes
148
 
                        if ((mpool = atoi(argv[++i])) <= 0)
149
 
                                return (invarg('c', argv[i]));
150
 
                }
151
 
                else if (strcmp(argv[i], "-f") == 0) {
152
 
                        // Fast mode: no txn sync.
153
 
                        txn_no_sync = 1;
154
 
                }
155
 
                else if (strcmp(argv[i], "-h") == 0) {
156
 
                        // DB  home.
157
 
                        home = argv[++i];
158
 
                }
159
 
                else if (strcmp(argv[i], "-i") == 0) {
160
 
                        // Initialize the test.
161
 
                        iflag = 1;
162
 
                }
163
 
                else if (strcmp(argv[i], "-n") == 0) {
164
 
                        // Number of transactions
165
 
                        if ((ntxns = atoi(argv[++i])) <= 0)
166
 
                                return (invarg('n', argv[i]));
167
 
                }
168
 
                else if (strcmp(argv[i], "-S") == 0) {
169
 
                        // Random number seed.
170
 
                        seed = strtoul(argv[++i], &endarg, 0);
171
 
                        if (*endarg != '\0')
172
 
                                return (invarg('S', argv[i]));
173
 
                }
174
 
                else if (strcmp(argv[i], "-s") == 0) {
175
 
                        // Number of history records
176
 
                        if ((history = atoi(argv[++i])) <= 0)
177
 
                                return (invarg('s', argv[i]));
178
 
                }
179
 
                else if (strcmp(argv[i], "-t") == 0) {
180
 
                        // Number of teller records
181
 
                        if ((tellers = atoi(argv[++i])) <= 0)
182
 
                                return (invarg('t', argv[i]));
183
 
                }
184
 
                else if (strcmp(argv[i], "-v") == 0) {
185
 
                        // Verbose option.
186
 
                        verbose = 1;
187
 
                }
188
 
                else {
189
 
                        return (usage());
190
 
                }
191
 
        }
192
 
 
193
 
        srand((unsigned int)seed);
194
 
 
195
 
        accounts = accounts == 0 ? ACCOUNTS : accounts;
196
 
        branches = branches == 0 ? BRANCHES : branches;
197
 
        tellers = tellers == 0 ? TELLERS : tellers;
198
 
        history = history == 0 ? HISTORY : history;
199
 
 
200
 
        if (verbose)
201
 
                cout << (long)accounts << " Accounts, "
202
 
                     << (long)branches << " Branches, "
203
 
                     << (long)tellers << " Tellers, "
204
 
                     << (long)history << " History\n";
205
 
 
206
 
        try {
207
 
                // Initialize the database environment.
208
 
                // Must be done in within a try block, unless you
209
 
                // change the error model in the environment options.
210
 
                //
211
 
                TpcbExample app(home, mpool, iflag,
212
 
                                txn_no_sync ? DB_TXN_NOSYNC : 0);
213
 
 
214
 
                if (iflag) {
215
 
                        if (ntxns != 0)
216
 
                                return (usage());
217
 
                        app.populate(accounts, branches, history, tellers);
218
 
                }
219
 
                else {
220
 
                        if (ntxns == 0)
221
 
                                return (usage());
222
 
                        app.run(ntxns, accounts, branches, tellers);
223
 
                }
224
 
 
225
 
                app.close(0);
226
 
                return (EXIT_SUCCESS);
227
 
        }
228
 
        catch (DbException &dbe) {
229
 
                cerr << "TpcbExample: " << dbe.what() << "\n";
230
 
                return (EXIT_FAILURE);
231
 
        }
232
 
}
233
 
 
234
 
static int
235
 
invarg(int arg, char *str)
236
 
{
237
 
        cerr << "TpcbExample: invalid argument for -"
238
 
             << (char)arg << ": " << str << "\n";
239
 
        return (EXIT_FAILURE);
240
 
}
241
 
 
242
 
static int
243
 
usage()
244
 
{
245
 
        cerr << "usage: TpcbExample [-fiv] [-a accounts] [-b branches]\n"
246
 
             << "                   [-c cachesize] [-h home] [-n transactions ]\n"
247
 
             << "                   [-S seed] [-s history] [-t tellers]\n";
248
 
        return (EXIT_FAILURE);
249
 
}
250
 
 
251
 
TpcbExample::TpcbExample(const char *home, int cachesize,
252
 
                         int initializing, int flags)
253
 
:       DbEnv(0)
254
 
{
255
 
        u_int32_t local_flags;
256
 
 
257
 
        set_error_stream(&cerr);
258
 
        set_errpfx("TpcbExample");
259
 
        (void)set_cachesize(0, cachesize == 0 ?
260
 
                            4 * 1024 * 1024 : (u_int32_t)cachesize, 0);
261
 
 
262
 
        if (flags & (DB_TXN_NOSYNC))
263
 
                set_flags(DB_TXN_NOSYNC, 1);
264
 
        flags &= ~(DB_TXN_NOSYNC);
265
 
 
266
 
        local_flags = flags | DB_CREATE | DB_INIT_MPOOL;
267
 
        if (!initializing)
268
 
                local_flags |= DB_INIT_TXN | DB_INIT_LOCK | DB_INIT_LOG;
269
 
        open(home, local_flags, 0);
270
 
}
271
 
 
272
 
//
273
 
// Initialize the database to the specified number of accounts, branches,
274
 
// history records, and tellers.
275
 
//
276
 
void
277
 
TpcbExample::populate(int accounts, int branches, int history, int tellers)
278
 
{
279
 
        Db *dbp;
280
 
 
281
 
        int err;
282
 
        u_int32_t balance, idnum;
283
 
        u_int32_t end_anum, end_bnum, end_tnum;
284
 
        u_int32_t start_anum, start_bnum, start_tnum;
285
 
 
286
 
        idnum = BEGID;
287
 
        balance = 500000;
288
 
 
289
 
        dbp = new Db(this, 0);
290
 
        dbp->set_h_nelem((unsigned int)accounts);
291
 
 
292
 
        if ((err = dbp->open(NULL, "account", NULL, DB_HASH,
293
 
                             DB_CREATE | DB_TRUNCATE, 0644)) != 0) {
294
 
                DbException except("Account file create failed", err);
295
 
                throw except;
296
 
        }
297
 
 
298
 
        start_anum = idnum;
299
 
        populateTable(dbp, idnum, balance, accounts, "account");
300
 
        idnum += accounts;
301
 
        end_anum = idnum - 1;
302
 
        if ((err = dbp->close(0)) != 0) {
303
 
                DbException except("Account file close failed", err);
304
 
                throw except;
305
 
        }
306
 
        delete dbp;
307
 
        if (verbose)
308
 
                cout << "Populated accounts: "
309
 
                     << (long)start_anum << " - " << (long)end_anum << "\n";
310
 
 
311
 
        dbp = new Db(this, 0);
312
 
        //
313
 
        // Since the number of branches is very small, we want to use very
314
 
        // small pages and only 1 key per page.  This is the poor-man's way
315
 
        // of getting key locking instead of page locking.
316
 
        //
317
 
        dbp->set_h_ffactor(1);
318
 
        dbp->set_h_nelem((unsigned int)branches);
319
 
        dbp->set_pagesize(512);
320
 
 
321
 
        if ((err = dbp->open(NULL, "branch", NULL, DB_HASH,
322
 
                             DB_CREATE | DB_TRUNCATE, 0644)) != 0) {
323
 
                DbException except("Branch file create failed", err);
324
 
                throw except;
325
 
        }
326
 
        start_bnum = idnum;
327
 
        populateTable(dbp, idnum, balance, branches, "branch");
328
 
        idnum += branches;
329
 
        end_bnum = idnum - 1;
330
 
        if ((err = dbp->close(0)) != 0) {
331
 
                DbException except("Close of branch file failed", err);
332
 
                throw except;
333
 
        }
334
 
        delete dbp;
335
 
 
336
 
        if (verbose)
337
 
                cout << "Populated branches: "
338
 
                     << (long)start_bnum << " - " << (long)end_bnum << "\n";
339
 
 
340
 
        dbp = new Db(this, 0);
341
 
        //
342
 
        // In the case of tellers, we also want small pages, but we'll let
343
 
        // the fill factor dynamically adjust itself.
344
 
        //
345
 
        dbp->set_h_ffactor(0);
346
 
        dbp->set_h_nelem((unsigned int)tellers);
347
 
        dbp->set_pagesize(512);
348
 
 
349
 
        if ((err = dbp->open(NULL, "teller", NULL, DB_HASH,
350
 
                             DB_CREATE | DB_TRUNCATE, 0644)) != 0) {
351
 
                DbException except("Teller file create failed", err);
352
 
                throw except;
353
 
        }
354
 
 
355
 
        start_tnum = idnum;
356
 
        populateTable(dbp, idnum, balance, tellers, "teller");
357
 
        idnum += tellers;
358
 
        end_tnum = idnum - 1;
359
 
        if ((err = dbp->close(0)) != 0) {
360
 
                DbException except("Close of teller file failed", err);
361
 
                throw except;
362
 
        }
363
 
        delete dbp;
364
 
        if (verbose)
365
 
                cout << "Populated tellers: "
366
 
                     << (long)start_tnum << " - " << (long)end_tnum << "\n";
367
 
 
368
 
        dbp = new Db(this, 0);
369
 
        dbp->set_re_len(HISTORY_LEN);
370
 
        if ((err = dbp->open(NULL, "history", NULL, DB_RECNO,
371
 
                             DB_CREATE | DB_TRUNCATE, 0644)) != 0) {
372
 
                DbException except("Create of history file failed", err);
373
 
                throw except;
374
 
        }
375
 
 
376
 
        populateHistory(dbp, history, accounts, branches, tellers);
377
 
        if ((err = dbp->close(0)) != 0) {
378
 
                DbException except("Close of history file failed", err);
379
 
                throw except;
380
 
        }
381
 
        delete dbp;
382
 
}
383
 
 
384
 
void
385
 
TpcbExample::populateTable(Db *dbp,
386
 
                           u_int32_t start_id, u_int32_t balance,
387
 
                           int nrecs, const char *msg)
388
 
{
389
 
        Defrec drec;
390
 
        memset(&drec.pad[0], 1, sizeof(drec.pad));
391
 
 
392
 
        Dbt kdbt(&drec.id, sizeof(u_int32_t));
393
 
        Dbt ddbt(&drec, sizeof(drec));
394
 
 
395
 
        for (int i = 0; i < nrecs; i++) {
396
 
                drec.id = start_id + (u_int32_t)i;
397
 
                drec.balance = balance;
398
 
                int err;
399
 
                if ((err =
400
 
                     dbp->put(NULL, &kdbt, &ddbt, DB_NOOVERWRITE)) != 0) {
401
 
                        cerr << "Failure initializing " << msg << " file: "
402
 
                             << strerror(err) << "\n";
403
 
                        DbException except("failure initializing file", err);
404
 
                        throw except;
405
 
                }
406
 
        }
407
 
}
408
 
 
409
 
void
410
 
TpcbExample::populateHistory(Db *dbp, int nrecs, u_int32_t accounts,
411
 
                             u_int32_t branches, u_int32_t tellers)
412
 
{
413
 
        Histrec hrec;
414
 
        memset(&hrec.pad[0], 1, sizeof(hrec.pad));
415
 
        hrec.amount = 10;
416
 
        db_recno_t key;
417
 
 
418
 
        Dbt kdbt(&key, sizeof(u_int32_t));
419
 
        Dbt ddbt(&hrec, sizeof(hrec));
420
 
 
421
 
        for (int i = 1; i <= nrecs; i++) {
422
 
                hrec.aid = random_id(ACCOUNT, accounts, branches, tellers);
423
 
                hrec.bid = random_id(BRANCH, accounts, branches, tellers);
424
 
                hrec.tid = random_id(TELLER, accounts, branches, tellers);
425
 
 
426
 
                int err;
427
 
                key = (db_recno_t)i;
428
 
                if ((err = dbp->put(NULL, &kdbt, &ddbt, DB_APPEND)) != 0) {
429
 
                        DbException except("failure initializing history file",
430
 
                                           err);
431
 
                        throw except;
432
 
                }
433
 
        }
434
 
}
435
 
 
436
 
u_int32_t
437
 
random_int(u_int32_t lo, u_int32_t hi)
438
 
{
439
 
        u_int32_t ret;
440
 
        int t;
441
 
 
442
 
        t = rand();
443
 
        ret = (u_int32_t)(((double)t / ((double)(RAND_MAX) + 1)) *
444
 
                          (hi - lo + 1));
445
 
        ret += lo;
446
 
        return (ret);
447
 
}
448
 
 
449
 
u_int32_t
450
 
random_id(FTYPE type, u_int32_t accounts, u_int32_t branches, u_int32_t tellers)
451
 
{
452
 
        u_int32_t min, max, num;
453
 
 
454
 
        max = min = BEGID;
455
 
        num = accounts;
456
 
        switch(type) {
457
 
        case TELLER:
458
 
                min += branches;
459
 
                num = tellers;
460
 
                // Fallthrough
461
 
        case BRANCH:
462
 
                if (type == BRANCH)
463
 
                        num = branches;
464
 
                min += accounts;
465
 
                // Fallthrough
466
 
        case ACCOUNT:
467
 
                max = min + num - 1;
468
 
        }
469
 
        return (random_int(min, max));
470
 
}
471
 
 
472
 
void
473
 
TpcbExample::run(int n, int accounts, int branches, int tellers)
474
 
{
475
 
        Db *adb, *bdb, *hdb, *tdb;
476
 
        double gtps, itps;
477
 
        int failed, ifailed, ret, txns;
478
 
        time_t starttime, curtime, lasttime;
479
 
 
480
 
        //
481
 
        // Open the database files.
482
 
        //
483
 
 
484
 
        int err;
485
 
        adb = new Db(this, 0);
486
 
        if ((err = adb->open(NULL, "account", NULL, DB_UNKNOWN,
487
 
                             DB_AUTO_COMMIT, 0)) != 0) {
488
 
                DbException except("Open of account file failed", err);
489
 
                throw except;
490
 
        }
491
 
 
492
 
        bdb = new Db(this, 0);
493
 
        if ((err = bdb->open(NULL, "branch", NULL, DB_UNKNOWN,
494
 
                             DB_AUTO_COMMIT, 0)) != 0) {
495
 
                DbException except("Open of branch file failed", err);
496
 
                throw except;
497
 
        }
498
 
 
499
 
        tdb = new Db(this, 0);
500
 
        if ((err = tdb->open(NULL, "teller", NULL, DB_UNKNOWN,
501
 
                             DB_AUTO_COMMIT, 0)) != 0) {
502
 
                DbException except("Open of teller file failed", err);
503
 
                throw except;
504
 
        }
505
 
 
506
 
        hdb = new Db(this, 0);
507
 
        if ((err = hdb->open(NULL, "history", NULL, DB_UNKNOWN,
508
 
                             DB_AUTO_COMMIT, 0)) != 0) {
509
 
                DbException except("Open of history file failed", err);
510
 
                throw except;
511
 
        }
512
 
 
513
 
        txns = failed = ifailed = 0;
514
 
        starttime = time(NULL);
515
 
        lasttime = starttime;
516
 
        while (n-- > 0) {
517
 
                txns++;
518
 
                ret = txn(adb, bdb, tdb, hdb, accounts, branches, tellers);
519
 
                if (ret != 0) {
520
 
                        failed++;
521
 
                        ifailed++;
522
 
                }
523
 
                if (n % 5000 == 0) {
524
 
                        curtime = time(NULL);
525
 
                        gtps = (double)(txns - failed) / (curtime - starttime);
526
 
                        itps = (double)(5000 - ifailed) / (curtime - lasttime);
527
 
 
528
 
                        // We use printf because it provides much simpler
529
 
                        // formatting than iostreams.
530
 
                        //
531
 
                        printf("%d txns %d failed ", txns, failed);
532
 
                        printf("%6.2f TPS (gross) %6.2f TPS (interval)\n",
533
 
                            gtps, itps);
534
 
                        lasttime = curtime;
535
 
                        ifailed = 0;
536
 
                }
537
 
        }
538
 
 
539
 
        (void)adb->close(0);
540
 
        (void)bdb->close(0);
541
 
        (void)tdb->close(0);
542
 
        (void)hdb->close(0);
543
 
 
544
 
        cout << (long)txns << " transactions begun "
545
 
             << (long)failed << " failed\n";
546
 
}
547
 
 
548
 
//
549
 
// XXX Figure out the appropriate way to pick out IDs.
550
 
//
551
 
int
552
 
TpcbExample::txn(Db *adb, Db *bdb, Db *tdb, Db *hdb,
553
 
                 int accounts, int branches, int tellers)
554
 
{
555
 
        Dbc *acurs = NULL;
556
 
        Dbc *bcurs = NULL;
557
 
        Dbc *tcurs = NULL;
558
 
        DbTxn *t = NULL;
559
 
 
560
 
        db_recno_t key;
561
 
        Defrec rec;
562
 
        Histrec hrec;
563
 
        int account, branch, teller, ret;
564
 
 
565
 
        Dbt d_dbt;
566
 
        Dbt d_histdbt;
567
 
        Dbt k_dbt;
568
 
        Dbt k_histdbt(&key, sizeof(key));
569
 
 
570
 
        //
571
 
        // XXX We could move a lot of this into the driver to make this
572
 
        // faster.
573
 
        //
574
 
        account = random_id(ACCOUNT, accounts, branches, tellers);
575
 
        branch = random_id(BRANCH, accounts, branches, tellers);
576
 
        teller = random_id(TELLER, accounts, branches, tellers);
577
 
 
578
 
        k_dbt.set_size(sizeof(int));
579
 
 
580
 
        d_dbt.set_flags(DB_DBT_USERMEM);
581
 
        d_dbt.set_data(&rec);
582
 
        d_dbt.set_ulen(sizeof(rec));
583
 
 
584
 
        hrec.aid = account;
585
 
        hrec.bid = branch;
586
 
        hrec.tid = teller;
587
 
        hrec.amount = 10;
588
 
        // Request 0 bytes since we're just positioning.
589
 
        d_histdbt.set_flags(DB_DBT_PARTIAL);
590
 
 
591
 
        // START TIMING
592
 
        if (txn_begin(NULL, &t, 0) != 0)
593
 
                goto err;
594
 
 
595
 
        if (adb->cursor(t, &acurs, 0) != 0 ||
596
 
            bdb->cursor(t, &bcurs, 0) != 0 ||
597
 
            tdb->cursor(t, &tcurs, 0) != 0)
598
 
                goto err;
599
 
 
600
 
        // Account record
601
 
        k_dbt.set_data(&account);
602
 
        if (acurs->get(&k_dbt, &d_dbt, DB_SET) != 0)
603
 
                goto err;
604
 
        rec.balance += 10;
605
 
        if (acurs->put(&k_dbt, &d_dbt, DB_CURRENT) != 0)
606
 
                goto err;
607
 
 
608
 
        // Branch record
609
 
        k_dbt.set_data(&branch);
610
 
        if (bcurs->get(&k_dbt, &d_dbt, DB_SET) != 0)
611
 
                goto err;
612
 
        rec.balance += 10;
613
 
        if (bcurs->put(&k_dbt, &d_dbt, DB_CURRENT) != 0)
614
 
                goto err;
615
 
 
616
 
        // Teller record
617
 
        k_dbt.set_data(&teller);
618
 
        if (tcurs->get(&k_dbt, &d_dbt, DB_SET) != 0)
619
 
                goto err;
620
 
        rec.balance += 10;
621
 
        if (tcurs->put(&k_dbt, &d_dbt, DB_CURRENT) != 0)
622
 
                goto err;
623
 
 
624
 
        // History record
625
 
        d_histdbt.set_flags(0);
626
 
        d_histdbt.set_data(&hrec);
627
 
        d_histdbt.set_ulen(sizeof(hrec));
628
 
        if (hdb->put(t, &k_histdbt, &d_histdbt, DB_APPEND) != 0)
629
 
                goto err;
630
 
 
631
 
        if (acurs->close() != 0 || bcurs->close() != 0 || tcurs->close() != 0)
632
 
                goto err;
633
 
 
634
 
        ret = t->commit(0);
635
 
        t = NULL;
636
 
        if (ret != 0)
637
 
                goto err;
638
 
 
639
 
        // END TIMING
640
 
        return (0);
641
 
 
642
 
err:
643
 
        if (acurs != NULL)
644
 
                (void)acurs->close();
645
 
        if (bcurs != NULL)
646
 
                (void)bcurs->close();
647
 
        if (tcurs != NULL)
648
 
                (void)tcurs->close();
649
 
        if (t != NULL)
650
 
                (void)t->abort();
651
 
 
652
 
        if (verbose)
653
 
                cout << "Transaction A=" << (long)account
654
 
                     << " B=" << (long)branch
655
 
                     << " T=" << (long)teller << " failed\n";
656
 
        return (-1);
657
 
}