summaryrefslogtreecommitdiff
path: root/db/db/db_cds.c
blob: 433ce3638e8ff5b9876ddc26d39d286111a70ba6 (plain)
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
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2000,2007 Oracle.  All rights reserved.
 *
 * $Id: db_cds.c,v 12.10 2007/07/17 07:29:04 mjc Exp $
 */

#include "db_config.h"

#include "db_int.h"
#include "dbinc/db_page.h"
#include "dbinc/db_am.h"
#include "dbinc/lock.h"
#include "dbinc/txn.h"

static int __cdsgroup_abort __P((DB_TXN *txn));
static int __cdsgroup_commit __P((DB_TXN *txn, u_int32_t flags));
static int __cdsgroup_discard __P((DB_TXN *txn, u_int32_t flags));
static u_int32_t __cdsgroup_id __P((DB_TXN *txn));
static int __cdsgroup_notsup __P((DB_ENV *dbenv, const char *meth));
static int __cdsgroup_prepare __P((DB_TXN *txn, u_int8_t *gid));
static int __cdsgroup_set_name __P((DB_TXN *txn, const char *name));
static int __cdsgroup_set_timeout
    __P((DB_TXN *txn, db_timeout_t timeout, u_int32_t flags));

/*
 * __cdsgroup_notsup --
 *	Error when CDS groups don't support a method.
 */
static int
__cdsgroup_notsup(dbenv, meth)
	DB_ENV *dbenv;
	const char *meth;
{
	__db_errx(dbenv, "CDS groups do not support %s", meth);
	return (DB_OPNOTSUP);
}

static int __cdsgroup_abort(txn)
	DB_TXN *txn;
{
	return (__cdsgroup_notsup(txn->mgrp->dbenv, "abort"));
}

static int __cdsgroup_commit(txn, flags)
	DB_TXN *txn;
	u_int32_t flags;
{
	DB_ENV *dbenv;
	DB_LOCKREQ lreq;
	DB_LOCKER *locker;
	int ret, t_ret;

	COMPQUIET(flags, 0);
	dbenv = txn->mgrp->dbenv;

	/* Check for live cursors. */
	if (txn->cursors != 0) {
		__db_errx(dbenv, "CDS group has active cursors");
		return (EINVAL);
	}

	/* We may be holding handle locks; release them. */
	lreq.op = DB_LOCK_PUT_ALL;
	lreq.obj = NULL;
	ret = __lock_vec(dbenv, txn->locker, 0, &lreq, 1, NULL);

	dbenv = txn->mgrp->dbenv;
	locker = txn->locker;
	__os_free(dbenv, txn->mgrp);
	__os_free(dbenv, txn);
	if ((t_ret = __lock_id_free(dbenv, locker)) != 0 && ret == 0)
		ret = t_ret;
	return (ret);
}

static int __cdsgroup_discard(txn, flags)
	DB_TXN *txn;
	u_int32_t flags;
{
	COMPQUIET(flags, 0);
	return (__cdsgroup_notsup(txn->mgrp->dbenv, "discard"));
}

static u_int32_t __cdsgroup_id(txn)
	DB_TXN *txn;
{
	return (txn->txnid);
}

static int __cdsgroup_prepare(txn, gid)
	DB_TXN *txn;
	u_int8_t *gid;
{
	COMPQUIET(gid, NULL);
	return (__cdsgroup_notsup(txn->mgrp->dbenv, "prepare"));
}

static int __cdsgroup_set_name(txn, name)
	DB_TXN *txn;
	const char *name;
{
	COMPQUIET(name, NULL);
	return (__cdsgroup_notsup(txn->mgrp->dbenv, "set_name"));
}

static int __cdsgroup_set_timeout(txn, timeout, flags)
	DB_TXN *txn;
	db_timeout_t timeout;
	u_int32_t flags;
{
	COMPQUIET(timeout, 0);
	COMPQUIET(flags, 0);
	return (__cdsgroup_notsup(txn->mgrp->dbenv, "set_timeout"));
}

/*
 * __cds_txn_begin --
 *	DB_ENV->cdsgroup_begin
 *
 * PUBLIC: int __cdsgroup_begin __P((DB_ENV *, DB_TXN **));
 */
int
__cdsgroup_begin(dbenv, txnpp)
	DB_ENV *dbenv;
	DB_TXN **txnpp;
{
	DB_THREAD_INFO *ip;
	DB_TXN *txn;
	int ret;

	PANIC_CHECK(dbenv);
	ENV_ILLEGAL_BEFORE_OPEN(dbenv, "cdsgroup_begin");
	if (!CDB_LOCKING(dbenv))
		return (__db_env_config(dbenv, "cdsgroup_begin", DB_INIT_CDB));

	ENV_ENTER(dbenv, ip);
	*txnpp = txn = NULL;
	if ((ret = __os_calloc(dbenv, 1, sizeof(DB_TXN), &txn)) != 0)
		goto err;
	/*
	 * We need a dummy DB_TXNMGR -- it's the only way to get from a
	 * transaction handle to the environment handle.
	 */
	if ((ret = __os_calloc(dbenv, 1, sizeof(DB_TXNMGR), &txn->mgrp)) != 0)
		goto err;
	txn->mgrp->dbenv = dbenv;

	if ((ret = __lock_id(dbenv, &txn->txnid, &txn->locker)) != 0)
		goto err;

	txn->flags = TXN_CDSGROUP;
	txn->abort = __cdsgroup_abort;
	txn->commit = __cdsgroup_commit;
	txn->discard = __cdsgroup_discard;
	txn->id = __cdsgroup_id;
	txn->prepare = __cdsgroup_prepare;
	txn->set_name = __cdsgroup_set_name;
	txn->set_timeout = __cdsgroup_set_timeout;

	*txnpp = txn;

	if (0) {
err:		if (txn != NULL) {
			if (txn->mgrp != NULL)
				__os_free(dbenv, txn->mgrp);
			__os_free(dbenv, txn);
		}
	}
	ENV_LEAVE(dbenv, ip);
	return (ret);
}