/* -*- mode: C; c-basic-offset: 4 -*- */ #ifndef CACHETABLE_H #define CACHETABLE_H #ident "$Id$" #ident "Copyright (c) 2007-2010 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 "brttypes.h" #include "workqueue.h" #if defined(__cplusplus) || defined(__cilkplusplus) extern "C" { #endif // 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; int toku_set_cleaner_period (CACHETABLE ct, u_int32_t new_period); u_int32_t toku_get_cleaner_period (CACHETABLE ct); u_int32_t toku_get_cleaner_period_unlocked (CACHETABLE ct); int toku_set_cleaner_iterations (CACHETABLE ct, u_int32_t new_iterations); u_int32_t toku_get_cleaner_iterations (CACHETABLE ct); u_int32_t toku_get_cleaner_iterations_unlocked (CACHETABLE ct); // cachetable operations int toku_create_cachetable(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. // 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); // return the fd int toku_cachefile_fd(CACHEFILE cf); // TODO: #1510 Add comments on how these behave int toku_cachetable_begin_checkpoint (CACHETABLE ct, TOKULOGGER); int toku_cachetable_end_checkpoint(CACHETABLE ct, TOKULOGGER logger, void (*ydb_lock)(void), void (*ydb_unlock)(void), 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); // Wait for the cachefile's background work to finish. void toku_cachefile_wait_for_background_work_to_quiesce(CACHEFILE cf); // Close the cachetable. // Effects: All of the memory objects are flushed to disk, and the cachetable is destroyed. int toku_cachetable_close (CACHETABLE*); /* Flushes everything to disk, and destroys the cachetable. */ // 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); // Returns the limit on the cachetable size uint64_t toku_cachetable_get_size_limit(CACHETABLE ct); // Bind a file to a new cachefile object. int toku_cachetable_openfd (CACHEFILE *,CACHETABLE, int /*fd*/, const char *fname_relative_to_env); /*(used for logging)*/ int toku_cachetable_openfd_with_filenum (CACHEFILE *,CACHETABLE, int /*fd*/, const char *fname_in_env, BOOL with_filenum, FILENUM filenum, BOOL reserved); int toku_cachetable_reserve_filenum (CACHETABLE ct, FILENUM *reserved_filenum, BOOL with_filenum, FILENUM filenum); void toku_cachetable_unreserve_filenum (CACHETABLE ct, FILENUM reserved_filenum); // 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