| 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 <db.h> |
| 42 | |
| 43 | #include "ft/cachetable/cachetable.h" |
| 44 | #include "ft/ft-ops.h" |
| 45 | #include "ft/logger/log.h" |
| 46 | #include "util/dbt.h" |
| 47 | |
| 48 | typedef struct ft *FT; |
| 49 | typedef struct ft_options *FT_OPTIONS; |
| 50 | |
| 51 | // unlink a ft from the filesystem with or without a txn. |
| 52 | // if with a txn, then the unlink happens on commit. |
| 53 | void toku_ft_unlink(FT_HANDLE handle); |
| 54 | void toku_ft_unlink_on_commit(FT_HANDLE handle, TOKUTXN txn); |
| 55 | |
| 56 | int toku_ft_rename_iname(DB_TXN *txn, |
| 57 | const char *data_dir, |
| 58 | const char *old_iname, |
| 59 | const char *new_iname, |
| 60 | CACHETABLE ct); |
| 61 | |
| 62 | void toku_ft_init_reflock(FT ft); |
| 63 | void toku_ft_destroy_reflock(FT ft); |
| 64 | void toku_ft_grab_reflock(FT ft); |
| 65 | void toku_ft_release_reflock(FT ft); |
| 66 | |
| 67 | void toku_ft_lock(struct ft *ft); |
| 68 | void toku_ft_unlock(struct ft *ft); |
| 69 | |
| 70 | void toku_ft_create(FT *ftp, FT_OPTIONS options, CACHEFILE cf, TOKUTXN txn); |
| 71 | void toku_ft_free (FT ft); |
| 72 | |
| 73 | int toku_read_ft_and_store_in_cachefile (FT_HANDLE ft_h, CACHEFILE cf, LSN max_acceptable_lsn, FT *); |
| 74 | void toku_ft_note_ft_handle_open(FT ft, FT_HANDLE live); |
| 75 | |
| 76 | bool toku_ft_needed_unlocked(FT ft); |
| 77 | bool toku_ft_has_one_reference_unlocked(FT ft); |
| 78 | |
| 79 | // evict a ft from memory by closing its cachefile. any future work |
| 80 | // will have to read in the ft in a new cachefile and new FT object. |
| 81 | void toku_ft_evict_from_memory(FT ft, bool oplsn_valid, LSN oplsn); |
| 82 | |
| 83 | FT_HANDLE toku_ft_get_only_existing_ft_handle(FT ft); |
| 84 | |
| 85 | void toku_ft_note_hot_begin(FT_HANDLE ft_h); |
| 86 | void toku_ft_note_hot_complete(FT_HANDLE ft_h, bool success, MSN msn_at_start_of_hot); |
| 87 | |
| 88 | void |
| 89 | toku_ft_init( |
| 90 | FT ft, |
| 91 | BLOCKNUM root_blocknum_on_disk, |
| 92 | LSN checkpoint_lsn, |
| 93 | TXNID root_xid_that_created, |
| 94 | uint32_t target_nodesize, |
| 95 | uint32_t target_basementnodesize, |
| 96 | enum toku_compression_method compression_method, |
| 97 | uint32_t fanout |
| 98 | ); |
| 99 | |
| 100 | int toku_dictionary_redirect_abort(FT old_h, FT new_h, TOKUTXN txn) __attribute__ ((warn_unused_result)); |
| 101 | int toku_dictionary_redirect (const char *dst_fname_in_env, FT_HANDLE old_ft, TOKUTXN txn); |
| 102 | void toku_reset_root_xid_that_created(FT ft, TXNID new_root_xid_that_created); |
| 103 | // Reset the root_xid_that_created field to the given value. |
| 104 | // This redefines which xid created the dictionary. |
| 105 | |
| 106 | void toku_ft_add_txn_ref(FT ft); |
| 107 | void toku_ft_remove_txn_ref(FT ft); |
| 108 | |
| 109 | void toku_calculate_root_offset_pointer (FT ft, CACHEKEY* root_key, uint32_t *roothash); |
| 110 | void toku_ft_set_new_root_blocknum(FT ft, CACHEKEY new_root_key); |
| 111 | LSN toku_ft_checkpoint_lsn(FT ft) __attribute__ ((warn_unused_result)); |
| 112 | void toku_ft_stat64 (FT ft, struct ftstat64_s *s); |
| 113 | void toku_ft_get_fractal_tree_info64 (FT ft, struct ftinfo64 *s); |
| 114 | int toku_ft_iterate_fractal_tree_block_map(FT ft, int (*iter)(uint64_t,int64_t,int64_t,int64_t,int64_t,void*), void *); |
| 115 | |
| 116 | // unconditionally set the descriptor for an open FT. can't do this when |
| 117 | // any operation has already occurred on the ft. |
| 118 | // see toku_ft_change_descriptor(), which is the transactional version |
| 119 | // used by the ydb layer. it better describes the client contract. |
| 120 | void toku_ft_update_descriptor(FT ft, DESCRIPTOR desc); |
| 121 | // use this version if the FT is not fully user-opened with a valid cachefile. |
| 122 | // this is a clean hack to get deserialization code to update a descriptor |
| 123 | // while the FT and cf are in the process of opening, for upgrade purposes |
| 124 | void toku_ft_update_descriptor_with_fd(FT ft, DESCRIPTOR desc, int fd); |
| 125 | void toku_ft_update_cmp_descriptor(FT ft); |
| 126 | |
| 127 | // get the descriptor for a ft. safe to read as long as clients honor the |
| 128 | // strict contract put forth by toku_ft_update_descriptor/toku_ft_change_descriptor |
| 129 | // essentially, there should never be a reader while there is a writer, enforced |
| 130 | // by the client, not the FT. |
| 131 | DESCRIPTOR toku_ft_get_descriptor(FT_HANDLE ft_handle); |
| 132 | DESCRIPTOR toku_ft_get_cmp_descriptor(FT_HANDLE ft_handle); |
| 133 | |
| 134 | typedef struct { |
| 135 | // delta versions in basements could be negative |
| 136 | // These represent the physical leaf entries and do not account |
| 137 | // for pending deletes or other in-flight messages that have not been |
| 138 | // applied to a leaf entry. |
| 139 | int64_t numrows; |
| 140 | int64_t numbytes; |
| 141 | } STAT64INFO_S, *STAT64INFO; |
| 142 | static const STAT64INFO_S ZEROSTATS = { .numrows = 0, .numbytes = 0 }; |
| 143 | |
| 144 | void toku_ft_update_stats(STAT64INFO , STAT64INFO_S delta); |
| 145 | void toku_ft_decrease_stats(STAT64INFO , STAT64INFO_S delta); |
| 146 | void toku_ft_adjust_logical_row_count(FT ft, int64_t delta); |
| 147 | |
| 148 | typedef void (*remove_ft_ref_callback)(FT ft, void *); |
| 149 | void toku_ft_remove_reference(FT ft, |
| 150 | bool oplsn_valid, LSN oplsn, |
| 151 | remove_ft_ref_callback remove_ref, void *); |
| 152 | |
| 153 | void toku_ft_set_nodesize(FT ft, unsigned int nodesize); |
| 154 | void toku_ft_get_nodesize(FT ft, unsigned int *nodesize); |
| 155 | void toku_ft_set_basementnodesize(FT ft, unsigned int basementnodesize); |
| 156 | void toku_ft_get_basementnodesize(FT ft, unsigned int *basementnodesize); |
| 157 | void toku_ft_set_compression_method(FT ft, enum toku_compression_method method); |
| 158 | void toku_ft_get_compression_method(FT ft, enum toku_compression_method *methodp); |
| 159 | void toku_ft_set_fanout(FT ft, unsigned int fanout); |
| 160 | void toku_ft_get_fanout(FT ft, unsigned int *fanout); |
| 161 | |
| 162 | // mark the ft as a blackhole. any message injections will be a no op. |
| 163 | void toku_ft_set_blackhole(FT_HANDLE ft_handle); |
| 164 | |
| 165 | // Effect: Calculates the total space and used space for a FT's leaf data. |
| 166 | // The difference between the two is MVCC garbage. |
| 167 | void toku_ft_get_garbage(FT ft, uint64_t *total_space, uint64_t *used_space); |
| 168 | |
| 169 | // TODO: Should be in portability |
| 170 | int get_num_cores(void); |
| 171 | |
| 172 | // TODO: Use the cachetable's worker pool instead of something managed by the FT... |
| 173 | struct toku_thread_pool *get_ft_pool(void); |
| 174 | |
| 175 | // TODO: Should be in portability |
| 176 | int toku_single_process_lock(const char *lock_dir, const char *which, int *lockfd); |
| 177 | int toku_single_process_unlock(int *lockfd); |
| 178 | |
| 179 | void tokuft_update_product_name_strings(void); |
| 180 | #define TOKU_MAX_PRODUCT_NAME_LENGTH (256) |
| 181 | extern char toku_product_name[TOKU_MAX_PRODUCT_NAME_LENGTH]; |
| 182 | |
| 183 | struct toku_product_name_strings_struct { |
| 184 | char db_version[sizeof(toku_product_name) + sizeof("1.2.3 build " ) + 256]; |
| 185 | char environmentdictionary[sizeof(toku_product_name) + sizeof(".environment" )]; |
| 186 | char fileopsdirectory[sizeof(toku_product_name) + sizeof(".directory" )]; |
| 187 | char single_process_lock[sizeof(toku_product_name) + sizeof("___lock_dont_delete_me" )]; |
| 188 | char rollback_cachefile[sizeof(toku_product_name) + sizeof(".rollback" )]; |
| 189 | }; |
| 190 | |
| 191 | extern struct toku_product_name_strings_struct toku_product_name_strings; |
| 192 | extern int tokuft_num_envs; |
| 193 | |