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#pragma once
40
41#include "ft/cachetable/cachetable.h"
42#include "ft/ft-internal.h"
43#include "ft/node.h"
44
45/**
46 * Put an empty node (that is, no fields filled) into the cachetable.
47 * In the process, write dependent nodes out for checkpoint if
48 * necessary.
49 */
50void
51cachetable_put_empty_node_with_dep_nodes(
52 FT ft,
53 uint32_t num_dependent_nodes,
54 FTNODE* dependent_nodes,
55 BLOCKNUM* name, //output
56 uint32_t* fullhash, //output
57 FTNODE* result
58 );
59
60/**
61 * Create a new ftnode with specified height and number of children.
62 * In the process, write dependent nodes out for checkpoint if
63 * necessary.
64 */
65void
66create_new_ftnode_with_dep_nodes(
67 FT ft,
68 FTNODE *result,
69 int height,
70 int n_children,
71 uint32_t num_dependent_nodes,
72 FTNODE* dependent_nodes
73 );
74
75/**
76 * Create a new ftnode with specified height
77 * and children.
78 * Used for test functions only.
79 */
80void
81toku_create_new_ftnode (
82 FT_HANDLE t,
83 FTNODE *result,
84 int height,
85 int n_children
86 );
87
88// This function returns a pinned ftnode to the caller.
89int
90toku_pin_ftnode_for_query(
91 FT_HANDLE ft_h,
92 BLOCKNUM blocknum,
93 uint32_t fullhash,
94 UNLOCKERS unlockers,
95 ANCESTORS ancestors,
96 const pivot_bounds &bounds,
97 ftnode_fetch_extra *bfe,
98 bool apply_ancestor_messages, // this bool is probably temporary, for #3972, once we know how range query estimates work, will revisit this
99 FTNODE *node_p,
100 bool* msgs_applied
101 );
102
103// Pins an ftnode without dependent pairs
104void toku_pin_ftnode(
105 FT ft,
106 BLOCKNUM blocknum,
107 uint32_t fullhash,
108 ftnode_fetch_extra *bfe,
109 pair_lock_type lock_type,
110 FTNODE *node_p,
111 bool move_messages
112 );
113
114// Pins an ftnode with dependent pairs
115// Unlike toku_pin_ftnode_for_query, this function blocks until the node is pinned.
116void toku_pin_ftnode_with_dep_nodes(
117 FT ft,
118 BLOCKNUM blocknum,
119 uint32_t fullhash,
120 ftnode_fetch_extra *bfe,
121 pair_lock_type lock_type,
122 uint32_t num_dependent_nodes,
123 FTNODE *dependent_nodes,
124 FTNODE *node_p,
125 bool move_messages
126 );
127
128/**
129 * This function may return a pinned ftnode to the caller, if pinning is cheap.
130 * If the node is already locked, or is pending a checkpoint, the node is not pinned and -1 is returned.
131 */
132int toku_maybe_pin_ftnode_clean(FT ft, BLOCKNUM blocknum, uint32_t fullhash, pair_lock_type lock_type, FTNODE *nodep);
133
134/**
135 * Effect: Unpin an ftnode.
136 */
137void toku_unpin_ftnode(FT ft, FTNODE node);
138void toku_unpin_ftnode_read_only(FT ft, FTNODE node);
139
140// Effect: Swaps pair values of two pinned nodes
141void toku_ftnode_swap_pair_values(FTNODE nodea, FTNODE nodeb);
142