~drizzle-trunk/drizzle/development

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
1241.9.64 by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal.
21
#ifndef DRIZZLED_INTERNAL_IOCACHE_H
22
#define DRIZZLED_INTERNAL_IOCACHE_H
481.2.1 by Monty Taylor
Split iocache definitions into their own header.
23
1241.9.64 by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal.
24
#include "drizzled/internal/my_sys.h"
584.1.14 by Monty Taylor
Removed field.h from common_includes.
25
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
26
namespace drizzled
27
{
28
namespace internal
29
{
481.1.16 by Monty Taylor
Merged iocache.h addition.
30
481.2.1 by Monty Taylor
Split iocache definitions into their own header.
31
struct st_io_cache;
32
typedef int (*IO_CACHE_CALLBACK)(struct st_io_cache*);
33
34
typedef struct st_io_cache_share
35
{
36
  pthread_mutex_t       mutex;           /* To sync on reads into buffer. */
37
  pthread_cond_t        cond;            /* To wait for signals. */
38
  pthread_cond_t        cond_writer;     /* For a synchronized writer. */
39
  /* Offset in file corresponding to the first byte of buffer. */
1241.13.1 by Monty Taylor
Put my_off_t back... but this time localized only to myisam and mysys.
40
  my_off_t              pos_in_file;
481.2.1 by Monty Taylor
Split iocache definitions into their own header.
41
  /* If a synchronized write cache is the source of the data. */
42
  struct st_io_cache    *source_cache;
43
  unsigned char                 *buffer;         /* The read buffer. */
44
  unsigned char                 *read_end;       /* Behind last valid byte of buffer. */
45
  int                   running_threads; /* threads not in lock. */
46
  int                   total_threads;   /* threads sharing the cache. */
47
  int                   error;           /* Last error. */
48
} IO_CACHE_SHARE;
49
50
typedef struct st_io_cache    /* Used when cacheing files */
51
{
52
  /* 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.
53
  my_off_t pos_in_file;
481.2.1 by Monty Taylor
Split iocache definitions into their own header.
54
  /*
55
    The offset of end of file for READ_CACHE and WRITE_CACHE.
56
    For SEQ_READ_APPEND it the maximum of the actual end of file and
57
    the position represented by read_end.
58
  */
1241.13.1 by Monty Taylor
Put my_off_t back... but this time localized only to myisam and mysys.
59
  my_off_t end_of_file;
481.2.1 by Monty Taylor
Split iocache definitions into their own header.
60
  /* Points to current read position in the buffer */
61
  unsigned char  *read_pos;
62
  /* the non-inclusive boundary in the buffer for the currently valid read */
63
  unsigned char  *read_end;
64
  unsigned char  *buffer;        /* The read buffer */
65
  /* Used in ASYNC_IO */
66
  unsigned char  *request_pos;
67
68
  /* Only used in WRITE caches and in SEQ_READ_APPEND to buffer writes */
69
  unsigned char  *write_buffer;
70
  /*
71
    Only used in SEQ_READ_APPEND, and points to the current read position
72
    in the write buffer. Note that reads in SEQ_READ_APPEND caches can
73
    happen from both read buffer (unsigned char* buffer) and write buffer
74
    (unsigned char* write_buffer).
75
  */
76
  unsigned char *append_read_pos;
77
  /* Points to current write position in the write buffer */
78
  unsigned char *write_pos;
79
  /* The non-inclusive boundary of the valid write area */
80
  unsigned char *write_end;
81
82
  /*
83
    Current_pos and current_end are convenience variables used by
84
    my_b_tell() and other routines that need to know the current offset
85
    current_pos points to &write_pos, and current_end to &write_end in a
86
    WRITE_CACHE, and &read_pos and &read_end respectively otherwise
87
  */
88
  unsigned char  **current_pos, **current_end;
89
  /*
90
    The lock is for append buffer used in SEQ_READ_APPEND cache
91
    need mutex copying from append buffer to read buffer.
92
  */
93
  pthread_mutex_t append_buffer_lock;
94
  /*
95
    The following is used when several threads are reading the
96
    same file in parallel. They are synchronized on disk
97
    accesses reading the cached part of the file asynchronously.
98
    It should be set to NULL to disable the feature.  Only
99
    READ_CACHE mode is supported.
100
  */
101
  IO_CACHE_SHARE *share;
102
  /*
103
    A caller will use my_b_read() macro to read from the cache
104
    if the data is already in cache, it will be simply copied with
105
    memcpy() and internal variables will be accordinging updated with
106
    no functions invoked. However, if the data is not fully in the cache,
107
    my_b_read() will call read_function to fetch the data. read_function
108
    must never be invoked directly.
109
  */
110
  int (*read_function)(struct st_io_cache *,unsigned char *,size_t);
111
  /*
112
    Same idea as in the case of read_function, except my_b_write() needs to
113
    be replaced with my_b_append() for a SEQ_READ_APPEND cache
114
  */
115
  int (*write_function)(struct st_io_cache *,const unsigned char *,size_t);
116
  /*
117
    Specifies the type of the cache. Depending on the type of the cache
118
    certain operations might not be available and yield unpredicatable
119
    results. Details to be documented later
120
  */
121
  enum cache_type type;
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
122
  int error;
481.2.1 by Monty Taylor
Split iocache definitions into their own header.
123
  /*
124
    Callbacks when the actual read I/O happens. These were added and
125
    are currently used for binary logging of LOAD DATA INFILE - when a
126
    block is read from the file, we create a block create/append event, and
127
    when IO_CACHE is closed, we create an end event. These functions could,
128
    of course be used for other things
129
  */
130
  IO_CACHE_CALLBACK pre_read;
131
  IO_CACHE_CALLBACK post_read;
132
  IO_CACHE_CALLBACK pre_close;
133
  void* arg;        /* for use by pre/post_read */
134
  char *file_name;      /* if used with 'open_cached_file' */
135
  char *dir,*prefix;
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
136
  int file; /* file descriptor */
481.2.1 by Monty Taylor
Split iocache definitions into their own header.
137
  /*
138
    seek_not_done is set by my_b_seek() to inform the upcoming read/write
139
    operation that a seek needs to be preformed prior to the actual I/O
140
    error is 0 if the cache operation was successful, -1 if there was a
141
    "hard" error, and the actual number of I/O-ed bytes if the read/write was
142
    partial.
143
  */
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
144
  int  seek_not_done;
481.2.1 by Monty Taylor
Split iocache definitions into their own header.
145
  /* buffer_length is memory size allocated for buffer or write_buffer */
146
  size_t  buffer_length;
147
  /* read_length is the same as buffer_length except when we use async io */
148
  size_t  read_length;
149
  myf  myflags;      /* Flags used to my_read/my_write */
150
  /*
151
    alloced_buffer is 1 if the buffer was allocated by init_io_cache() and
152
    0 if it was supplied by the user.
153
    Currently READ_NET is the only one that will use a buffer allocated
154
    somewhere else
155
  */
156
  bool alloced_buffer;
157
#ifdef HAVE_AIOWAIT
158
  /*
159
    As inidicated by ifdef, this is for async I/O, which is not currently
160
    used (because it's not reliable on all systems)
161
  */
162
  uint32_t inited;
1241.13.1 by Monty Taylor
Put my_off_t back... but this time localized only to myisam and mysys.
163
  my_off_t aio_read_pos;
481.2.1 by Monty Taylor
Split iocache definitions into their own header.
164
  my_aio_result aio_result;
165
#endif
166
} IO_CACHE;
167
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
168
extern int init_io_cache(IO_CACHE *info,int file,size_t cachesize,
1241.13.1 by Monty Taylor
Put my_off_t back... but this time localized only to myisam and mysys.
169
                         enum cache_type type,my_off_t seek_offset,
481.2.1 by Monty Taylor
Split iocache definitions into their own header.
170
                         bool use_async_io, myf cache_myflags);
171
extern bool reinit_io_cache(IO_CACHE *info,enum cache_type type,
1241.13.1 by Monty Taylor
Put my_off_t back... but this time localized only to myisam and mysys.
172
                            my_off_t seek_offset,bool use_async_io,
481.2.1 by Monty Taylor
Split iocache definitions into their own header.
173
                            bool clear_cache);
174
extern void setup_io_cache(IO_CACHE* info);
175
extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
176
                                IO_CACHE *write_cache, uint32_t num_threads);
177
extern void remove_io_thread(IO_CACHE *info);
178
extern int _my_b_get(IO_CACHE *info);
179
extern int _my_b_async_read(IO_CACHE *info,unsigned char *Buffer,size_t Count);
180
181
extern int my_block_write(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.
182
                          size_t Count, my_off_t pos);
481.2.1 by Monty Taylor
Split iocache definitions into their own header.
183
extern int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock);
184
185
#define flush_io_cache(info) my_b_flush_io_cache((info),1)
186
187
extern int end_io_cache(IO_CACHE *info);
188
extern bool open_cached_file(IO_CACHE *cache,const char *dir,
189
                             const char *prefix, size_t cache_size,
190
                             myf cache_myflags);
191
extern bool real_open_cached_file(IO_CACHE *cache);
192
extern void close_cached_file(IO_CACHE *cache);
193
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
194
} /* namespace internal */
195
} /* namespace drizzled */
481.1.16 by Monty Taylor
Merged iocache.h addition.
196
1241.9.64 by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal.
197
#endif /* DRIZZLED_INTERNAL_IOCACHE_H */