From a175314c3e5827eb193872241446f2f8f5c9d33c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 20:07:14 +0200 Subject: Adding upstream version 1:10.5.12. Signed-off-by: Daniel Baumann --- .../tokudb/PerconaFT/ft/cachetable/cachetable.h | 588 +++++++++++++++++++++ 1 file changed, 588 insertions(+) create mode 100644 storage/tokudb/PerconaFT/ft/cachetable/cachetable.h (limited to 'storage/tokudb/PerconaFT/ft/cachetable/cachetable.h') diff --git a/storage/tokudb/PerconaFT/ft/cachetable/cachetable.h b/storage/tokudb/PerconaFT/ft/cachetable/cachetable.h new file mode 100644 index 00000000..c5c21b49 --- /dev/null +++ b/storage/tokudb/PerconaFT/ft/cachetable/cachetable.h @@ -0,0 +1,588 @@ +/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: +#ident "$Id$" +/*====== +This file is part of PerconaFT. + + +Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. + + PerconaFT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2, + as published by the Free Software Foundation. + + PerconaFT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with PerconaFT. If not, see . + +---------------------------------------- + + PerconaFT is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License, version 3, + as published by the Free Software Foundation. + + PerconaFT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with PerconaFT. If not, see . +======= */ + +#ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved." + +#pragma once + +#include + +#include "ft/logger/logger.h" +#include "ft/serialize/block_table.h" +#include "ft/txn/txn.h" +#include "ft/ft-status.h" +#include "util/minicron.h" + +// Maintain a cache mapping from cachekeys to values (void*) +// Some of the keys can be pinned. Don't pin too many or for too long. +// If the cachetable is too full, it will call the flush_callback() function with the key, the value, and the otherargs +// and then remove the key-value pair from the cache. +// The callback won't be any of the currently pinned keys. +// Also when flushing an object, the cachetable drops all references to it, +// so you may need to free() it. +// Note: The cachetable should use a common pool of memory, flushing things across cachetables. +// (The first implementation doesn't) +// If you pin something twice, you must unpin it twice. +// table_size is the initial size of the cache table hash table (in number of entries) +// size limit is the upper bound of the sum of size of the entries in the cache table (total number of bytes) + +typedef BLOCKNUM CACHEKEY; + +class checkpointer; +typedef class checkpointer *CHECKPOINTER; +typedef struct cachetable *CACHETABLE; +typedef struct cachefile *CACHEFILE; +typedef struct ctpair *PAIR; + +// This struct hold information about values stored in the cachetable. +// As one can tell from the names, we are probably violating an +// abstraction layer by placing names. +// +// The purpose of having this struct is to have a way for the +// cachetable to accumulate the some totals we are interested in. +// Breaking this abstraction layer by having these names was the +// easiest way. +// +typedef struct pair_attr_s { + long size; // size PAIR's value takes in memory + long nonleaf_size; // size if PAIR is a nonleaf node, 0 otherwise, used only for engine status + long leaf_size; // size if PAIR is a leaf node, 0 otherwise, used only for engine status + long rollback_size; // size of PAIR is a rollback node, 0 otherwise, used only for engine status + long cache_pressure_size; // amount PAIR contributes to cache pressure, is sum of buffer sizes and workdone counts + bool is_valid; +} PAIR_ATTR; + +static inline PAIR_ATTR make_pair_attr(long size) { + PAIR_ATTR result={ + .size = size, + .nonleaf_size = 0, + .leaf_size = 0, + .rollback_size = 0, + .cache_pressure_size = 0, + .is_valid = true + }; + return result; +} + +void toku_set_cleaner_period (CACHETABLE ct, uint32_t new_period); +uint32_t toku_get_cleaner_period_unlocked (CACHETABLE ct); +void toku_set_cleaner_iterations (CACHETABLE ct, uint32_t new_iterations); +uint32_t toku_get_cleaner_iterations (CACHETABLE ct); +uint32_t toku_get_cleaner_iterations_unlocked (CACHETABLE ct); +void toku_set_enable_partial_eviction (CACHETABLE ct, bool enabled); +bool toku_get_enable_partial_eviction (CACHETABLE ct); + +// cachetable operations + +// create and initialize a cache table +// size_limit is the upper limit on the size of the size of the values in the table +// pass 0 if you want the default +int toku_cachetable_create_ex(CACHETABLE *result, long size_limit, + unsigned long client_pool_threads, + unsigned long cachetable_pool_threads, + unsigned long checkpoint_pool_threads, + LSN initial_lsn, struct tokulogger *logger); + +#define toku_cachetable_create(r, s, l, o) \ + toku_cachetable_create_ex(r, s, 0, 0, 0, l, o); + +// Create a new cachetable. +// Effects: a new cachetable is created and initialized. +// The cachetable pointer is stored into result. +// The sum of the sizes of the memory objects is set to size_limit, in whatever +// units make sense to the user of the cachetable. +// Returns: If success, returns 0 and result points to the new cachetable. Otherwise, +// returns an error number. + +// Returns a pointer to the checkpointer within the given cachetable. +CHECKPOINTER toku_cachetable_get_checkpointer(CACHETABLE ct); + +// What is the cachefile that goes with a particular filenum? +// During a transaction, we cannot reuse a filenum. +int toku_cachefile_of_filenum (CACHETABLE t, FILENUM filenum, CACHEFILE *cf); + +// What is the cachefile that goes with a particular iname (relative to env)? +// During a transaction, we cannot reuse an iname. +int toku_cachefile_of_iname_in_env (CACHETABLE ct, const char *iname_in_env, CACHEFILE *cf); + +// Get the iname (within the cwd) associated with the cachefile +// Return the filename +char *toku_cachefile_fname_in_cwd (CACHEFILE cf); + +void toku_cachetable_begin_checkpoint (CHECKPOINTER cp, struct tokulogger *logger); + +void toku_cachetable_end_checkpoint(CHECKPOINTER cp, struct tokulogger *logger, + void (*testcallback_f)(void*), void * testextra); + + +// Shuts down checkpoint thread +// Requires no locks be held that are taken by the checkpoint function +void toku_cachetable_minicron_shutdown(CACHETABLE ct); + +// Prepare to close the cachetable. This informs the cachetable that it is about to be closed +// so that it can tune its checkpoint resource use. +void toku_cachetable_prepare_close(CACHETABLE ct); + +// Close the cachetable. +// Effects: All of the memory objects are flushed to disk, and the cachetable is destroyed. +void toku_cachetable_close(CACHETABLE *ct); + +// Open a file and bind the file to a new cachefile object. (For use by test programs only.) +int toku_cachetable_openf(CACHEFILE *,CACHETABLE, const char *fname_in_env, int flags, mode_t mode); + +// Bind a file to a new cachefile object. +int toku_cachetable_openfd(CACHEFILE *,CACHETABLE, int fd, + const char *fname_relative_to_env); +int toku_cachetable_openfd_with_filenum (CACHEFILE *,CACHETABLE, int fd, + const char *fname_in_env, + FILENUM filenum, bool* was_open); + +// reserve a unique filenum +FILENUM toku_cachetable_reserve_filenum(CACHETABLE ct); + +// Effect: Reserve a fraction of the cachetable memory. +// Returns the amount reserved. +// To return the memory to the cachetable, call toku_cachetable_release_reserved_memory +// Requires 0