Drizzled Public API Documentation

keycache.h
00001 /* Copyright (C) 2003 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00015 
00016 /* Key cache variable structures */
00017 
00018 #pragma once
00019 
00020 enum flush_type
00021 {
00022   FLUSH_KEEP,           /* flush block and keep it in the cache */
00023   FLUSH_RELEASE,        /* flush block and remove it from the cache */
00024   FLUSH_IGNORE_CHANGED, /* remove block from the cache */
00025   /*
00026  *     As my_disable_flush_pagecache_blocks is always 0, the following option
00027  *         is strictly equivalent to FLUSH_KEEP
00028  *           */
00029   FLUSH_FORCE_WRITE
00030 };
00031 
00032 
00033 /* declare structures that is used by st_key_cache */
00034 
00035 struct st_block_link;
00036 typedef struct st_block_link BLOCK_LINK;
00037 struct st_keycache_page;
00038 typedef struct st_keycache_page KEYCACHE_PAGE;
00039 struct st_hash_link;
00040 typedef struct st_hash_link HASH_LINK;
00041 
00042 namespace drizzled
00043 {
00044 namespace internal
00045 {
00046 typedef uint64_t my_off_t;
00047 struct st_my_thread_var;
00048 }
00049 
00050 /* info about requests in a waiting queue */
00051 typedef struct st_keycache_wqueue
00052 {
00053   drizzled::internal::st_my_thread_var *last_thread;  /* circular list of waiting threads */
00054 } KEYCACHE_WQUEUE;
00055 
00056 #define CHANGED_BLOCKS_HASH 128             /* must be power of 2 */
00057 
00058 /*
00059   The key cache structure
00060   It also contains read-only statistics parameters.
00061 */
00062 
00063 typedef struct st_key_cache
00064 {
00065   bool key_cache_inited;
00066   bool can_be_used;           /* usage of cache for read/write is allowed */
00067 
00068   uint32_t key_cache_block_size;     /* size of the page buffer of a cache block */
00069 
00070   int blocks;                   /* max number of blocks in the cache        */
00071 
00072   bool in_init;   /* Set to 1 in MySQL during init/resize     */
00073 
00074   st_key_cache():
00075     key_cache_inited(false),
00076     can_be_used(false),
00077     key_cache_block_size(0),
00078     blocks(0),
00079     in_init(0)
00080   { }
00081 
00082 } KEY_CACHE;
00083 
00084 } /* namespace drizzled */
00085 
00086 /* The default key cache */
00087 extern int init_key_cache(drizzled::KEY_CACHE *keycache, uint32_t key_cache_block_size,
00088         size_t use_mem, uint32_t division_limit,
00089         uint32_t age_threshold);
00090 extern unsigned char *key_cache_read(drizzled::KEY_CACHE *keycache,
00091                             int file, drizzled::internal::my_off_t filepos, int level,
00092                             unsigned char *buff, uint32_t length,
00093           uint32_t block_length,int return_buffer);
00094 extern int key_cache_insert(drizzled::KEY_CACHE *keycache,
00095                             int file, drizzled::internal::my_off_t filepos, int level,
00096                             unsigned char *buff, uint32_t length);
00097 extern int key_cache_write(drizzled::KEY_CACHE *keycache,
00098                            int file, drizzled::internal::my_off_t filepos, int level,
00099                            unsigned char *buff, uint32_t length,
00100          uint32_t block_length,int force_write);
00101 extern int flush_key_blocks(drizzled::KEY_CACHE *keycache,
00102                             int file, enum flush_type type);
00103 extern void end_key_cache(drizzled::KEY_CACHE *keycache, bool cleanup);
00104 
00105 /*
00106   Next highest power of two
00107 
00108   SYNOPSIS
00109     my_round_up_to_next_power()
00110     v   Value to check
00111 
00112   RETURN
00113     Next or equal power of 2
00114     Note: 0 will return 0
00115 
00116   NOTES
00117     Algorithm by Sean Anderson, according to:
00118     http://graphics.stanford.edu/~seander/bithacks.html
00119     (Orignal code public domain)
00120 
00121     Comments shows how this works with 01100000000000000000000000001011
00122 */
00123 
00124 static inline uint32_t my_round_up_to_next_power(uint32_t v)
00125 {
00126   v--;      /* 01100000000000000000000000001010 */
00127   v|= v >> 1;   /* 01110000000000000000000000001111 */
00128   v|= v >> 2;   /* 01111100000000000000000000001111 */
00129   v|= v >> 4;   /* 01111111110000000000000000001111 */
00130   v|= v >> 8;   /* 01111111111111111100000000001111 */
00131   v|= v >> 16;    /* 01111111111111111111111111111111 */
00132   return v+1;   /* 10000000000000000000000000000000 */
00133 }
00134 
00135