summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authormonty@mysql.com <>2003-11-20 22:06:25 +0200
committermonty@mysql.com <>2003-11-20 22:06:25 +0200
commit7c6113a39f56832da982cfb4ff191e9db49ca798 (patch)
tree685b3a2a60fc00121d338cb0b5f84b4cd028bfe1 /include
parentba659679e7816cd9c992c866645f65b06e5f69de (diff)
downloadmariadb-git-7c6113a39f56832da982cfb4ff191e9db49ca798.tar.gz
Merge key cache structures to one
Fixed compiler warnings (IRIX C compiler and VC++)
Diffstat (limited to 'include')
-rw-r--r--include/hash.h11
-rw-r--r--include/keycache.h134
-rw-r--r--include/my_pthread.h4
-rw-r--r--include/my_sys.h65
-rw-r--r--include/myisam.h9
-rw-r--r--include/mysql.h44
-rw-r--r--include/sql_common.h2
-rw-r--r--include/violite.h2
8 files changed, 172 insertions, 99 deletions
diff --git a/include/hash.h b/include/hash.h
index 3c2ae32c70e..c7cc118b7bd 100644
--- a/include/hash.h
+++ b/include/hash.h
@@ -22,14 +22,15 @@
extern "C" {
#endif
+/*
+ Overhead to store an element in hash
+ Can be used to approximate memory consumption for a hash
+ */
+#define HASH_OVERHEAD (sizeof(char*)*2)
+
typedef byte *(*hash_get_key)(const byte *,uint*,my_bool);
typedef void (*hash_free_key)(void *);
-typedef struct st_hash_info {
- uint next; /* index to next key */
- byte *data; /* data for current entry */
-} HASH_LINK;
-
typedef struct st_hash {
uint key_offset,key_length; /* Length of key if const length */
uint records,blength,current_record;
diff --git a/include/keycache.h b/include/keycache.h
new file mode 100644
index 00000000000..824c5874ffc
--- /dev/null
+++ b/include/keycache.h
@@ -0,0 +1,134 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ 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.
+
+ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/* Key cache variable structures */
+
+#ifndef _keycache_h
+#define _keycache_h
+C_MODE_START
+
+/* declare structures that is used by st_key_cache */
+
+struct st_block_link;
+typedef struct st_block_link BLOCK_LINK;
+struct st_keycache_page;
+typedef struct st_keycache_page KEYCACHE_PAGE;
+struct st_hash_link;
+typedef struct st_hash_link HASH_LINK;
+
+/* info about requests in a waiting queue */
+typedef struct st_keycache_wqueue
+{
+ struct st_my_thread_var *last_thread; /* circular list of waiting threads */
+} KEYCACHE_WQUEUE;
+
+#define CHANGED_BLOCKS_HASH 128 /* must be power of 2 */
+
+/*
+ The key cache structure
+ It also contains read-only statistics parameters.
+*/
+
+typedef struct st_key_cache
+{
+ my_bool key_cache_inited;
+ uint key_cache_shift;
+ ulong key_cache_mem_size; /* specified size of the cache memory */
+ uint key_cache_block_size; /* size of the page buffer of a cache block */
+ ulong min_warm_blocks; /* min number of warm blocks; */
+ ulong age_threshold; /* age threshold for hot blocks */
+ ulonglong keycache_time; /* total number of block link operations */
+ uint hash_entries; /* max number of entries in the hash table */
+ int hash_links; /* max number of hash links */
+ int hash_links_used; /* number of hash links currently used */
+ int disk_blocks; /* max number of blocks in the cache */
+ ulong blocks_used; /* number of currently used blocks */
+ ulong blocks_changed; /* number of currently dirty blocks */
+ ulong warm_blocks; /* number of blocks in warm sub-chain */
+ long blocks_available; /* number of blocks available in the LRU chain */
+ HASH_LINK **hash_root; /* arr. of entries into hash table buckets */
+ HASH_LINK *hash_link_root; /* memory for hash table links */
+ HASH_LINK *free_hash_list; /* list of free hash links */
+ BLOCK_LINK *block_root; /* memory for block links */
+ byte HUGE_PTR *block_mem; /* memory for block buffers */
+ BLOCK_LINK *used_last; /* ptr to the last block of the LRU chain */
+ BLOCK_LINK *used_ins; /* ptr to the insertion block in LRU chain */
+ pthread_mutex_t cache_lock; /* to lock access to the cache structure */
+ KEYCACHE_WQUEUE waiting_for_hash_link; /* waiting for a free hash link */
+ KEYCACHE_WQUEUE waiting_for_block; /* requests waiting for a free block */
+ BLOCK_LINK *changed_blocks[CHANGED_BLOCKS_HASH]; /* hash for dirty file bl.*/
+ BLOCK_LINK *file_blocks[CHANGED_BLOCKS_HASH]; /* hash for other file bl.*/
+
+ /*
+ The following variables are and variables used to hold parameters for
+ initializing the key cache.
+ */
+
+ ulonglong param_buff_size; /* size the memory allocated for the cache */
+ ulong param_block_size; /* size of the blocks in the key cache */
+ ulong param_division_limit; /* min. percentage of warm blocks */
+ ulong param_age_threshold; /* determines when hot block is downgraded */
+
+ /* Statistics variables */
+ ulong global_blocks_used; /* number of currently used blocks */
+ ulong global_blocks_changed; /* number of currently dirty blocks */
+ ulong global_cache_w_requests;/* number of write requests (write hits) */
+ ulong global_cache_write; /* number of writes from the cache to files */
+ ulong global_cache_r_requests;/* number of read requests (read hits) */
+ ulong global_cache_read; /* number of reads from files to the cache */
+ int blocks; /* max number of blocks in the cache */
+ my_bool in_init; /* Set to 1 in MySQL during init/resize */
+
+ /* optional call back function */
+ void (*action)(struct st_key_cache *);
+} KEY_CACHE;
+
+/* The default key cache */
+extern KEY_CACHE dflt_key_cache_var, *dflt_key_cache;
+
+extern int init_key_cache(KEY_CACHE *keycache, uint key_cache_block_size,
+ ulong use_mem, uint division_limit,
+ uint age_threshold);
+extern int resize_key_cache(KEY_CACHE *keycache, uint key_cache_block_size,
+ ulong use_mem, uint division_limit,
+ uint age_threshold);
+extern void change_key_cache_param(KEY_CACHE *keycache, uint division_limit,
+ uint age_threshold);
+extern byte *key_cache_read(KEY_CACHE *keycache,
+ File file, my_off_t filepos, int level,
+ byte *buff, uint length,
+ uint block_length,int return_buffer);
+extern int key_cache_insert(KEY_CACHE *keycache,
+ File file, my_off_t filepos, int level,
+ byte *buff, uint length);
+extern int key_cache_write(KEY_CACHE *keycache,
+ File file, my_off_t filepos, int level,
+ byte *buff, uint length,
+ uint block_length,int force_write);
+extern int flush_key_blocks(KEY_CACHE *keycache,
+ int file, enum flush_type type);
+extern void end_key_cache(KEY_CACHE *keycache, my_bool cleanup);
+
+/* Functions to handle multiple key caches */
+extern my_bool multi_keycache_init(void);
+extern void multi_keycache_free(void);
+extern KEY_CACHE *multi_key_cache_search(byte *key, uint length);
+extern my_bool multi_key_cache_set(const byte *key, uint length,
+ KEY_CACHE *key_cache);
+extern void multi_key_cache_change(KEY_CACHE *old_data,
+ KEY_CACHE *new_data);
+C_MODE_END
+#endif /* _keycache_h */
diff --git a/include/my_pthread.h b/include/my_pthread.h
index a4ea88b20f0..44e6edcddec 100644
--- a/include/my_pthread.h
+++ b/include/my_pthread.h
@@ -468,7 +468,7 @@ int my_pthread_mutex_trylock(pthread_mutex_t *mutex);
typedef struct st_safe_mutex_t
{
pthread_mutex_t global,mutex;
- char *file;
+ const char *file;
uint line,count;
pthread_t thread;
#ifdef SAFE_MUTEX_DETECT_DESTROY
@@ -487,7 +487,7 @@ typedef struct st_safe_mutex_info_t
{
struct st_safe_mutex_info_t *next;
struct st_safe_mutex_info_t *prev;
- char *init_file;
+ const char *init_file;
uint32 init_line;
} safe_mutex_info_t;
#endif /* SAFE_MUTEX_DETECT_DESTROY */
diff --git a/include/my_sys.h b/include/my_sys.h
index d1c7b658665..604eaf34fb7 100644
--- a/include/my_sys.h
+++ b/include/my_sys.h
@@ -505,44 +505,6 @@ my_off_t my_b_append_tell(IO_CACHE* info);
typedef uint32 ha_checksum;
-/* Pointer to a key cache data structure (see the key cache module) */
-typedef struct st_key_cache* KEY_CACHE_HANDLE;
-
-/* Key cache variable structure */
-/*
- The structure contains the parameters of a key cache that can
- be set and undated by regular set global statements.
- It also contains read-only statistics parameters.
- If the corresponding key cache data structure has been already
- created the variable contains the key cache handle.
- The variables are put into a named list called key_caches.
- At present the variables are only added to this list.
-*/
-typedef struct st_key_cache_var
-{
- ulonglong buff_size; /* size the memory allocated for the cache */
- ulong block_size; /* size of the blocks in the key cache */
- ulong division_limit; /* min. percentage of warm blocks */
- ulong age_threshold; /* determines when hot block is downgraded */
- KEY_CACHE_HANDLE cache; /* handles for the current and registered */
- ulong blocks_used; /* number of currently used blocks */
- ulong blocks_changed; /* number of currently dirty blocks */
- ulong cache_w_requests; /* number of write requests (write hits) */
- ulong cache_write; /* number of writes from the cache to files */
- ulong cache_r_requests; /* number of read requests (read hits) */
- ulong cache_read; /* number of reads from files to the cache */
- int blocks; /* max number of blocks in the cache */
- my_bool in_init; /* Set to 1 in MySQL during init/resize */
- struct st_key_cache_asmt *assign_list; /* list of assignments to the cache */
- int assignments; /* number of not completed assignments */
- void (*action)(void *); /* optional call back function */
- void *extra_info; /* ptr to extra info */
-} KEY_CACHE_VAR;
-
-
-extern KEY_CACHE_HANDLE *dflt_keycache;
-extern KEY_CACHE_VAR dflt_key_cache_var;
-
#include <my_alloc.h>
/* Prototypes for mysys and my_func functions */
@@ -682,33 +644,6 @@ extern int flush_write_cache(RECORD_CACHE *info);
extern long my_clock(void);
extern sig_handler sigtstp_handler(int signal_number);
extern void handle_recived_signals(void);
-extern int init_key_cache(KEY_CACHE_HANDLE *pkeycache,
- uint key_cache_block_size,
- ulong use_mem, KEY_CACHE_VAR* env);
-extern int resize_key_cache(KEY_CACHE_HANDLE *pkeycache,
- uint key_cache_block_size, ulong use_mem);
-extern void change_key_cache_param(KEY_CACHE_HANDLE keycache);
-extern byte *key_cache_read(KEY_CACHE_HANDLE keycache,
- File file, my_off_t filepos, int level,
- byte* buff, uint length,
- uint block_length,int return_buffer);
-extern int key_cache_insert(KEY_CACHE_HANDLE keycache,
- File file, my_off_t filepos, int level,
- byte *buff, uint length);
-extern int key_cache_write(KEY_CACHE_HANDLE keycache,
- File file, my_off_t filepos, int level,
- byte* buff, uint length,
- uint block_length,int force_write);
-extern int flush_key_blocks(KEY_CACHE_HANDLE keycache,
- int file, enum flush_type type);
-extern void end_key_cache(KEY_CACHE_HANDLE keycache, my_bool cleanup);
-extern my_bool multi_keycache_init(void);
-extern void multi_keycache_free(void);
-extern KEY_CACHE_HANDLE *multi_key_cache_search(byte *key, uint length);
-extern my_bool multi_key_cache_set(const byte *key, uint length,
- KEY_CACHE_HANDLE *key_cache);
-extern void multi_key_cache_change(KEY_CACHE_HANDLE *old_data,
- KEY_CACHE_HANDLE *new_data);
extern sig_handler my_set_alarm_variable(int signo);
extern void my_string_ptr_sort(void *base,uint items,size_s size);
diff --git a/include/myisam.h b/include/myisam.h
index 52f2948aaef..613a9965832 100644
--- a/include/myisam.h
+++ b/include/myisam.h
@@ -28,6 +28,9 @@ extern "C" {
#ifndef _m_ctype_h
#include <m_ctype.h>
#endif
+#ifndef _keycache_h
+#include "keycache.h"
+#endif
#include "my_handler.h"
/* defines used by myisam-funktions */
@@ -408,9 +411,9 @@ int mi_init_bulk_insert(MI_INFO *info, ulong cache_size, ha_rows rows);
void mi_flush_bulk_insert(MI_INFO *info, uint inx);
void mi_end_bulk_insert(MI_INFO *info);
int mi_assign_to_key_cache(MI_INFO *info, ulonglong key_map,
- KEY_CACHE_VAR *key_cache);
-void mi_change_key_cache(KEY_CACHE_VAR *old_key_cache,
- KEY_CACHE_VAR *new_key_cache);
+ KEY_CACHE *key_cache);
+void mi_change_key_cache(KEY_CACHE *old_key_cache,
+ KEY_CACHE *new_key_cache);
int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves);
#ifdef __cplusplus
diff --git a/include/mysql.h b/include/mysql.h
index 7df42460c6d..23d89fd531f 100644
--- a/include/mysql.h
+++ b/include/mysql.h
@@ -535,10 +535,10 @@ typedef struct st_mysql_stmt
char *query; /* query buffer */
MEM_ROOT mem_root; /* root allocations */
my_ulonglong last_fetched_column; /* last fetched column */
- unsigned long param_count; /* parameters count */
- unsigned long field_count; /* fields count */
unsigned long stmt_id; /* Id for prepared statement */
unsigned int last_errno; /* error code */
+ unsigned int param_count; /* parameters count */
+ unsigned int field_count; /* fields count */
enum PREP_STMT_STATE state; /* statement state */
char last_error[MYSQL_ERRMSG_SIZE]; /* error message */
char sqlstate[SQLSTATE_LENGTH+1];
@@ -552,27 +552,27 @@ typedef struct st_mysql_stmt
typedef struct st_mysql_methods
{
- my_bool (* STDCALL read_query_result)(MYSQL *mysql);
- my_bool (* STDCALL advanced_command)(MYSQL *mysql,
- enum enum_server_command command,
- const char *header,
- unsigned long header_length,
- const char *arg,
- unsigned long arg_length,
- my_bool skip_check);
- MYSQL_DATA *(* STDCALL read_rows)(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
- unsigned int fields);
- MYSQL_RES * (* STDCALL use_result)(MYSQL *mysql);
- void (* STDCALL fetch_lengths)(unsigned long *to,
- MYSQL_ROW column, unsigned int field_count);
+ my_bool (*read_query_result)(MYSQL *mysql);
+ my_bool (*advanced_command)(MYSQL *mysql,
+ enum enum_server_command command,
+ const char *header,
+ unsigned long header_length,
+ const char *arg,
+ unsigned long arg_length,
+ my_bool skip_check);
+ MYSQL_DATA *(*read_rows)(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
+ unsigned int fields);
+ MYSQL_RES * (*use_result)(MYSQL *mysql);
+ void (*fetch_lengths)(unsigned long *to,
+ MYSQL_ROW column, unsigned int field_count);
#if !defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY)
- MYSQL_FIELD * (* STDCALL list_fields)(MYSQL *mysql);
- my_bool (* STDCALL read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
- int (* STDCALL stmt_execute)(MYSQL_STMT *stmt);
- MYSQL_DATA *(* STDCALL read_binary_rows)(MYSQL_STMT *stmt);
- int (* STDCALL unbuffered_fetch)(MYSQL *mysql, char **row);
- void (* STDCALL free_embedded_thd)(MYSQL *mysql);
- const char *(* STDCALL read_statistic)(MYSQL *mysql);
+ MYSQL_FIELD * (*list_fields)(MYSQL *mysql);
+ my_bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
+ int (*stmt_execute)(MYSQL_STMT *stmt);
+ MYSQL_DATA *(*read_binary_rows)(MYSQL_STMT *stmt);
+ int (*unbuffered_fetch)(MYSQL *mysql, char **row);
+ void (*free_embedded_thd)(MYSQL *mysql);
+ const char *(*read_statistic)(MYSQL *mysql);
#endif
} MYSQL_METHODS;
diff --git a/include/sql_common.h b/include/sql_common.h
index 1f442339c4f..1c374030a55 100644
--- a/include/sql_common.h
+++ b/include/sql_common.h
@@ -34,7 +34,7 @@ void end_server(MYSQL *mysql);
my_bool mysql_reconnect(MYSQL *mysql);
void mysql_read_default_options(struct st_mysql_options *options,
const char *filename,const char *group);
-my_bool STDCALL
+my_bool
cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
const char *header, ulong header_length,
const char *arg, ulong arg_length, my_bool skip_check);
diff --git a/include/violite.h b/include/violite.h
index 37c5abbbe67..e8f30288d34 100644
--- a/include/violite.h
+++ b/include/violite.h
@@ -177,7 +177,7 @@ struct st_vio
void (*viodelete)(Vio*);
int (*vioerrno)(Vio*);
int (*read)(Vio*, gptr, int);
- int (*write)(Vio*, gptr, int);
+ int (*write)(Vio*, const gptr, int);
int (*vioblocking)(Vio*, my_bool, my_bool *);
my_bool (*is_blocking)(Vio*);
int (*viokeepalive)(Vio*, my_bool);