1/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
3#ident "$Id$"
4/*======
5This file is part of PerconaFT.
6
7
8Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
9
10 PerconaFT is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License, version 2,
12 as published by the Free Software Foundation.
13
14 PerconaFT is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with PerconaFT. If not, see <http://www.gnu.org/licenses/>.
21
22----------------------------------------
23
24 PerconaFT is free software: you can redistribute it and/or modify
25 it under the terms of the GNU Affero General Public License, version 3,
26 as published by the Free Software Foundation.
27
28 PerconaFT is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU Affero General Public License for more details.
32
33 You should have received a copy of the GNU Affero General Public License
34 along with PerconaFT. If not, see <http://www.gnu.org/licenses/>.
35======= */
36
37#ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."
38
39/* Purpose of this file is to provide the world with everything necessary
40 * to use the xids and nothing else.
41 * Internal requirements of the xids logic do not belong here.
42 *
43 * xids is (abstractly) an immutable list of nested transaction ids, accessed only
44 * via the functions in this file.
45 *
46 * See design documentation for nested transactions at
47 * TokuWiki/Imp/TransactionsOverview.
48 */
49
50#pragma once
51
52#include "ft/txn/txn.h"
53#include "ft/serialize/rbuf.h"
54#include "ft/serialize/wbuf.h"
55
56/* The number of transaction ids stored in the xids structure is
57 * represented by an 8-bit value. The value 255 is reserved.
58 * The constant MAX_NESTED_TRANSACTIONS is one less because
59 * one slot in the packed leaf entry is used for the implicit
60 * root transaction (id 0).
61 */
62enum {
63 MAX_NESTED_TRANSACTIONS = 253,
64 MAX_TRANSACTION_RECORDS = MAX_NESTED_TRANSACTIONS + 1
65};
66
67// Variable size list of transaction ids (known in design doc as xids<>).
68// ids[0] is the outermost transaction.
69// ids[num_xids - 1] is the innermost transaction.
70// Should only be accessed by accessor functions toku_xids_xxx, not directly.
71
72// If the xids struct is unpacked, the compiler aligns the ids[] and we waste a lot of space
73struct __attribute__((__packed__)) XIDS_S {
74 // maximum value of MAX_TRANSACTION_RECORDS - 1 because transaction 0 is implicit
75 uint8_t num_xids;
76 TXNID ids[];
77};
78typedef struct XIDS_S *XIDS;
79
80// Retrieve an XIDS representing the root transaction.
81XIDS toku_xids_get_root_xids(void);
82
83bool toku_xids_can_create_child(XIDS xids);
84
85void toku_xids_cpy(XIDS target, XIDS source);
86
87//Creates an XIDS representing this transaction.
88//You must pass in an XIDS representing the parent of this transaction.
89int toku_xids_create_child(XIDS parent_xids, XIDS *xids_p, TXNID this_xid);
90
91// The following two functions (in order) are equivalent to toku_xids_create child,
92// but allow you to do most of the work without knowing the new xid.
93int toku_xids_create_unknown_child(XIDS parent_xids, XIDS *xids_p);
94void toku_xids_finalize_with_child(XIDS xids, TXNID this_xid);
95
96void toku_xids_create_from_buffer(struct rbuf *rb, XIDS *xids_p);
97
98void toku_xids_destroy(XIDS *xids_p);
99
100TXNID toku_xids_get_xid(XIDS xids, uint8_t index);
101
102uint8_t toku_xids_get_num_xids(XIDS xids);
103
104TXNID toku_xids_get_innermost_xid(XIDS xids);
105TXNID toku_xids_get_outermost_xid(XIDS xids);
106
107// return size in bytes
108uint32_t toku_xids_get_size(XIDS xids);
109
110uint32_t toku_xids_get_serialize_size(XIDS xids);
111
112unsigned char *toku_xids_get_end_of_array(XIDS xids);
113
114void wbuf_nocrc_xids(struct wbuf *wb, XIDS xids);
115
116void toku_xids_fprintf(FILE* fp, XIDS xids);
117