/* -*- 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$" #ident "Copyright (c) 2007-2012 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 (CACHETABLE ct); 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 void 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); // 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