1 /*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2011, 2013 Oracle and/or its affiliates. All rights reserved.
5 */
6
7 /*
8 * #19612 Data not rolled back when transaction aborted after timout.
9 */
10
11 #include <sys/types.h>
12 #include <sys/time.h>
13
14 #include <ctype.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <unistd.h>
19
20 #include <tx.h>
21 #include <atmi.h>
22 #include <fml32.h>
23 #include <fml1632.h>
24
25 #include <db.h>
26
27 #include "../utilities/bdb_xa_util.h"
28
29 #define HOME "../data"
30 #define TABLE1 "../data/table1.db"
31 #define TABLE2 "../data/table2.db"
32
33 DB_ENV *dbenv;
34 char *progname; /* Client run-time name. */
35
36 int usage(void);
37
38 int
main(int argc,char * argv[])39 main(int argc, char* argv[])
40 {
41 DB *dbp3;
42 DBT key, data;
43 TPINIT *initBuf;
44 FBFR *replyBuf;
45 long replyLen;
46 int ch, ret, i;
47 char *target;
48 char *home = HOME;
49 u_int32_t flags = DB_INIT_MPOOL | DB_INIT_LOG | DB_INIT_TXN |
50 DB_INIT_LOCK | DB_CREATE | DB_THREAD | DB_RECOVER | DB_REGISTER;
51 u_int32_t dbflags = DB_CREATE | DB_THREAD;
52
53 progname = argv[0];
54
55 initBuf = NULL;
56 ret = 0;
57 replyBuf = NULL;
58 replyLen = 1024;
59
60 while ((ch = getopt(argc, argv, "v")) != EOF)
61 switch (ch) {
62 case 'v':
63 verbose = 1;
64 break;
65 case '?':
66 default:
67 return (usage());
68 }
69 argc -= optind;
70 argv += optind;
71
72 if (verbose)
73 printf("%s: called\n", progname);
74
75 if (tpinit((TPINIT *)NULL) == -1)
76 goto tuxedo_err;
77 if (verbose)
78 printf("%s: tpinit() OK\n", progname);
79
80 /* Create the DB environment. */
81 if ((ret = db_env_create(&dbenv, 0)) != 0 ||
82 (ret = dbenv->open(dbenv, home, flags, 0)) != 0) {
83 fprintf(stderr,
84 "%s: %s: %s\n", progname, home, db_strerror(ret));
85 goto err;
86 }
87 dbenv->set_errfile(dbenv, stderr);
88 if (verbose)
89 printf("%s: opened %s OK\n", progname, home);
90
91 memset(&key, 0, sizeof(key));
92 memset(&data, 0, sizeof(data));
93
94 /* Allocate reply buffer. */
95 if ((replyBuf = (FBFR*)tpalloc("FML32", NULL, replyLen))
96 == NULL)
97 goto tuxedo_err;
98 if (verbose)
99 printf("%s: tpalloc(\"FML32\"), reply buffer OK\n",
100 progname);
101 for (i = 0; i < 2; i++) {
102 if (tpbegin(10L, 0L) == -1)
103 goto tuxedo_err;
104 if (verbose)
105 printf("%s: tpbegin() OK\n", progname);
106
107 if (tpcall("TestTxn1", NULL, 0L, (char **)&replyBuf,
108 &replyLen, TPSIGRSTRT) == -1)
109 goto tuxedo_err;
110
111 /* This call will timeout. */
112 tpcall("TestTxn2", NULL, 0L, (char **)&replyBuf, &replyLen,
113 TPSIGRSTRT);
114 if (tperrno != TPETIME)
115 goto tuxedo_err;
116
117 if (i == 0) {
118 if (tpabort(0L) == -1)
119 goto tuxedo_err;
120 if (verbose)
121 printf("%s: tpabort() OK\n", progname);
122 } else {
123 /* Commit will fail due to the time out. */
124 tpcommit(0L);
125 if (tperrno != TPEABORT)
126 goto tuxedo_err;
127 if (verbose)
128 printf("%s: tpcommit() OK\n", progname);
129 }
130
131
132 ret = check_data(dbenv, TABLE1, dbenv, TABLE2, progname);
133 }
134
135 if (0) {
136 tuxedo_err: fprintf(stderr, "%s: TUXEDO ERROR: %s (code %d)\n",
137 progname, tpstrerror(tperrno), tperrno);
138 goto err;
139 }
140 if (0) {
141 err: ret = EXIT_FAILURE;
142 }
143
144 if (replyBuf != NULL)
145 tpfree((char *)replyBuf);
146 if (dbenv != NULL)
147 (void)dbenv->close(dbenv, 0);
148
149 tpterm();
150 if (verbose)
151 printf("%s: tpterm() OK\n", progname);
152
153 if (verbose && ret == 0)
154 printf("%s: test passed.\n", progname);
155 else if (verbose)
156 printf("%s: test failed.\n", progname);
157 return (ret);
158 }
159
160 int
usage()161 usage()
162 {
163 fprintf(stderr, "usage: %s [-v] [-n txn]\n", progname);
164 return (EXIT_FAILURE);
165 }
166