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
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2011, 2015 Oracle and/or its affiliates. All rights reserved.
*/
/*
* This server is only called by bdb1. It takes the data sent by bdb1 and
* inserts it into db2.
*/
#include <db.h>
#include <xa.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <atmi.h> /* TUXEDO Header File */
#include <userlog.h> /* TUXEDO Header File */
#include <string.h>
#include <time.h>
#include <tpadm.h>
#include "../utilities/bdb_xa_util.h"
#define NUMDB 2
static char *progname;
/* Write the given data into the given database. */
static int writedb(DB * dbp, void *buf, u_int32_t size){
DBT key, data;
size_t len;
int ch, ret;
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
key.data = buf;
data.data = buf;
data.size = key.size = size;
ret = dbp->put(dbp, NULL, &key, &data, DB_NOOVERWRITE);
switch (ret) {
case 0:
return (EXIT_SUCCESS);
case DB_KEYEXIST:
return (EXIT_SUCCESS);
case DB_LOCK_DEADLOCK:
return (EXIT_SUCCESS);
default:
userlog("put: %s", db_strerror(ret));
return (-1);
}
}
/* Open the databases used by this server when it is started. */
int
tpsvrinit(argc, argv)
int argc;
char **argv;
{
progname = argv[0];
return (init_xa_server(NUMDB, progname, 0));
}
/* Close the database when the server is shutdown. */
void
tpsvrdone(void)
{
close_xa_server(NUMDB,progname);
}
/*
* Get the data the calling server just inserted into db1 and insert it into
* db2. Fgets32 is used to get the key passed by the calling server.
*/
int
WRITE2(rqst)
TPSVCINFO *rqst;
{
char buf[100];
DBT key, data;
FBFR32 *reqbuf = (FBFR32*)rqst->data;
int ret;
Fgets32(reqbuf, TA_REPOSPARAM, 0, buf);
userlog("buf:[%s]", buf);
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
key.data = buf;
key.size = (u_int32_t)strlen(buf);
data.flags = DB_DBT_MALLOC;
/* Get the data that the calling server inserted into db1 */
switch (ret = dbs[0]->get(dbs[0], NULL, &key, &data, DB_READ_UNCOMMITTED)){
case 0:
break;
case DB_LOCK_DEADLOCK:
tpreturn(TPSUCCESS, 1L, rqst->data, 0L, 0);
default:
userlog("get: %s", db_strerror(ret));
tpreturn(TPFAIL, 0L, rqst->data, 0L, 0);
}
/* Write the data to db2 */
if(writedb(dbs[1], data.data, data.size) != 0){
tpreturn(TPSUCCESS, 1L, rqst->data, 0L, 0);
}
tpreturn(TPSUCCESS, 0, rqst->data, 0L, 0);
}
|