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 <stdint.h>
42
43#include "ft/cachetable/cachetable.h"
44
45//Effect: Change [end checkpoint (n) - begin checkpoint (n+1)] delay to
46// new_period seconds. 0 means disable.
47void toku_set_checkpoint_period(CACHETABLE ct, uint32_t new_period);
48
49uint32_t toku_get_checkpoint_period_unlocked(CACHETABLE ct);
50
51
52/******
53 *
54 * NOTE: checkpoint_safe_lock is highest level lock
55 * multi_operation_lock is next level lock
56 * ydb_big_lock is next level lock
57 *
58 * Locks must always be taken in this sequence (highest level first).
59 *
60 */
61
62
63/******
64 * Client code must hold the checkpoint_safe lock during the following operations:
65 * - delete a dictionary via DB->remove
66 * - delete a dictionary via DB_TXN->abort(txn) (where txn created a dictionary)
67 * - rename a dictionary //TODO: Handlerton rename needs to take this
68 * //TODO: Handlerton rename needs to be recoded for transaction recovery
69 *****/
70
71void toku_checkpoint_safe_client_lock(void);
72
73void toku_checkpoint_safe_client_unlock(void);
74
75
76
77/******
78 * These functions are called from the ydb level.
79 * Client code must hold the multi_operation lock during the following operations:
80 * - insertion into multiple indexes
81 * - replace into (simultaneous delete/insert on a single key)
82 *****/
83
84void toku_multi_operation_client_lock(void);
85void toku_low_priority_multi_operation_client_lock(void);
86
87void toku_multi_operation_client_unlock(void);
88void toku_low_priority_multi_operation_client_unlock(void);
89
90
91// Initialize the checkpoint mechanism, must be called before any client operations.
92// Must pass in function pointers to take/release ydb lock.
93void toku_checkpoint_init(void);
94
95void toku_checkpoint_destroy(void);
96
97typedef enum {SCHEDULED_CHECKPOINT = 0, // "normal" checkpoint taken on checkpoint thread
98 CLIENT_CHECKPOINT = 1, // induced by client, such as FLUSH LOGS or SAVEPOINT
99 INDEXER_CHECKPOINT = 2,
100 STARTUP_CHECKPOINT = 3,
101 UPGRADE_CHECKPOINT = 4,
102 RECOVERY_CHECKPOINT = 5,
103 SHUTDOWN_CHECKPOINT = 6} checkpoint_caller_t;
104
105// Take a checkpoint of all currently open dictionaries
106// Callbacks are called during checkpoint procedure while checkpoint_safe lock is still held.
107// Callbacks are primarily intended for use in testing.
108// caller_id identifies why the checkpoint is being taken.
109int toku_checkpoint(CHECKPOINTER cp, struct tokulogger *logger,
110 void (*callback_f)(void *extra), void *extra,
111 void (*callback2_f)(void *extra2), void *extra2,
112 checkpoint_caller_t caller_id);
113
114/******
115 * These functions are called from the ydb level.
116 * They return status information and have no side effects.
117 * Some status information may be incorrect because no locks are taken to collect status.
118 * (If checkpoint is in progress, it may overwrite status info while it is being read.)
119 *****/
120void toku_checkpoint_get_status(CACHETABLE ct, CHECKPOINT_STATUS stat);
121