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
43// A leaf entry cursor (LE_CURSOR) is a special type of FT_CURSOR that visits all of the leaf entries in a tree
44// and returns the leaf entry to the caller. It maintains a copy of the key that it was last positioned over to
45// speed up key comparisions with a given key. For example, the hot indexing could use the _key_right_of_cursor
46// function to determine where a given key sits relative to the LE_CURSOR position.
47
48// When _next and _key_right_of_cursor functions are run on multiple threads, they must be protected by a lock. This
49// lock is assumed to exist outside of the LE_CURSOR.
50
51typedef struct le_cursor *LE_CURSOR;
52
53// Create a leaf cursor for a tree (ft_h) within a transaction (txn)
54// Success: returns 0, stores the LE_CURSOR in the le_cursor_result
55// Failure: returns a non-zero error number
56int toku_le_cursor_create(LE_CURSOR *le_cursor_result, FT_HANDLE ft_h, TOKUTXN txn);
57
58// Close and free the LE_CURSOR
59void toku_le_cursor_close(LE_CURSOR le_cursor);
60
61// Move to the next leaf entry under the LE_CURSOR
62// Success: returns zero, calls the getf callback with the getf_v parameter
63// Failure: returns a non-zero error number
64int toku_le_cursor_next(LE_CURSOR le_cursor, FT_GET_CALLBACK_FUNCTION getf, void *getf_v);
65
66// Return true if the key is to the right of the LE_CURSOR position. that is, current cursor key < given key
67// Otherwise returns false when the key is at or to the left of the LE_CURSOR position. that is, current cursor key >= given key
68// The LE_CURSOR position is intialized to -infinity. Any key comparision with -infinity returns true.
69// When the cursor runs off the right edge of the tree, the LE_CURSOR position is set to +infinity. Any key comparision with +infinity
70// returns false.
71bool toku_le_cursor_is_key_greater_or_equal(LE_CURSOR le_cursor, const DBT *key);
72
73// extracts position of le_cursor into estimate. Responsibility of caller to handle
74// thread safety. Caller (the indexer), does so by ensuring indexer lock is held
75void toku_le_cursor_update_estimate(LE_CURSOR le_cursor, DBT* estimate);
76