~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/internal/iocache.h

  • Committer: Stewart Smith
  • Date: 2008-08-02 07:12:36 UTC
  • mfrom: (258 drizzle)
  • mto: This revision was merged to the branch mainline in revision 408.
  • Revision ID: stewart@flamingspork.com-20080802071236-kbcozl5zm23j6mkn
merge from mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
21
 
#ifndef DRIZZLED_INTERNAL_IOCACHE_H
22
 
#define DRIZZLED_INTERNAL_IOCACHE_H
23
 
 
24
 
#include "drizzled/internal/my_sys.h"
25
 
 
26
 
namespace drizzled
27
 
{
28
 
namespace internal
29
 
{
30
 
 
31
 
struct st_io_cache;
32
 
typedef int (*IO_CACHE_CALLBACK)(struct st_io_cache*);
33
 
 
34
 
struct st_io_cache    /* Used when cacheing files */
35
 
{
36
 
  /* Offset in file corresponding to the first byte of unsigned char* buffer. */
37
 
  my_off_t pos_in_file;
38
 
  /*
39
 
    The offset of end of file for READ_CACHE and WRITE_CACHE.
40
 
    For SEQ_READ_APPEND it the maximum of the actual end of file and
41
 
    the position represented by read_end.
42
 
  */
43
 
  my_off_t end_of_file;
44
 
  /* Points to current read position in the buffer */
45
 
  unsigned char  *read_pos;
46
 
  /* the non-inclusive boundary in the buffer for the currently valid read */
47
 
  unsigned char  *read_end;
48
 
  unsigned char  *buffer;        /* The read buffer */
49
 
  /* Used in ASYNC_IO */
50
 
  unsigned char  *request_pos;
51
 
 
52
 
  /* Only used in WRITE caches and in SEQ_READ_APPEND to buffer writes */
53
 
  unsigned char  *write_buffer;
54
 
  /*
55
 
    Only used in SEQ_READ_APPEND, and points to the current read position
56
 
    in the write buffer. Note that reads in SEQ_READ_APPEND caches can
57
 
    happen from both read buffer (unsigned char* buffer) and write buffer
58
 
    (unsigned char* write_buffer).
59
 
  */
60
 
  unsigned char *append_read_pos;
61
 
  /* Points to current write position in the write buffer */
62
 
  unsigned char *write_pos;
63
 
  /* The non-inclusive boundary of the valid write area */
64
 
  unsigned char *write_end;
65
 
 
66
 
  /*
67
 
    Current_pos and current_end are convenience variables used by
68
 
    my_b_tell() and other routines that need to know the current offset
69
 
    current_pos points to &write_pos, and current_end to &write_end in a
70
 
    WRITE_CACHE, and &read_pos and &read_end respectively otherwise
71
 
  */
72
 
  unsigned char  **current_pos, **current_end;
73
 
  /*
74
 
    A caller will use my_b_read() macro to read from the cache
75
 
    if the data is already in cache, it will be simply copied with
76
 
    memcpy() and internal variables will be accordinging updated with
77
 
    no functions invoked. However, if the data is not fully in the cache,
78
 
    my_b_read() will call read_function to fetch the data. read_function
79
 
    must never be invoked directly.
80
 
  */
81
 
  int (*read_function)(struct st_io_cache *,unsigned char *,size_t);
82
 
  /*
83
 
    Same idea as in the case of read_function, except my_b_write() needs to
84
 
    be replaced with my_b_append() for a SEQ_READ_APPEND cache
85
 
  */
86
 
  int (*write_function)(struct st_io_cache *,const unsigned char *,size_t);
87
 
  /*
88
 
    Specifies the type of the cache. Depending on the type of the cache
89
 
    certain operations might not be available and yield unpredicatable
90
 
    results. Details to be documented later
91
 
  */
92
 
  enum cache_type type;
93
 
  int error;
94
 
  /*
95
 
    Callbacks when the actual read I/O happens. These were added and
96
 
    are currently used for binary logging of LOAD DATA INFILE - when a
97
 
    block is read from the file, we create a block create/append event, and
98
 
    when IO_CACHE is closed, we create an end event. These functions could,
99
 
    of course be used for other things
100
 
  */
101
 
  IO_CACHE_CALLBACK pre_read;
102
 
  IO_CACHE_CALLBACK post_read;
103
 
  IO_CACHE_CALLBACK pre_close;
104
 
  void* arg;        /* for use by pre/post_read */
105
 
  char *file_name;      /* if used with 'open_cached_file' */
106
 
  char *dir,*prefix;
107
 
  int file; /* file descriptor */
108
 
  /*
109
 
    seek_not_done is set by my_b_seek() to inform the upcoming read/write
110
 
    operation that a seek needs to be preformed prior to the actual I/O
111
 
    error is 0 if the cache operation was successful, -1 if there was a
112
 
    "hard" error, and the actual number of I/O-ed bytes if the read/write was
113
 
    partial.
114
 
  */
115
 
  int  seek_not_done;
116
 
  /* buffer_length is memory size allocated for buffer or write_buffer */
117
 
  size_t  buffer_length;
118
 
  /* read_length is the same as buffer_length except when we use async io */
119
 
  size_t  read_length;
120
 
  myf  myflags;      /* Flags used to my_read/my_write */
121
 
  /*
122
 
    alloced_buffer is 1 if the buffer was allocated by init_io_cache() and
123
 
    0 if it was supplied by the user.
124
 
    Currently READ_NET is the only one that will use a buffer allocated
125
 
    somewhere else
126
 
  */
127
 
  bool alloced_buffer;
128
 
#ifdef HAVE_AIOWAIT
129
 
  /*
130
 
    As inidicated by ifdef, this is for async I/O, which is not currently
131
 
    used (because it's not reliable on all systems)
132
 
  */
133
 
  uint32_t inited;
134
 
  my_off_t aio_read_pos;
135
 
  my_aio_result aio_result;
136
 
#endif
137
 
 
138
 
  st_io_cache() :
139
 
    pos_in_file(0),
140
 
    end_of_file(0),
141
 
    read_pos(0),
142
 
    read_end(0),
143
 
    buffer(0),
144
 
    request_pos(0),
145
 
    write_buffer(0),
146
 
    append_read_pos(0),
147
 
    write_pos(0),
148
 
    write_end(0),
149
 
    current_pos(0),
150
 
    current_end(0),
151
 
    read_function(0),
152
 
    write_function(0),
153
 
    type(TYPE_NOT_SET),
154
 
    error(0),
155
 
    pre_read(0),
156
 
    post_read(0),
157
 
    pre_close(0),
158
 
    arg(0),
159
 
    file_name(0),
160
 
    dir(0),
161
 
    prefix(0),
162
 
    file(0),
163
 
    seek_not_done(0),
164
 
    buffer_length(0),
165
 
    read_length(0),
166
 
    myflags(0),
167
 
    alloced_buffer(0)
168
 
#ifdef HAVE_AIOWAIT
169
 
    ,
170
 
    inited(0),
171
 
    aio_read_pos(0),
172
 
    aio_result(0)
173
 
#endif
174
 
  { }
175
 
 
176
 
  ~st_io_cache()
177
 
  { }
178
 
 
179
 
  void close_cached_file();
180
 
  bool real_open_cached_file();
181
 
  int end_io_cache();
182
 
  int init_io_cache(int file, size_t cachesize,
183
 
                    enum cache_type type, my_off_t seek_offset,
184
 
                    bool use_async_io, myf cache_myflags);
185
 
  void init_functions();
186
 
 
187
 
  bool reinit_io_cache(enum cache_type type_arg,
188
 
                       my_off_t seek_offset,
189
 
                       bool use_async_io,
190
 
                       bool clear_cache);
191
 
  void setup_io_cache();
192
 
  bool open_cached_file(const char *dir,
193
 
                        const char *prefix, size_t cache_size,
194
 
                        myf cache_myflags);
195
 
 
196
 
};
197
 
 
198
 
typedef struct st_io_cache IO_CACHE;    /* Used when cacheing files */
199
 
 
200
 
extern int _my_b_get(st_io_cache *info);
201
 
extern int _my_b_async_read(st_io_cache *info,unsigned char *Buffer,size_t Count);
202
 
 
203
 
extern int my_block_write(st_io_cache *info, const unsigned char *Buffer,
204
 
                          size_t Count, my_off_t pos);
205
 
extern int my_b_flush_io_cache(st_io_cache *info, int need_append_buffer_lock);
206
 
 
207
 
#define flush_io_cache(info) my_b_flush_io_cache((info),1)
208
 
 
209
 
} /* namespace internal */
210
 
} /* namespace drizzled */
211
 
 
212
 
#endif /* DRIZZLED_INTERNAL_IOCACHE_H */