Skip to content

Commit 7c6113a

Browse files
Merge key cache structures to one
Fixed compiler warnings (IRIX C compiler and VC++)
1 parent ba65967 commit 7c6113a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+737
-710
lines changed

VC++Files/client/mysqlclient.dsp

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VC++Files/libmysql/libmysql.dsp

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VC++Files/myisam/myisam.dsp

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VC++Files/mysys/mysys.dsp

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

heap/hp_test1.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ int main(int argc, char **argv)
9191
{
9292
if (i == remove_ant) { VOID(heap_close(file)) ; return (0) ; }
9393
sprintf(key,"%6d",(j=(int) ((rand() & 32767)/32767.*25)));
94-
if ((error = heap_rkey(file,record,0,key,0,6)))
94+
if ((error = heap_rkey(file,record,0,key,6,HA_READ_KEY_EXACT)))
9595
{
9696
if (verbose || (flags[j] == 1 ||
9797
(error && my_errno != HA_ERR_KEY_NOT_FOUND)))
@@ -119,7 +119,7 @@ int main(int argc, char **argv)
119119
sprintf(key,"%6d",i);
120120
bmove(record+1,key,6);
121121
my_errno=0;
122-
error=heap_rkey(file,record,0,key,0,6);
122+
error=heap_rkey(file,record,0,key,6,HA_READ_KEY_EXACT);
123123
if (verbose ||
124124
(error == 0 && flags[i] != 1) ||
125125
(error && (flags[i] != 0 || my_errno != HA_ERR_KEY_NOT_FOUND)))

heap/hp_test2.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ int main(int argc, char *argv[])
179179
if (j != 0)
180180
{
181181
sprintf(key,"%6d",j);
182-
if (heap_rkey(file,record,0,key,6,0))
182+
if (heap_rkey(file,record,0,key,6, HA_READ_KEY_EXACT))
183183
{
184184
printf("can't find key1: \"%s\"\n",key);
185185
goto err;
@@ -239,7 +239,7 @@ int main(int argc, char *argv[])
239239
if (!key1[j])
240240
continue;
241241
sprintf(key,"%6d",j);
242-
if (heap_rkey(file,record,0,key,6,0))
242+
if (heap_rkey(file,record,0,key,6, HA_READ_KEY_EXACT))
243243
{
244244
printf("can't find key1: \"%s\"\n",key);
245245
goto err;
@@ -289,7 +289,7 @@ int main(int argc, char *argv[])
289289
printf("- Read first key - next - delete - next -> last\n");
290290
DBUG_PRINT("progpos",("first - next - delete - next -> last"));
291291

292-
if (heap_rkey(file,record,0,key,6,0))
292+
if (heap_rkey(file,record,0,key,6, HA_READ_KEY_EXACT))
293293
goto err;
294294
if (heap_rnext(file,record3)) goto err;
295295
if (heap_delete(file,record3)) goto err;
@@ -513,7 +513,7 @@ int main(int argc, char *argv[])
513513
}
514514
printf("- Read through all keys with first-next-last-prev\n");
515515
ant=0;
516-
for (error=heap_rkey(file,record,0,key,6,0);
516+
for (error=heap_rkey(file,record,0,key,6, HA_READ_KEY_EXACT);
517517
! error ;
518518
error=heap_rnext(file,record))
519519
ant++;
@@ -550,7 +550,8 @@ int main(int argc, char *argv[])
550550
{
551551
if (error == 0)
552552
{
553-
if (heap_rkey(file2,record2,2,record+keyinfo[2].seg[0].start,8,0))
553+
if (heap_rkey(file2,record2,2,record+keyinfo[2].seg[0].start,8,
554+
HA_READ_KEY_EXACT))
554555
{
555556
printf("can't find key3: \"%.8s\"\n",
556557
record+keyinfo[2].seg[0].start);

include/hash.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
extern "C" {
2323
#endif
2424

25+
/*
26+
Overhead to store an element in hash
27+
Can be used to approximate memory consumption for a hash
28+
*/
29+
#define HASH_OVERHEAD (sizeof(char*)*2)
30+
2531
typedef byte *(*hash_get_key)(const byte *,uint*,my_bool);
2632
typedef void (*hash_free_key)(void *);
2733

28-
typedef struct st_hash_info {
29-
uint next; /* index to next key */
30-
byte *data; /* data for current entry */
31-
} HASH_LINK;
32-
3334
typedef struct st_hash {
3435
uint key_offset,key_length; /* Length of key if const length */
3536
uint records,blength,current_record;

include/keycache.h

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/* Copyright (C) 2003 MySQL AB
2+
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; either version 2 of the License, or
6+
(at your option) any later version.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License
14+
along with this program; if not, write to the Free Software
15+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16+
17+
/* Key cache variable structures */
18+
19+
#ifndef _keycache_h
20+
#define _keycache_h
21+
C_MODE_START
22+
23+
/* declare structures that is used by st_key_cache */
24+
25+
struct st_block_link;
26+
typedef struct st_block_link BLOCK_LINK;
27+
struct st_keycache_page;
28+
typedef struct st_keycache_page KEYCACHE_PAGE;
29+
struct st_hash_link;
30+
typedef struct st_hash_link HASH_LINK;
31+
32+
/* info about requests in a waiting queue */
33+
typedef struct st_keycache_wqueue
34+
{
35+
struct st_my_thread_var *last_thread; /* circular list of waiting threads */
36+
} KEYCACHE_WQUEUE;
37+
38+
#define CHANGED_BLOCKS_HASH 128 /* must be power of 2 */
39+
40+
/*
41+
The key cache structure
42+
It also contains read-only statistics parameters.
43+
*/
44+
45+
typedef struct st_key_cache
46+
{
47+
my_bool key_cache_inited;
48+
uint key_cache_shift;
49+
ulong key_cache_mem_size; /* specified size of the cache memory */
50+
uint key_cache_block_size; /* size of the page buffer of a cache block */
51+
ulong min_warm_blocks; /* min number of warm blocks; */
52+
ulong age_threshold; /* age threshold for hot blocks */
53+
ulonglong keycache_time; /* total number of block link operations */
54+
uint hash_entries; /* max number of entries in the hash table */
55+
int hash_links; /* max number of hash links */
56+
int hash_links_used; /* number of hash links currently used */
57+
int disk_blocks; /* max number of blocks in the cache */
58+
ulong blocks_used; /* number of currently used blocks */
59+
ulong blocks_changed; /* number of currently dirty blocks */
60+
ulong warm_blocks; /* number of blocks in warm sub-chain */
61+
long blocks_available; /* number of blocks available in the LRU chain */
62+
HASH_LINK **hash_root; /* arr. of entries into hash table buckets */
63+
HASH_LINK *hash_link_root; /* memory for hash table links */
64+
HASH_LINK *free_hash_list; /* list of free hash links */
65+
BLOCK_LINK *block_root; /* memory for block links */
66+
byte HUGE_PTR *block_mem; /* memory for block buffers */
67+
BLOCK_LINK *used_last; /* ptr to the last block of the LRU chain */
68+
BLOCK_LINK *used_ins; /* ptr to the insertion block in LRU chain */
69+
pthread_mutex_t cache_lock; /* to lock access to the cache structure */
70+
KEYCACHE_WQUEUE waiting_for_hash_link; /* waiting for a free hash link */
71+
KEYCACHE_WQUEUE waiting_for_block; /* requests waiting for a free block */
72+
BLOCK_LINK *changed_blocks[CHANGED_BLOCKS_HASH]; /* hash for dirty file bl.*/
73+
BLOCK_LINK *file_blocks[CHANGED_BLOCKS_HASH]; /* hash for other file bl.*/
74+
75+
/*
76+
The following variables are and variables used to hold parameters for
77+
initializing the key cache.
78+
*/
79+
80+
ulonglong param_buff_size; /* size the memory allocated for the cache */
81+
ulong param_block_size; /* size of the blocks in the key cache */
82+
ulong param_division_limit; /* min. percentage of warm blocks */
83+
ulong param_age_threshold; /* determines when hot block is downgraded */
84+
85+
/* Statistics variables */
86+
ulong global_blocks_used; /* number of currently used blocks */
87+
ulong global_blocks_changed; /* number of currently dirty blocks */
88+
ulong global_cache_w_requests;/* number of write requests (write hits) */
89+
ulong global_cache_write; /* number of writes from the cache to files */
90+
ulong global_cache_r_requests;/* number of read requests (read hits) */
91+
ulong global_cache_read; /* number of reads from files to the cache */
92+
int blocks; /* max number of blocks in the cache */
93+
my_bool in_init; /* Set to 1 in MySQL during init/resize */
94+
95+
/* optional call back function */
96+
void (*action)(struct st_key_cache *);
97+
} KEY_CACHE;
98+
99+
/* The default key cache */
100+
extern KEY_CACHE dflt_key_cache_var, *dflt_key_cache;
101+
102+
extern int init_key_cache(KEY_CACHE *keycache, uint key_cache_block_size,
103+
ulong use_mem, uint division_limit,
104+
uint age_threshold);
105+
extern int resize_key_cache(KEY_CACHE *keycache, uint key_cache_block_size,
106+
ulong use_mem, uint division_limit,
107+
uint age_threshold);
108+
extern void change_key_cache_param(KEY_CACHE *keycache, uint division_limit,
109+
uint age_threshold);
110+
extern byte *key_cache_read(KEY_CACHE *keycache,
111+
File file, my_off_t filepos, int level,
112+
byte *buff, uint length,
113+
uint block_length,int return_buffer);
114+
extern int key_cache_insert(KEY_CACHE *keycache,
115+
File file, my_off_t filepos, int level,
116+
byte *buff, uint length);
117+
extern int key_cache_write(KEY_CACHE *keycache,
118+
File file, my_off_t filepos, int level,
119+
byte *buff, uint length,
120+
uint block_length,int force_write);
121+
extern int flush_key_blocks(KEY_CACHE *keycache,
122+
int file, enum flush_type type);
123+
extern void end_key_cache(KEY_CACHE *keycache, my_bool cleanup);
124+
125+
/* Functions to handle multiple key caches */
126+
extern my_bool multi_keycache_init(void);
127+
extern void multi_keycache_free(void);
128+
extern KEY_CACHE *multi_key_cache_search(byte *key, uint length);
129+
extern my_bool multi_key_cache_set(const byte *key, uint length,
130+
KEY_CACHE *key_cache);
131+
extern void multi_key_cache_change(KEY_CACHE *old_data,
132+
KEY_CACHE *new_data);
133+
C_MODE_END
134+
#endif /* _keycache_h */

include/my_pthread.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ int my_pthread_mutex_trylock(pthread_mutex_t *mutex);
468468
typedef struct st_safe_mutex_t
469469
{
470470
pthread_mutex_t global,mutex;
471-
char *file;
471+
const char *file;
472472
uint line,count;
473473
pthread_t thread;
474474
#ifdef SAFE_MUTEX_DETECT_DESTROY
@@ -487,7 +487,7 @@ typedef struct st_safe_mutex_info_t
487487
{
488488
struct st_safe_mutex_info_t *next;
489489
struct st_safe_mutex_info_t *prev;
490-
char *init_file;
490+
const char *init_file;
491491
uint32 init_line;
492492
} safe_mutex_info_t;
493493
#endif /* SAFE_MUTEX_DETECT_DESTROY */

include/my_sys.h

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -505,44 +505,6 @@ my_off_t my_b_append_tell(IO_CACHE* info);
505505

506506
typedef uint32 ha_checksum;
507507

508-
/* Pointer to a key cache data structure (see the key cache module) */
509-
typedef struct st_key_cache* KEY_CACHE_HANDLE;
510-
511-
/* Key cache variable structure */
512-
/*
513-
The structure contains the parameters of a key cache that can
514-
be set and undated by regular set global statements.
515-
It also contains read-only statistics parameters.
516-
If the corresponding key cache data structure has been already
517-
created the variable contains the key cache handle.
518-
The variables are put into a named list called key_caches.
519-
At present the variables are only added to this list.
520-
*/
521-
typedef struct st_key_cache_var
522-
{
523-
ulonglong buff_size; /* size the memory allocated for the cache */
524-
ulong block_size; /* size of the blocks in the key cache */
525-
ulong division_limit; /* min. percentage of warm blocks */
526-
ulong age_threshold; /* determines when hot block is downgraded */
527-
KEY_CACHE_HANDLE cache; /* handles for the current and registered */
528-
ulong blocks_used; /* number of currently used blocks */
529-
ulong blocks_changed; /* number of currently dirty blocks */
530-
ulong cache_w_requests; /* number of write requests (write hits) */
531-
ulong cache_write; /* number of writes from the cache to files */
532-
ulong cache_r_requests; /* number of read requests (read hits) */
533-
ulong cache_read; /* number of reads from files to the cache */
534-
int blocks; /* max number of blocks in the cache */
535-
my_bool in_init; /* Set to 1 in MySQL during init/resize */
536-
struct st_key_cache_asmt *assign_list; /* list of assignments to the cache */
537-
int assignments; /* number of not completed assignments */
538-
void (*action)(void *); /* optional call back function */
539-
void *extra_info; /* ptr to extra info */
540-
} KEY_CACHE_VAR;
541-
542-
543-
extern KEY_CACHE_HANDLE *dflt_keycache;
544-
extern KEY_CACHE_VAR dflt_key_cache_var;
545-
546508
#include <my_alloc.h>
547509

548510
/* Prototypes for mysys and my_func functions */
@@ -682,33 +644,6 @@ extern int flush_write_cache(RECORD_CACHE *info);
682644
extern long my_clock(void);
683645
extern sig_handler sigtstp_handler(int signal_number);
684646
extern void handle_recived_signals(void);
685-
extern int init_key_cache(KEY_CACHE_HANDLE *pkeycache,
686-
uint key_cache_block_size,
687-
ulong use_mem, KEY_CACHE_VAR* env);
688-
extern int resize_key_cache(KEY_CACHE_HANDLE *pkeycache,
689-
uint key_cache_block_size, ulong use_mem);
690-
extern void change_key_cache_param(KEY_CACHE_HANDLE keycache);
691-
extern byte *key_cache_read(KEY_CACHE_HANDLE keycache,
692-
File file, my_off_t filepos, int level,
693-
byte* buff, uint length,
694-
uint block_length,int return_buffer);
695-
extern int key_cache_insert(KEY_CACHE_HANDLE keycache,
696-
File file, my_off_t filepos, int level,
697-
byte *buff, uint length);
698-
extern int key_cache_write(KEY_CACHE_HANDLE keycache,
699-
File file, my_off_t filepos, int level,
700-
byte* buff, uint length,
701-
uint block_length,int force_write);
702-
extern int flush_key_blocks(KEY_CACHE_HANDLE keycache,
703-
int file, enum flush_type type);
704-
extern void end_key_cache(KEY_CACHE_HANDLE keycache, my_bool cleanup);
705-
extern my_bool multi_keycache_init(void);
706-
extern void multi_keycache_free(void);
707-
extern KEY_CACHE_HANDLE *multi_key_cache_search(byte *key, uint length);
708-
extern my_bool multi_key_cache_set(const byte *key, uint length,
709-
KEY_CACHE_HANDLE *key_cache);
710-
extern void multi_key_cache_change(KEY_CACHE_HANDLE *old_data,
711-
KEY_CACHE_HANDLE *new_data);
712647

713648
extern sig_handler my_set_alarm_variable(int signo);
714649
extern void my_string_ptr_sort(void *base,uint items,size_s size);

0 commit comments

Comments
 (0)