/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: #ifndef CACHETABLE_H #define CACHETABLE_H #ident "$Id$" /* COPYING CONDITIONS NOTICE: This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation, and provided that the following conditions are met: * Redistributions of source code must retain this COPYING CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the PATENT MARKING NOTICE (below), and the PATENT RIGHTS GRANT (below). * Redistributions in binary form must reproduce this COPYING CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the PATENT MARKING NOTICE (below), and the PATENT RIGHTS GRANT (below) in the documentation and/or other materials provided with the distribution. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. COPYRIGHT NOTICE: TokuDB, Tokutek Fractal Tree Indexing Library. Copyright (C) 2007-2013 Tokutek, Inc. DISCLAIMER: This program 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. UNIVERSITY PATENT NOTICE: The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it. PATENT MARKING NOTICE: This software is covered by US Patent No. 8,185,551. This software is covered by US Patent No. 8,489,638. PATENT RIGHTS GRANT: "THIS IMPLEMENTATION" means the copyrightable works distributed by Tokutek as part of the Fractal Tree project. "PATENT CLAIMS" means the claims of patents that are owned or licensable by Tokutek, both currently or in the future; and that in the absence of this license would be infringed by THIS IMPLEMENTATION or by using or running THIS IMPLEMENTATION. "PATENT CHALLENGE" shall mean a challenge to the validity, patentability, enforceability and/or non-infringement of any of the PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS. Tokutek hereby grants to you, for the term and geographical scope of the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, transfer, and otherwise run, modify, and propagate the contents of THIS IMPLEMENTATION, where such license applies only to the PATENT CLAIMS. This grant does not include claims that would be infringed only as a consequence of further modifications of THIS IMPLEMENTATION. If you or your agent or licensee institute or order or agree to the institution of patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that THIS IMPLEMENTATION constitutes direct or contributory patent infringement, or inducement of patent infringement, then any rights granted to you under this License shall terminate as of the date such litigation is filed. If you or your agent or exclusive licensee institute or order or agree to the institution of a PATENT CHALLENGE, then Tokutek may terminate any rights granted to you under this License. */ #ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved." #ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it." #include #include "fttypes.h" #include "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; 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); // 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(CACHETABLE *result, long size_limit, LSN initial_lsn, TOKULOGGER); // 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, TOKULOGGER); void toku_cachetable_end_checkpoint(CHECKPOINTER cp, 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); // 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