summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/src/txn/txn_ext.c
blob: 1f42ab5eb431e0cc412e19e4068169146ab9c30c (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
/*-
 * Copyright (c) 2014-2019 MongoDB, Inc.
 * Copyright (c) 2008-2014 WiredTiger, Inc.
 *	All rights reserved.
 *
 * See the file LICENSE for redistribution information.
 */

#include "wt_internal.h"

/*
 * __wt_ext_transaction_id --
 *	Return the session's transaction ID.
 */
uint64_t
__wt_ext_transaction_id(WT_EXTENSION_API *wt_api, WT_SESSION *wt_session)
{
	WT_SESSION_IMPL *session;

	(void)wt_api;					/* Unused parameters */
	session = (WT_SESSION_IMPL *)wt_session;
	/* Ignore failures: the only case is running out of transaction IDs. */
	WT_IGNORE_RET(__wt_txn_id_check(session));
	return (session->txn.id);
}

/*
 * __wt_ext_transaction_isolation_level --
 *	Return if the current transaction's isolation level.
 */
int
__wt_ext_transaction_isolation_level(
    WT_EXTENSION_API *wt_api, WT_SESSION *wt_session)
{
	WT_SESSION_IMPL *session;
	WT_TXN *txn;

	(void)wt_api;					/* Unused parameters */

	session = (WT_SESSION_IMPL *)wt_session;
	txn = &session->txn;

	if (txn->isolation == WT_ISO_READ_COMMITTED)
		return (WT_TXN_ISO_READ_COMMITTED);
	if (txn->isolation == WT_ISO_READ_UNCOMMITTED)
		return (WT_TXN_ISO_READ_UNCOMMITTED);
	return (WT_TXN_ISO_SNAPSHOT);
}

/*
 * __wt_ext_transaction_notify --
 *	Request notification of transaction resolution.
 */
int
__wt_ext_transaction_notify(
    WT_EXTENSION_API *wt_api, WT_SESSION *wt_session, WT_TXN_NOTIFY *notify)
{
	WT_SESSION_IMPL *session;
	WT_TXN *txn;

	(void)wt_api;					/* Unused parameters */

	session = (WT_SESSION_IMPL *)wt_session;
	txn = &session->txn;

	/*
	 * XXX
	 * For now, a single slot for notifications: I'm not bothering with
	 * more than one because more than one data-source in a transaction
	 * doesn't work anyway.
	 */
	if (txn->notify == notify)
		return (0);
	if (txn->notify != NULL)
		WT_RET_MSG(
		    session, WT_ERROR, "transaction notify already scheduled");

	txn->notify = notify;

	return (0);
}

/*
 * __wt_ext_transaction_oldest --
 *	Return the oldest transaction ID not yet visible to a running
 * transaction.
 */
uint64_t
__wt_ext_transaction_oldest(WT_EXTENSION_API *wt_api)
{
	return (((WT_CONNECTION_IMPL *)wt_api->conn)->txn_global.oldest_id);
}

/*
 * __wt_ext_transaction_visible --
 *	Return if the current transaction can see the given transaction ID.
 */
int
__wt_ext_transaction_visible(
    WT_EXTENSION_API *wt_api, WT_SESSION *wt_session, uint64_t transaction_id)
{
	(void)wt_api;					/* Unused parameters */

	return (__wt_txn_visible(
	    (WT_SESSION_IMPL *)wt_session, transaction_id, WT_TS_NONE));
}