12
12
You should have received a copy of the GNU General Public License
13
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
16
#include "myisam_priv.h"
17
17
#include <drizzled/util/test.h>
57
56
/* Next/prev gives first/last */
58
57
if (info->opt_flag & READ_CACHE_USED)
60
info->rec_cache.reinit_io_cache(internal::READ_CACHE,0,
61
(bool) (info->lock_type != F_UNLCK),
62
(bool) test(info->update & HA_STATE_ROW_CHANGED));
59
reinit_io_cache(&info->rec_cache,READ_CACHE,0,
60
(bool) (info->lock_type != F_UNLCK),
61
(bool) test(info->update & HA_STATE_ROW_CHANGED)
64
64
info->update= ((info->update & HA_STATE_CHANGED) | HA_STATE_NEXT_FOUND |
65
65
HA_STATE_PREV_FOUND);
77
77
if (info->opt_flag & WRITE_CACHE_USED)
79
79
info->opt_flag&= ~WRITE_CACHE_USED;
80
if ((error= info->rec_cache.end_io_cache()))
80
if ((error=end_io_cache(&info->rec_cache)))
83
83
if (!(info->opt_flag &
84
84
(READ_CACHE_USED | WRITE_CACHE_USED | MEMMAP_USED)))
86
86
cache_size= (extra_arg ? *(uint32_t*) extra_arg :
87
internal::my_default_record_cache_size);
88
if (!(info->rec_cache.init_io_cache(info->dfile, (uint) min((uint32_t)info->state->data_file_length+1, cache_size),
89
internal::READ_CACHE,0L,(bool) (info->lock_type != F_UNLCK),
90
MYF(share->write_flag & MY_WAIT_IF_FULL))))
87
my_default_record_cache_size);
88
if (!(init_io_cache(&info->rec_cache,info->dfile,
89
(uint) min((uint32_t)info->state->data_file_length+1,
91
READ_CACHE,0L,(bool) (info->lock_type != F_UNLCK),
92
MYF(share->write_flag & MY_WAIT_IF_FULL))))
92
94
info->opt_flag|=READ_CACHE_USED;
93
95
info->update&= ~HA_STATE_ROW_CHANGED;
99
101
case HA_EXTRA_REINIT_CACHE:
100
102
if (info->opt_flag & READ_CACHE_USED)
102
info->rec_cache.reinit_io_cache(internal::READ_CACHE,info->nextpos,
104
reinit_io_cache(&info->rec_cache,READ_CACHE,info->nextpos,
103
105
(bool) (info->lock_type != F_UNLCK),
104
106
(bool) test(info->update & HA_STATE_ROW_CHANGED));
105
107
info->update&= ~HA_STATE_ROW_CHANGED;
117
119
cache_size= (extra_arg ? *(uint32_t*) extra_arg :
118
internal::my_default_record_cache_size);
119
if (not (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED | OPT_NO_ROWS)) && !share->state.header.uniques)
121
if (not (info->rec_cache.init_io_cache(info->dfile, cache_size,
122
internal::WRITE_CACHE,info->state->data_file_length,
123
(bool) (info->lock_type != F_UNLCK),
124
MYF(share->write_flag & MY_WAIT_IF_FULL))))
120
my_default_record_cache_size);
121
if (!(info->opt_flag &
122
(READ_CACHE_USED | WRITE_CACHE_USED | OPT_NO_ROWS)) &&
123
!share->state.header.uniques)
124
if (!(init_io_cache(&info->rec_cache,info->dfile, cache_size,
125
WRITE_CACHE,info->state->data_file_length,
126
(bool) (info->lock_type != F_UNLCK),
127
MYF(share->write_flag & MY_WAIT_IF_FULL))))
126
info->opt_flag|=WRITE_CACHE_USED;
127
info->update&= ~(HA_STATE_ROW_CHANGED |
129
info->opt_flag|=WRITE_CACHE_USED;
130
info->update&= ~(HA_STATE_ROW_CHANGED |
128
131
HA_STATE_WRITE_AT_END |
129
132
HA_STATE_EXTEND_BLOCK);
133
135
case HA_EXTRA_PREPARE_FOR_UPDATE:
134
136
if (info->s->data_file_type != DYNAMIC_RECORD)
138
140
if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
140
142
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
141
error= info->rec_cache.end_io_cache();
143
error=end_io_cache(&info->rec_cache);
142
144
/* Sergei will insert full text index caching here */
144
#if !defined(TARGET_OS_SOLARIS)
146
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE) && !defined(TARGET_OS_SOLARIS)
145
147
if (info->opt_flag & MEMMAP_USED)
146
148
madvise((char*) share->file_map, share->state.state.data_file_length,
239
241
case HA_EXTRA_FORCE_REOPEN:
240
THR_LOCK_myisam.lock();
242
pthread_mutex_lock(&THR_LOCK_myisam);
241
243
share->last_version= 0L; /* Impossible version */
242
THR_LOCK_myisam.unlock();
244
pthread_mutex_unlock(&THR_LOCK_myisam);
244
246
case HA_EXTRA_PREPARE_FOR_DROP:
245
THR_LOCK_myisam.lock();
247
pthread_mutex_lock(&THR_LOCK_myisam);
246
248
share->last_version= 0L; /* Impossible version */
247
249
#ifdef __WIN__REMOVE_OBSOLETE_WORKAROUND
248
250
/* Close the isam and data files as Win32 can't drop an open table */
251
pthread_mutex_lock(&share->intern_lock);
249
252
if (flush_key_blocks(share->key_cache, share->kfile,
250
253
(function == HA_EXTRA_FORCE_REOPEN ?
251
254
FLUSH_RELEASE : FLUSH_IGNORE_CHANGED)))
254
257
share->changed=1;
255
258
mi_print_error(info->s, HA_ERR_CRASHED);
256
259
mi_mark_crashed(info); /* Fatal error found */
265
268
info->was_locked=info->lock_type;
266
269
if (mi_lock_database(info,F_UNLCK))
268
271
info->lock_type = F_UNLCK;
270
273
if (share->kfile >= 0)
271
274
_mi_decrement_open_count(info);
272
if (share->kfile >= 0 && internal::my_close(share->kfile,MYF(0)))
275
if (share->kfile >= 0 && my_close(share->kfile,MYF(0)))
275
278
list<MI_INFO *>::iterator it= myisam_open_list.begin();
276
279
while (it != myisam_open_list.end())
278
281
MI_INFO *tmpinfo= *it;
279
282
if (tmpinfo->s == info->s)
281
if (tmpinfo->dfile >= 0 && internal::my_close(tmpinfo->dfile,MYF(0)))
284
if (tmpinfo->dfile >= 0 && my_close(tmpinfo->dfile,MYF(0)))
283
286
tmpinfo->dfile= -1;
288
291
share->kfile= -1; /* Files aren't open anymore */
292
pthread_mutex_unlock(&share->intern_lock);
290
THR_LOCK_myisam.unlock();
294
pthread_mutex_unlock(&THR_LOCK_myisam);
292
296
case HA_EXTRA_FLUSH:
293
297
if (!share->temporary)
294
flush_key_blocks(share->getKeyCache(), share->kfile, FLUSH_KEEP);
298
flush_key_blocks(share->key_cache, share->kfile, FLUSH_KEEP);
295
299
#ifdef HAVE_PWRITE
296
300
_mi_decrement_open_count(info);
298
302
if (share->not_flushed)
300
share->not_flushed= false;
304
share->not_flushed=0;
305
if (my_sync(share->kfile, MYF(0)))
307
if (my_sync(info->dfile, MYF(0)))
312
mi_print_error(info->s, HA_ERR_CRASHED);
313
mi_mark_crashed(info); /* Fatal error found */
302
316
if (share->base.blobs)
303
mi_alloc_rec_buff(info, SIZE_MAX, &info->rec_buff);
317
mi_alloc_rec_buff(info, -1, &info->rec_buff);
305
319
case HA_EXTRA_NORMAL: /* Theese isn't in use */
306
320
info->quick_mode=0;
366
380
if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
368
382
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
369
error= info->rec_cache.end_io_cache();
383
error= end_io_cache(&info->rec_cache);
371
385
if (share->base.blobs)
372
mi_alloc_rec_buff(info, SIZE_MAX, &info->rec_buff);
373
#if !defined(TARGET_OS_SOLARIS)
386
mi_alloc_rec_buff(info, -1, &info->rec_buff);
387
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE) && !defined(TARGET_OS_SOLARIS)
374
388
if (info->opt_flag & MEMMAP_USED)
375
389
madvise((char*) share->file_map, share->state.state.data_file_length,