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/ft-internal.h"
42
43void toku_ft_flusher_get_status(FT_FLUSHER_STATUS);
44
45/**
46 * Only for testing, not for production.
47 *
48 * Set a callback the flusher thread will use to signal various points
49 * during its execution.
50 */
51void
52toku_flusher_thread_set_callback(
53 void (*callback_f)(int, void*),
54 void* extra
55 );
56
57/**
58 * Puts a workitem on the flusher thread queue, scheduling the node to be
59 * flushed by toku_ft_flush_some_child.
60 */
61void toku_ft_flush_node_on_background_thread(FT ft, FTNODE parent);
62
63enum split_mode {
64 SPLIT_EVENLY,
65 SPLIT_LEFT_HEAVY,
66 SPLIT_RIGHT_HEAVY
67};
68
69
70// Given pinned node and pinned child, split child into two
71// and update node with information about its new child.
72void toku_ft_split_child(
73 FT ft,
74 FTNODE node,
75 int childnum,
76 FTNODE child,
77 enum split_mode split_mode
78 );
79
80// Given pinned node, merge childnum with a neighbor and update node with
81// information about the change
82void toku_ft_merge_child(
83 FT ft,
84 FTNODE node,
85 int childnum
86 );
87
88/**
89 * Effect: Split a leaf node.
90 * Argument "node" is node to be split.
91 * Upon return:
92 * nodea and nodeb point to new nodes that result from split of "node"
93 * nodea is the left node that results from the split
94 * splitk is the right-most key of nodea
95 */
96// TODO: Rename toku_ft_leaf_split
97void
98ftleaf_split(
99 FT ft,
100 FTNODE node,
101 FTNODE *nodea,
102 FTNODE *nodeb,
103 DBT *splitk,
104 bool create_new_node,
105 enum split_mode split_mode,
106 uint32_t num_dependent_nodes,
107 FTNODE* dependent_nodes
108 );
109
110/**
111 * Effect: node must be a node-leaf node. It is split into two nodes, and
112 * the fanout is split between them.
113 * Sets splitk->data pointer to a malloc'd value
114 * Sets nodea, and nodeb to the two new nodes.
115 * The caller must replace the old node with the two new nodes.
116 * This function will definitely reduce the number of children for the node,
117 * but it does not guarantee that the resulting nodes are smaller than nodesize.
118 */
119void
120// TODO: Rename toku_ft_nonleaf_split
121ft_nonleaf_split(
122 FT ft,
123 FTNODE node,
124 FTNODE *nodea,
125 FTNODE *nodeb,
126 DBT *splitk,
127 uint32_t num_dependent_nodes,
128 FTNODE* dependent_nodes
129 );
130
131/************************************************************************
132 * HOT optimize, should perhaps be factored out to its own header file *
133 ************************************************************************
134 */
135void toku_ft_hot_get_status(FT_HOT_STATUS);
136
137/**
138 * Takes given FT and pushes all pending messages between left and right to the leaf nodes.
139 * All messages between left and right (inclusive) will be pushed, as will some others
140 * that happen to share buffers with messages near the boundary.
141 * If left is NULL, messages from beginning of FT are pushed. If right is NULL, that means
142 * we go until the end of the FT.
143 */
144int
145toku_ft_hot_optimize(FT_HANDLE ft_h, DBT* left, DBT* right,
146 int (*progress_callback)(void *extra, float progress),
147 void *progress_extra, uint64_t* loops_run);
148