481.2.1
by Monty Taylor
Split iocache definitions into their own header. |
1 |
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 MySQL
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; either version 2 of the License, or
|
|
9 |
* (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program; if not, write to the Free Software
|
|
18 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19 |
*/
|
|
20 |
||
2234
by Brian Aker
Mass removal of ifdef/endif in favor of pragma once. |
21 |
#pragma once
|
481.2.1
by Monty Taylor
Split iocache definitions into their own header. |
22 |
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
23 |
#include <drizzled/internal/my_sys.h> |
584.1.14
by Monty Taylor
Removed field.h from common_includes. |
24 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
25 |
namespace drizzled |
26 |
{
|
|
27 |
namespace internal |
|
28 |
{
|
|
481.1.16
by Monty Taylor
Merged iocache.h addition. |
29 |
|
481.2.1
by Monty Taylor
Split iocache definitions into their own header. |
30 |
struct st_io_cache; |
31 |
typedef int (*IO_CACHE_CALLBACK)(struct st_io_cache*); |
|
32 |
||
1578.4.5
by Brian Aker
Remove memset call around IO_CACHE. |
33 |
struct st_io_cache /* Used when cacheing files */ |
481.2.1
by Monty Taylor
Split iocache definitions into their own header. |
34 |
{
|
35 |
/* Offset in file corresponding to the first byte of unsigned char* buffer. */
|
|
1241.13.1
by Monty Taylor
Put my_off_t back... but this time localized only to myisam and mysys. |
36 |
my_off_t pos_in_file; |
481.2.1
by Monty Taylor
Split iocache definitions into their own header. |
37 |
/*
|
38 |
The offset of end of file for READ_CACHE and WRITE_CACHE.
|
|
39 |
For SEQ_READ_APPEND it the maximum of the actual end of file and
|
|
40 |
the position represented by read_end.
|
|
41 |
*/
|
|
1241.13.1
by Monty Taylor
Put my_off_t back... but this time localized only to myisam and mysys. |
42 |
my_off_t end_of_file; |
481.2.1
by Monty Taylor
Split iocache definitions into their own header. |
43 |
/* Points to current read position in the buffer */
|
44 |
unsigned char *read_pos; |
|
45 |
/* the non-inclusive boundary in the buffer for the currently valid read */
|
|
46 |
unsigned char *read_end; |
|
47 |
unsigned char *buffer; /* The read buffer */ |
|
48 |
/* Used in ASYNC_IO */
|
|
49 |
unsigned char *request_pos; |
|
50 |
||
51 |
/* Only used in WRITE caches and in SEQ_READ_APPEND to buffer writes */
|
|
52 |
unsigned char *write_buffer; |
|
53 |
/*
|
|
54 |
Only used in SEQ_READ_APPEND, and points to the current read position
|
|
55 |
in the write buffer. Note that reads in SEQ_READ_APPEND caches can
|
|
56 |
happen from both read buffer (unsigned char* buffer) and write buffer
|
|
57 |
(unsigned char* write_buffer).
|
|
58 |
*/
|
|
59 |
unsigned char *append_read_pos; |
|
60 |
/* Points to current write position in the write buffer */
|
|
61 |
unsigned char *write_pos; |
|
62 |
/* The non-inclusive boundary of the valid write area */
|
|
63 |
unsigned char *write_end; |
|
64 |
||
65 |
/*
|
|
66 |
Current_pos and current_end are convenience variables used by
|
|
67 |
my_b_tell() and other routines that need to know the current offset
|
|
68 |
current_pos points to &write_pos, and current_end to &write_end in a
|
|
69 |
WRITE_CACHE, and &read_pos and &read_end respectively otherwise
|
|
70 |
*/
|
|
71 |
unsigned char **current_pos, **current_end; |
|
72 |
/*
|
|
73 |
A caller will use my_b_read() macro to read from the cache
|
|
74 |
if the data is already in cache, it will be simply copied with
|
|
75 |
memcpy() and internal variables will be accordinging updated with
|
|
76 |
no functions invoked. However, if the data is not fully in the cache,
|
|
77 |
my_b_read() will call read_function to fetch the data. read_function
|
|
78 |
must never be invoked directly.
|
|
79 |
*/
|
|
80 |
int (*read_function)(struct st_io_cache *,unsigned char *,size_t); |
|
81 |
/*
|
|
82 |
Same idea as in the case of read_function, except my_b_write() needs to
|
|
83 |
be replaced with my_b_append() for a SEQ_READ_APPEND cache
|
|
84 |
*/
|
|
85 |
int (*write_function)(struct st_io_cache *,const unsigned char *,size_t); |
|
86 |
/*
|
|
87 |
Specifies the type of the cache. Depending on the type of the cache
|
|
88 |
certain operations might not be available and yield unpredicatable
|
|
89 |
results. Details to be documented later
|
|
90 |
*/
|
|
91 |
enum cache_type type; |
|
1030.1.1
by Brian Aker
Straighten out structures (remove some some dead bits). |
92 |
int error; |
481.2.1
by Monty Taylor
Split iocache definitions into their own header. |
93 |
/*
|
94 |
Callbacks when the actual read I/O happens. These were added and
|
|
95 |
are currently used for binary logging of LOAD DATA INFILE - when a
|
|
96 |
block is read from the file, we create a block create/append event, and
|
|
97 |
when IO_CACHE is closed, we create an end event. These functions could,
|
|
98 |
of course be used for other things
|
|
99 |
*/
|
|
100 |
IO_CACHE_CALLBACK pre_read; |
|
101 |
IO_CACHE_CALLBACK post_read; |
|
102 |
IO_CACHE_CALLBACK pre_close; |
|
103 |
void* arg; /* for use by pre/post_read */ |
|
104 |
char *file_name; /* if used with 'open_cached_file' */ |
|
105 |
char *dir,*prefix; |
|
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
106 |
int file; /* file descriptor */ |
481.2.1
by Monty Taylor
Split iocache definitions into their own header. |
107 |
/*
|
108 |
seek_not_done is set by my_b_seek() to inform the upcoming read/write
|
|
109 |
operation that a seek needs to be preformed prior to the actual I/O
|
|
110 |
error is 0 if the cache operation was successful, -1 if there was a
|
|
111 |
"hard" error, and the actual number of I/O-ed bytes if the read/write was
|
|
112 |
partial.
|
|
113 |
*/
|
|
1030.1.1
by Brian Aker
Straighten out structures (remove some some dead bits). |
114 |
int seek_not_done; |
481.2.1
by Monty Taylor
Split iocache definitions into their own header. |
115 |
/* buffer_length is memory size allocated for buffer or write_buffer */
|
116 |
size_t buffer_length; |
|
117 |
/* read_length is the same as buffer_length except when we use async io */
|
|
118 |
size_t read_length; |
|
119 |
myf myflags; /* Flags used to my_read/my_write */ |
|
120 |
/*
|
|
121 |
alloced_buffer is 1 if the buffer was allocated by init_io_cache() and
|
|
122 |
0 if it was supplied by the user.
|
|
123 |
Currently READ_NET is the only one that will use a buffer allocated
|
|
124 |
somewhere else
|
|
125 |
*/
|
|
126 |
bool alloced_buffer; |
|
127 |
#ifdef HAVE_AIOWAIT
|
|
128 |
/*
|
|
129 |
As inidicated by ifdef, this is for async I/O, which is not currently
|
|
130 |
used (because it's not reliable on all systems)
|
|
131 |
*/
|
|
132 |
uint32_t inited; |
|
1241.13.1
by Monty Taylor
Put my_off_t back... but this time localized only to myisam and mysys. |
133 |
my_off_t aio_read_pos; |
481.2.1
by Monty Taylor
Split iocache definitions into their own header. |
134 |
my_aio_result aio_result; |
135 |
#endif
|
|
1578.4.5
by Brian Aker
Remove memset call around IO_CACHE. |
136 |
|
137 |
st_io_cache() : |
|
138 |
pos_in_file(0), |
|
139 |
end_of_file(0), |
|
140 |
read_pos(0), |
|
141 |
read_end(0), |
|
142 |
buffer(0), |
|
143 |
request_pos(0), |
|
144 |
write_buffer(0), |
|
145 |
append_read_pos(0), |
|
146 |
write_pos(0), |
|
147 |
write_end(0), |
|
148 |
current_pos(0), |
|
149 |
current_end(0), |
|
150 |
read_function(0), |
|
151 |
write_function(0), |
|
152 |
type(TYPE_NOT_SET), |
|
153 |
error(0), |
|
154 |
pre_read(0), |
|
155 |
post_read(0), |
|
156 |
pre_close(0), |
|
157 |
arg(0), |
|
158 |
file_name(0), |
|
159 |
dir(0), |
|
160 |
prefix(0), |
|
161 |
file(0), |
|
162 |
seek_not_done(0), |
|
163 |
buffer_length(0), |
|
164 |
read_length(0), |
|
165 |
myflags(0), |
|
166 |
alloced_buffer(0) |
|
167 |
#ifdef HAVE_AIOWAIT
|
|
168 |
,
|
|
169 |
inited(0), |
|
170 |
aio_read_pos(0), |
|
171 |
aio_result(0) |
|
172 |
#endif
|
|
173 |
{ } |
|
174 |
||
175 |
~st_io_cache() |
|
176 |
{ } |
|
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
177 |
|
178 |
void close_cached_file(); |
|
179 |
bool real_open_cached_file(); |
|
180 |
int end_io_cache(); |
|
181 |
int init_io_cache(int file, size_t cachesize, |
|
182 |
enum cache_type type, my_off_t seek_offset, |
|
183 |
bool use_async_io, myf cache_myflags); |
|
184 |
void init_functions(); |
|
185 |
||
186 |
bool reinit_io_cache(enum cache_type type_arg, |
|
187 |
my_off_t seek_offset, |
|
188 |
bool use_async_io, |
|
189 |
bool clear_cache); |
|
190 |
void setup_io_cache(); |
|
1909.1.2
by Brian Aker
Additional io_cache encapsulation. |
191 |
bool open_cached_file(const char *dir, |
192 |
const char *prefix, size_t cache_size, |
|
193 |
myf cache_myflags); |
|
194 |
||
1578.4.5
by Brian Aker
Remove memset call around IO_CACHE. |
195 |
};
|
196 |
||
197 |
typedef struct st_io_cache IO_CACHE; /* Used when cacheing files */ |
|
481.2.1
by Monty Taylor
Split iocache definitions into their own header. |
198 |
|
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
199 |
extern int _my_b_get(st_io_cache *info); |
200 |
extern int _my_b_async_read(st_io_cache *info,unsigned char *Buffer,size_t Count); |
|
481.2.1
by Monty Taylor
Split iocache definitions into their own header. |
201 |
|
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
202 |
extern int my_block_write(st_io_cache *info, const unsigned char *Buffer, |
1241.13.1
by Monty Taylor
Put my_off_t back... but this time localized only to myisam and mysys. |
203 |
size_t Count, my_off_t pos); |
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
204 |
extern int my_b_flush_io_cache(st_io_cache *info, int need_append_buffer_lock); |
481.2.1
by Monty Taylor
Split iocache definitions into their own header. |
205 |
|
206 |
#define flush_io_cache(info) my_b_flush_io_cache((info),1)
|
|
207 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
208 |
} /* namespace internal */ |
209 |
} /* namespace drizzled */ |
|
481.1.16
by Monty Taylor
Merged iocache.h addition. |
210 |