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 | /*====== |
5 | This file is part of PerconaFT. |
6 | |
7 | |
8 | Copyright (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 | #pragma once |
40 | |
41 | #include "ft/cachetable/cachetable.h" |
42 | #include "ft/serialize/sub_block.h" |
43 | #include "ft/txn/txn.h" |
44 | |
45 | #include "util/memarena.h" |
46 | |
47 | typedef struct rollback_log_node *ROLLBACK_LOG_NODE; |
48 | typedef struct serialized_rollback_log_node *SERIALIZED_ROLLBACK_LOG_NODE; |
49 | |
50 | void toku_poll_txn_progress_function(TOKUTXN txn, uint8_t is_commit, uint8_t stall_for_checkpoint); |
51 | |
52 | // these functions assert internally that they succeed |
53 | |
54 | // get a rollback node this txn may use for a new entry. if there |
55 | // is a current rollback node to use, pin it, otherwise create one. |
56 | void toku_get_and_pin_rollback_log_for_new_entry(TOKUTXN txn, ROLLBACK_LOG_NODE *log); |
57 | |
58 | // get a specific rollback by blocknum |
59 | void toku_get_and_pin_rollback_log(TOKUTXN txn, BLOCKNUM blocknum, ROLLBACK_LOG_NODE *log); |
60 | |
61 | // unpin a rollback node from the cachetable |
62 | void toku_rollback_log_unpin(TOKUTXN txn, ROLLBACK_LOG_NODE log); |
63 | |
64 | // assert that the given log's txnid and sequence match the ones given |
65 | void toku_rollback_verify_contents(ROLLBACK_LOG_NODE log, TXNID_PAIR txnid, uint64_t sequence); |
66 | |
67 | // if there is a previous rollback log for the given log node, prefetch it |
68 | void toku_maybe_prefetch_previous_rollback_log(TOKUTXN txn, ROLLBACK_LOG_NODE log); |
69 | |
70 | // unpin and rmove a rollback log from the cachetable |
71 | void toku_rollback_log_unpin_and_remove(TOKUTXN txn, ROLLBACK_LOG_NODE log); |
72 | |
73 | void *toku_malloc_in_rollback(ROLLBACK_LOG_NODE log, size_t size); |
74 | void *toku_memdup_in_rollback(ROLLBACK_LOG_NODE log, const void *v, size_t len); |
75 | |
76 | // given a transaction and a log node, and if the log is too full, |
77 | // set the current rollback log to ROLLBACK_NONE and move the current |
78 | // node onto the tail of the rollback node chain. further insertions |
79 | // into the rollback log for this transaction will force the creation |
80 | // of a new rollback log. |
81 | // |
82 | // this never unpins the rollback log if a spill occurs. the caller |
83 | // is responsible for ensuring the given rollback node is unpinned |
84 | // if necessary. |
85 | void toku_maybe_spill_rollbacks(TOKUTXN txn, ROLLBACK_LOG_NODE log); |
86 | |
87 | void toku_txn_maybe_note_ft (TOKUTXN txn, struct ft *ft); |
88 | int toku_logger_txn_rollback_stats(TOKUTXN txn, struct txn_stat *txn_stat); |
89 | |
90 | int toku_find_xid_by_xid (const TXNID &xid, const TXNID &xidfind); |
91 | |
92 | PAIR_ATTR rollback_memory_size(ROLLBACK_LOG_NODE log); |
93 | |
94 | // A high-level rollback log is made up of a chain of rollback log nodes. |
95 | // Each rollback log node is represented (separately) in the cachetable by |
96 | // this structure. Each portion of the rollback log chain has a block num |
97 | // and a hash to identify it. |
98 | struct rollback_log_node { |
99 | int layout_version; |
100 | int layout_version_original; |
101 | int layout_version_read_from_disk; |
102 | uint32_t build_id; // build_id (svn rev number) of software that wrote this node to disk |
103 | int dirty; |
104 | // to which transaction does this node belong? |
105 | TXNID_PAIR txnid; |
106 | // sequentially, where in the rollback log chain is this node? |
107 | // the sequence is between 0 and totalnodes-1 |
108 | uint64_t sequence; |
109 | BLOCKNUM blocknum; // on which block does this node live? |
110 | // which block number is the previous in the chain of rollback nodes |
111 | // that make up this rollback log? |
112 | BLOCKNUM previous; |
113 | struct roll_entry *oldest_logentry; |
114 | struct roll_entry *newest_logentry; |
115 | memarena rollentry_arena; |
116 | size_t rollentry_resident_bytecount; // How many bytes for the rollentries that are stored in main memory. |
117 | PAIR ct_pair; |
118 | }; |
119 | |
120 | struct serialized_rollback_log_node { |
121 | char *data; |
122 | uint32_t len; |
123 | int n_sub_blocks; |
124 | BLOCKNUM blocknum; |
125 | struct sub_block sub_block[max_sub_blocks]; |
126 | }; |
127 | typedef struct serialized_rollback_log_node *SERIALIZED_ROLLBACK_LOG_NODE; |
128 | |
129 | static inline void |
130 | toku_static_serialized_rollback_log_destroy(SERIALIZED_ROLLBACK_LOG_NODE log) { |
131 | toku_free(log->data); |
132 | } |
133 | |
134 | static inline void |
135 | toku_serialized_rollback_log_destroy(SERIALIZED_ROLLBACK_LOG_NODE log) { |
136 | toku_static_serialized_rollback_log_destroy(log); |
137 | toku_free(log); |
138 | } |
139 | |
140 | void rollback_empty_log_init(ROLLBACK_LOG_NODE log); |
141 | void make_rollback_log_empty(ROLLBACK_LOG_NODE log); |
142 | |
143 | static inline bool rollback_log_is_unused(ROLLBACK_LOG_NODE log) { |
144 | return (log->txnid.parent_id64 == TXNID_NONE); |
145 | } |
146 | |