~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/iocache.h

  • Committer: Brian Aker
  • Date: 2009-02-21 00:18:15 UTC
  • Revision ID: brian@tangent.org-20090221001815-x20e8h71e984lvs1
Completion (?) of uint conversion.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
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
 
{
 
21
#ifndef mysys_iocache_h
 
22
#define mysys_iocache_h
 
23
 
 
24
#include <mysys/my_sys.h>
 
25
 
 
26
#if defined(__cplusplus)
 
27
extern "C" {
 
28
#endif
30
29
 
31
30
struct st_io_cache;
32
31
typedef int (*IO_CACHE_CALLBACK)(struct st_io_cache*);
33
32
 
34
 
struct st_io_cache    /* Used when cacheing files */
 
33
typedef struct st_io_cache_share
 
34
{
 
35
  pthread_mutex_t       mutex;           /* To sync on reads into buffer. */
 
36
  pthread_cond_t        cond;            /* To wait for signals. */
 
37
  pthread_cond_t        cond_writer;     /* For a synchronized writer. */
 
38
  /* Offset in file corresponding to the first byte of buffer. */
 
39
  my_off_t              pos_in_file;
 
40
  /* If a synchronized write cache is the source of the data. */
 
41
  struct st_io_cache    *source_cache;
 
42
  unsigned char                 *buffer;         /* The read buffer. */
 
43
  unsigned char                 *read_end;       /* Behind last valid byte of buffer. */
 
44
  int                   running_threads; /* threads not in lock. */
 
45
  int                   total_threads;   /* threads sharing the cache. */
 
46
  int                   error;           /* Last error. */
 
47
#ifdef NOT_YET_IMPLEMENTED
 
48
  /* whether the structure should be free'd */
 
49
  bool alloced;
 
50
#endif
 
51
} IO_CACHE_SHARE;
 
52
 
 
53
typedef struct st_io_cache    /* Used when cacheing files */
35
54
{
36
55
  /* Offset in file corresponding to the first byte of unsigned char* buffer. */
37
56
  my_off_t pos_in_file;
71
90
  */
72
91
  unsigned char  **current_pos, **current_end;
73
92
  /*
 
93
    The lock is for append buffer used in SEQ_READ_APPEND cache
 
94
    need mutex copying from append buffer to read buffer.
 
95
  */
 
96
  pthread_mutex_t append_buffer_lock;
 
97
  /*
 
98
    The following is used when several threads are reading the
 
99
    same file in parallel. They are synchronized on disk
 
100
    accesses reading the cached part of the file asynchronously.
 
101
    It should be set to NULL to disable the feature.  Only
 
102
    READ_CACHE mode is supported.
 
103
  */
 
104
  IO_CACHE_SHARE *share;
 
105
  /*
74
106
    A caller will use my_b_read() macro to read from the cache
75
107
    if the data is already in cache, it will be simply copied with
76
108
    memcpy() and internal variables will be accordinging updated with
90
122
    results. Details to be documented later
91
123
  */
92
124
  enum cache_type type;
93
 
  int error;
94
125
  /*
95
126
    Callbacks when the actual read I/O happens. These were added and
96
127
    are currently used for binary logging of LOAD DATA INFILE - when a
101
132
  IO_CACHE_CALLBACK pre_read;
102
133
  IO_CACHE_CALLBACK post_read;
103
134
  IO_CACHE_CALLBACK pre_close;
 
135
  /*
 
136
    Counts the number of times, when we were forced to use disk. We use it to
 
137
    increase the binlog_cache_disk_use status variable.
 
138
  */
 
139
  uint32_t disk_writes;
104
140
  void* arg;        /* for use by pre/post_read */
105
141
  char *file_name;      /* if used with 'open_cached_file' */
106
142
  char *dir,*prefix;
107
 
  int file; /* file descriptor */
 
143
  File file; /* file descriptor */
108
144
  /*
109
145
    seek_not_done is set by my_b_seek() to inform the upcoming read/write
110
146
    operation that a seek needs to be preformed prior to the actual I/O
112
148
    "hard" error, and the actual number of I/O-ed bytes if the read/write was
113
149
    partial.
114
150
  */
115
 
  int  seek_not_done;
 
151
  int  seek_not_done,error;
116
152
  /* buffer_length is memory size allocated for buffer or write_buffer */
117
153
  size_t  buffer_length;
118
154
  /* read_length is the same as buffer_length except when we use async io */
134
170
  my_off_t aio_read_pos;
135
171
  my_aio_result aio_result;
136
172
#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,
 
173
} IO_CACHE;
 
174
 
 
175
/* tell write offset in the SEQ_APPEND cache */
 
176
int      my_b_copy_to_file(IO_CACHE *cache, FILE *file);
 
177
my_off_t my_b_append_tell(IO_CACHE* info);
 
178
my_off_t my_b_safe_tell(IO_CACHE* info); /* picks the correct tell() */
 
179
 
 
180
extern int init_io_cache(IO_CACHE *info,File file,size_t cachesize,
 
181
                         enum cache_type type,my_off_t seek_offset,
 
182
                         bool use_async_io, myf cache_myflags);
 
183
extern bool reinit_io_cache(IO_CACHE *info,enum cache_type type,
 
184
                            my_off_t seek_offset,bool use_async_io,
 
185
                            bool clear_cache);
 
186
extern void setup_io_cache(IO_CACHE* info);
 
187
extern int _my_b_read(IO_CACHE *info,unsigned char *Buffer,size_t Count);
 
188
extern int _my_b_read_r(IO_CACHE *info,unsigned char *Buffer,size_t Count);
 
189
extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
 
190
                                IO_CACHE *write_cache, uint32_t num_threads);
 
191
extern void remove_io_thread(IO_CACHE *info);
 
192
extern int _my_b_seq_read(IO_CACHE *info,unsigned char *Buffer,size_t Count);
 
193
extern int _my_b_net_read(IO_CACHE *info,unsigned char *Buffer,size_t Count);
 
194
extern int _my_b_get(IO_CACHE *info);
 
195
extern int _my_b_async_read(IO_CACHE *info,unsigned char *Buffer,size_t Count);
 
196
extern int _my_b_write(IO_CACHE *info,const unsigned char *Buffer,
 
197
                       size_t Count);
 
198
extern int my_b_append(IO_CACHE *info,const unsigned char *Buffer,
 
199
                       size_t Count);
 
200
extern int my_b_safe_write(IO_CACHE *info,const unsigned char *Buffer,
 
201
                           size_t Count);
 
202
 
 
203
extern int my_block_write(IO_CACHE *info, const unsigned char *Buffer,
204
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);
 
205
extern int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock);
206
206
 
207
207
#define flush_io_cache(info) my_b_flush_io_cache((info),1)
208
208
 
209
 
} /* namespace internal */
210
 
} /* namespace drizzled */
211
 
 
212
 
#endif /* DRIZZLED_INTERNAL_IOCACHE_H */
 
209
extern int end_io_cache(IO_CACHE *info);
 
210
extern size_t my_b_fill(IO_CACHE *info);
 
211
extern void my_b_seek(IO_CACHE *info,my_off_t pos);
 
212
extern size_t my_b_gets(IO_CACHE *info, char *to, size_t max_length);
 
213
extern my_off_t my_b_filelength(IO_CACHE *info);
 
214
extern size_t my_b_printf(IO_CACHE *info, const char* fmt, ...);
 
215
extern size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list ap);
 
216
extern bool open_cached_file(IO_CACHE *cache,const char *dir,
 
217
                             const char *prefix, size_t cache_size,
 
218
                             myf cache_myflags);
 
219
extern bool real_open_cached_file(IO_CACHE *cache);
 
220
extern void close_cached_file(IO_CACHE *cache);
 
221
 
 
222
#if defined(__cplusplus)
 
223
}
 
224
#endif
 
225
 
 
226
#endif