forked from bloomberg/comdb2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtxn_method.c
205 lines (178 loc) · 4.7 KB
/
txn_method.c
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1996-2003
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
static const char revid[] = "$Id: txn_method.c,v 11.66 2003/06/30 17:20:30 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#ifdef HAVE_RPC
#include <rpc/rpc.h>
#endif
#include <string.h>
#endif
#include "db_int.h"
#include "dbinc/txn.h"
#ifdef HAVE_RPC
#include "dbinc_auto/db_server.h"
#include "dbinc_auto/rpc_client_ext.h"
#endif
#include "logmsg.h"
static int __txn_get_tx_max __P((DB_ENV *, u_int32_t *));
static int __txn_get_tx_timestamp __P((DB_ENV *, time_t *));
static int __txn_set_tx_timestamp __P((DB_ENV *, time_t *));
static void __txn_dump_ltrans __P((DB_ENV *, FILE *, u_int32_t));
static int __txn_set_logical_start __P((DB_ENV *,
int (*)(DB_ENV *, void *, u_int64_t, DB_LSN *)));
static int __txn_set_logical_commit __P((DB_ENV *,
int (*)(DB_ENV *, void *, u_int64_t, DB_LSN *)));
/*
* __txn_dbenv_create --
* Transaction specific initialization of the DB_ENV structure.
*
* PUBLIC: void __txn_dbenv_create __P((DB_ENV *));
*/
void
__txn_dbenv_create(dbenv)
DB_ENV *dbenv;
{
/*
* !!!
* Our caller has not yet had the opportunity to reset the panic
* state or turn off mutex locking, and so we can neither check
* the panic state or acquire a mutex in the DB_ENV create path.
*/
dbenv->tx_max = DEF_MAX_TXNS;
#ifdef HAVE_RPC
if (F_ISSET(dbenv, DB_ENV_RPCCLIENT)) {
dbenv->get_tx_max = __dbcl_get_tx_max;
dbenv->set_tx_max = __dbcl_set_tx_max;
dbenv->get_tx_timestamp = __dbcl_get_tx_timestamp;
dbenv->set_tx_timestamp = __dbcl_set_tx_timestamp;
dbenv->txn_checkpoint = __dbcl_txn_checkpoint;
dbenv->txn_recover = __dbcl_txn_recover;
dbenv->txn_stat = __dbcl_txn_stat;
dbenv->txn_begin = __dbcl_txn_begin;
} else
#endif
{
dbenv->get_tx_max = __txn_get_tx_max;
dbenv->set_tx_max = __txn_set_tx_max;
dbenv->get_tx_timestamp = __txn_get_tx_timestamp;
dbenv->set_tx_timestamp = __txn_set_tx_timestamp;
dbenv->txn_checkpoint = __txn_checkpoint_pp;
dbenv->txn_recover = __txn_recover_pp;
dbenv->txn_stat = __txn_stat_pp;
dbenv->txn_begin = __txn_begin_pp;
dbenv->txn_dump_ltrans = __txn_dump_ltrans;
dbenv->lowest_logical_lsn = __txn_ltrans_find_lowest_lsn;
dbenv->ltran_count = __txn_count_ltrans;
dbenv->get_ltran_list = __txn_get_ltran_list;
dbenv->set_logical_start = __txn_set_logical_start;
dbenv->set_logical_commit = __txn_set_logical_commit;
dbenv->txn_begin_set_retries = __txn_begin_set_retries_pp;
}
}
static int
__txn_set_logical_start(dbenv, l_start)
DB_ENV *dbenv;
int (*l_start) __P((DB_ENV *, void *state, u_int64_t ltranid,
DB_LSN *lsn));
{
PANIC_CHECK(dbenv);
if (l_start == NULL) {
__db_err(dbenv,
"DB_ENV->set_logical_start no start function specified");
return (EINVAL);
}
dbenv->txn_logical_start = l_start;
return (0);
}
static int
__txn_set_logical_commit(dbenv, l_commit)
DB_ENV *dbenv;
int (*l_commit) __P((DB_ENV *, void *state, u_int64_t ltranid,
DB_LSN *lsn));
{
PANIC_CHECK(dbenv);
if (l_commit == NULL) {
__db_err(dbenv,
"DB_ENV->set_logical_commit no commit function specified");
return (EINVAL);
}
dbenv->txn_logical_commit = l_commit;
return (0);
}
static int
__txn_get_tx_max(dbenv, tx_maxp)
DB_ENV *dbenv;
u_int32_t *tx_maxp;
{
*tx_maxp = dbenv->tx_max;
return (0);
}
/*
* __txn_set_tx_max --
* DB_ENV->set_tx_max.
*
* PUBLIC: int __txn_set_tx_max __P((DB_ENV *, u_int32_t));
*/
int
__txn_set_tx_max(dbenv, tx_max)
DB_ENV *dbenv;
u_int32_t tx_max;
{
ENV_ILLEGAL_AFTER_OPEN(dbenv, "DB_ENV->set_tx_max");
dbenv->tx_max = tx_max;
return (0);
}
static int
__txn_get_tx_timestamp(dbenv, timestamp)
DB_ENV *dbenv;
time_t *timestamp;
{
*timestamp = dbenv->tx_timestamp;
return (0);
}
/*
* __txn_set_tx_timestamp --
* Set the transaction recovery timestamp.
*/
static int
__txn_set_tx_timestamp(dbenv, timestamp)
DB_ENV *dbenv;
time_t *timestamp;
{
ENV_ILLEGAL_AFTER_OPEN(dbenv, "DB_ENV->set_tx_timestamp");
dbenv->tx_timestamp = *timestamp;
return (0);
}
static inline void
__txn_print_ltrans(dbenv, lt, f, flags)
DB_ENV *dbenv;
LTDESC *lt;
FILE *f;
u_int32_t flags;
{
logmsg(LOGMSG_USER, "LTRANID %016llx ACTIVE-TXN %4d\n", lt->ltranid,
lt->active_txn_count);
}
static void
__txn_dump_ltrans(dbenv, f, flags)
DB_ENV *dbenv;
FILE *f;
u_int32_t flags;
{
LTDESC *lt, *lttemp;
pthread_mutex_lock(&dbenv->ltrans_active_lk);
logmsg(LOGMSG_USER, "%4d ACTIVE LOGICAL TRANSACTIONS\n",
listc_size(&dbenv->active_ltrans));
LISTC_FOR_EACH_SAFE(&dbenv->active_ltrans, lt, lttemp, lnk) {
__txn_print_ltrans(dbenv, lt, f, flags);
}
pthread_mutex_unlock(&dbenv->ltrans_active_lk);
}