2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
8 * This server is called by the client. It inserts a value into db1 then
9 * calls bdb2 to insert a value into db2.
17 #include <atmi.h> /* TUXEDO Header File */
18 #include <userlog.h> /* TUXEDO Header File */
23 #include "../utilities/bdb_xa_util.h"
30 static char *progname;
32 /* Open the database when the server is started. */
42 /* Some compilers warn if argc and argv aren't used. */
43 while ((ch = getopt(argc, argv, "t:")) != EOF)
51 return (init_xa_server(NUMDB, progname, 0));
54 /* Close the database when the server is shutdown. */
58 close_xa_server(NUMDB, progname);
61 /* Insert a value into db1, then call bdb2 to insert that value into db2. */
71 char *p, *t, buf[1024];
76 for(i=0; i<times; i++){
77 /* Insert random records into the db1*/
78 memset(&key, 0, sizeof(DBT));
79 memset(&data, 0, sizeof(DBT));
80 sprintf(buf, "%ld %ld",random(), seq++);
85 data.size = key.size = (u_int32_t)len ;
87 switch (ret = dbp->put(dbp, NULL, &key, &data,
91 case DB_LOCK_DEADLOCK:
93 userlog("tpabort() fail:%s",
96 tpreturn(TPSUCCESS, 1, rqst->data, 0L, 0);
98 userlog("put: %s", db_strerror(ret));
100 userlog("tpabort() fail:%s",
101 tpstrerror(tperrno));
103 tpreturn(TPFAIL, 0, rqst->data, 0L, 0);
108 * Insert the key into a queue and call bdb2 where it will read
109 * the key out of the queue.
114 if((reqbuf = (FBFR32*) tpalloc("FML32", NULL, 100)) == NULL) {
116 userlog("alloc fail");
117 tpreturn(TPFAIL, 0, rqst->data, 0L, 0);
120 if((rcvbuf = (char *) tpalloc("STRING", NULL, 100)) == NULL) {
122 userlog("alloc fail");
123 tpreturn(TPFAIL, 0, rqst->data, 0L, 0);
126 Fadd32(reqbuf, TA_REPOSPARAM, buf, 0);
129 ret = tpcall("WRITE2", (char *)reqbuf, 0, &rcvbuf, &rcvlen,TPSIGRSTRT);
130 tpfree((char*)reqbuf);
131 tpfree((char*)rcvbuf);
133 userlog("call WRITE2 fail");
135 userlog("tpabort() fail:%s", tpstrerror(tperrno));
136 tpreturn(TPFAIL, 0, rqst->data, 0L, 0);
138 /* Commit for a return value of 0, otherwise abort. */
140 if(tpcommit(0) == -1){
141 userlog("tpcommit fail");
142 tpreturn(TPFAIL, 0, rqst->data, 0L, 0);
145 if(tpabort(0) == -1){
146 userlog("tpabort fail");
147 tpreturn(TPFAIL, 0, rqst->data, 0L, 0);
151 tpreturn(TPSUCCESS, 0, rqst->data, 0L, 0);
154 /* Iterates the database with a cursor. */
167 ret = dbp->cursor(dbp, NULL, &cursorp, 0);
169 userlog("count_records: cursor open failed.");
170 tpreturn(TPFAIL, 0, rqst->data, 0L, 0);
173 /* Get the key DBT used for the database read */
174 memset(&key, 0, sizeof(DBT));
175 memset(&value, 0, sizeof(DBT));
177 ret = cursorp->c_get(cursorp, &key, &value, DB_NEXT);
184 case DB_LOCK_DEADLOCK:
185 if(tpcommit(0) == -1)
186 userlog("tpcommit() fail:%s",
187 tpstrerror(tperrno));
188 cursorp->c_close(cursorp);
189 tpreturn(TPSUCCESS, 1L, rqst->data, 0L, 0);
193 userlog("tpabort() fail:%s",
194 tpstrerror(tperrno));
195 cursorp->c_close(cursorp);
197 "Count records unspecified error");
198 tpreturn(TPFAIL, 0, rqst->data, 0L, 0);
201 cursorp->c_close(cursorp);
203 tpreturn(TPSUCCESS, 0, rqst->data, 0L, 0);