1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2011, 2015 Oracle and/or its affiliates. All rights reserved.
*/
/*
* This code is for servers used in test 4. Server 1 inserts
* into database 1 and Server 2 inserts into database 2, then
* sleeps for 30 seconds to cause a timeout error in the client.
*/
#include <sys/types.h>
#include "../utilities/bdb_xa_util.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <atmi.h>
#include <fml1632.h>
#include <fml32.h>
#include <tx.h>
#include <xa.h>
#include <db.h>
/*
* The two servers are largely identical, #ifdef the source code.
*/
#ifdef SERVER1
#define TXN_FUNC TestTxn1
#define TXN_STRING "TestTxn1"
#endif
#ifdef SERVER2
#define TXN_FUNC TestTxn2
#define TXN_STRING "TestTxn2"
#endif
void TXN_FUNC(TPSVCINFO *);
#define HOME "../data"
#define NUMDB 2
char *progname; /* Server run-time name. */
/*
* Called when each server is started. It creates and opens a database.
*/
int
tpsvrinit(int argc, char* argv[])
{
progname = argv[0];
return (init_xa_server(NUMDB, progname, 0));
}
/* Called when the servers are shutdown. This closes the database. */
void
tpsvrdone()
{
close_xa_server(NUMDB, progname);
}
/*
* This function is called by the client. Here, on Server 1 data is
* inserted into table 1 and it returns successfully. On Server 2 data
* is inserted into table 2, but then it sleeps for 30 seconds then
* returns, in order to force a timeout and to make sure that the data
* is rolled back in both databases.
*/
void
TXN_FUNC(TPSVCINFO *msg)
{
DBT data;
DBT key;
int ret, val, i;
DB *db;
const char *name;
#ifdef SERVER1
i = 0;
#else
i = 1;
#endif
db = dbs[i];
name = db_names[i];
val = 1;
memset(&key, 0, sizeof(key));
key.data = &val;
key.size = sizeof(val);
memset(&data, 0, sizeof(data));
data.data = &val;
data.size = sizeof(val);
if (verbose) {
printf("put: key in %s: %i\n", val, db_names[0]);
printf("put: data in %s: %i\n", val, db_names[0]);
}
if ((ret = db->put(db, NULL, &key, &data, 0)) != 0) {
if (ret == DB_LOCK_DEADLOCK)
goto abort;
fprintf(stderr, "%s: %s: %s->put: %s\n",
progname, TXN_STRING, name,
db_strerror(ret));
goto err;
}
/* Sleep for 30 seconds to force a timeout error. */
#ifdef SERVER2
sleep(30);
#endif
tpreturn(TPSUCCESS, 0L, 0, 0L, 0);
if (0) {
abort: if (verbose)
printf("%s: %s: abort\n", progname, TXN_STRING);
tpreturn(TPSUCCESS, 1L, 0, 0L, 0);
}
return;
err:
tpreturn(TPFAIL, 0L, 0, 0L, 0);
}
|