~drizzle-trunk/drizzle/development

1 by brian
clean slate
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; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
16
/* Key cache variable structures */
17
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
18
#pragma once
53.2.37 by Monty Taylor
Moved keycache code to MyISAM.
19
20
enum flush_type
21
{
22
  FLUSH_KEEP,           /* flush block and keep it in the cache */
23
  FLUSH_RELEASE,        /* flush block and remove it from the cache */
24
  FLUSH_IGNORE_CHANGED, /* remove block from the cache */
25
  /*
26
 *     As my_disable_flush_pagecache_blocks is always 0, the following option
27
 *         is strictly equivalent to FLUSH_KEEP
28
 *           */
29
  FLUSH_FORCE_WRITE
30
};
31
1241.13.1 by Monty Taylor
Put my_off_t back... but this time localized only to myisam and mysys.
32
1 by brian
clean slate
33
/* declare structures that is used by st_key_cache */
34
35
struct st_block_link;
36
typedef struct st_block_link BLOCK_LINK;
37
struct st_keycache_page;
38
typedef struct st_keycache_page KEYCACHE_PAGE;
39
struct st_hash_link;
40
typedef struct st_hash_link HASH_LINK;
41
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
42
namespace drizzled
43
{
44
namespace internal
45
{
46
typedef uint64_t my_off_t;
47
struct st_my_thread_var;
48
}
49
1 by brian
clean slate
50
/* info about requests in a waiting queue */
51
typedef struct st_keycache_wqueue
52
{
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
53
  drizzled::internal::st_my_thread_var *last_thread;  /* circular list of waiting threads */
1 by brian
clean slate
54
} KEYCACHE_WQUEUE;
55
56
#define CHANGED_BLOCKS_HASH 128             /* must be power of 2 */
57
58
/*
59
  The key cache structure
60
  It also contains read-only statistics parameters.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
61
*/
1 by brian
clean slate
62
63
typedef struct st_key_cache
64
{
281 by Brian Aker
Converted myisam away from my_bool
65
  bool key_cache_inited;
66
  bool can_be_used;           /* usage of cache for read/write is allowed */
1689.2.23 by Brian Aker
Remaining keycache bits.
67
482 by Brian Aker
Remove uint.
68
  uint32_t key_cache_block_size;     /* size of the page buffer of a cache block */
1 by brian
clean slate
69
1030.1.2 by Brian Aker
More alignment for structures
70
  int blocks;                   /* max number of blocks in the cache        */
1 by brian
clean slate
71
281 by Brian Aker
Converted myisam away from my_bool
72
  bool in_init;		/* Set to 1 in MySQL during init/resize     */
1689.2.23 by Brian Aker
Remaining keycache bits.
73
74
  st_key_cache():
75
    key_cache_inited(false),
76
    can_be_used(false),
77
    key_cache_block_size(0),
78
    blocks(0),
79
    in_init(0)
80
  { }
81
1 by brian
clean slate
82
} KEY_CACHE;
83
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
84
} /* namespace drizzled */
85
1 by brian
clean slate
86
/* The default key cache */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
87
extern int init_key_cache(drizzled::KEY_CACHE *keycache, uint32_t key_cache_block_size,
88
			  size_t use_mem, uint32_t division_limit,
482 by Brian Aker
Remove uint.
89
			  uint32_t age_threshold);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
90
extern unsigned char *key_cache_read(drizzled::KEY_CACHE *keycache,
91
                            int file, drizzled::internal::my_off_t filepos, int level,
1241.13.1 by Monty Taylor
Put my_off_t back... but this time localized only to myisam and mysys.
92
                            unsigned char *buff, uint32_t length,
93
			    uint32_t block_length,int return_buffer);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
94
extern int key_cache_insert(drizzled::KEY_CACHE *keycache,
95
                            int file, drizzled::internal::my_off_t filepos, int level,
482 by Brian Aker
Remove uint.
96
                            unsigned char *buff, uint32_t length);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
97
extern int key_cache_write(drizzled::KEY_CACHE *keycache,
98
                           int file, drizzled::internal::my_off_t filepos, int level,
482 by Brian Aker
Remove uint.
99
                           unsigned char *buff, uint32_t length,
100
			   uint32_t block_length,int force_write);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
101
extern int flush_key_blocks(drizzled::KEY_CACHE *keycache,
1 by brian
clean slate
102
                            int file, enum flush_type type);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
103
extern void end_key_cache(drizzled::KEY_CACHE *keycache, bool cleanup);
1 by brian
clean slate
104
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
105
/*
106
  Next highest power of two
107
108
  SYNOPSIS
109
    my_round_up_to_next_power()
110
    v		Value to check
111
112
  RETURN
113
    Next or equal power of 2
114
    Note: 0 will return 0
115
116
  NOTES
117
    Algorithm by Sean Anderson, according to:
118
    http://graphics.stanford.edu/~seander/bithacks.html
119
    (Orignal code public domain)
120
121
    Comments shows how this works with 01100000000000000000000000001011
122
*/
123
124
static inline uint32_t my_round_up_to_next_power(uint32_t v)
125
{
126
  v--;			/* 01100000000000000000000000001010 */
127
  v|= v >> 1;		/* 01110000000000000000000000001111 */
128
  v|= v >> 2;		/* 01111100000000000000000000001111 */
129
  v|= v >> 4;		/* 01111111110000000000000000001111 */
130
  v|= v >> 8;		/* 01111111111111111100000000001111 */
131
  v|= v >> 16;		/* 01111111111111111111111111111111 */
132
  return v+1;		/* 10000000000000000000000000000000 */
398.1.9 by Monty Taylor
Cleaned up stuff out of global.h.
133
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
134
398.1.9 by Monty Taylor
Cleaned up stuff out of global.h.
135