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
#include "myisam_priv.h"
16
#include "myisamdef.h"
17
17
#include <drizzled/util/test.h>
18
18
#include <sys/types.h>
19
19
#include <sys/mman.h>
21
21
#include <string.h>
24
using namespace drizzled;
27
23
static void mi_extra_keyflag(MI_INFO *info, enum ha_extra_function function);
57
53
/* Next/prev gives first/last */
58
54
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));
56
reinit_io_cache(&info->rec_cache,READ_CACHE,0,
57
(bool) (info->lock_type != F_UNLCK),
58
(bool) test(info->update & HA_STATE_ROW_CHANGED)
64
61
info->update= ((info->update & HA_STATE_CHANGED) | HA_STATE_NEXT_FOUND |
65
62
HA_STATE_PREV_FOUND);
77
74
if (info->opt_flag & WRITE_CACHE_USED)
79
76
info->opt_flag&= ~WRITE_CACHE_USED;
80
if ((error= info->rec_cache.end_io_cache()))
77
if ((error=end_io_cache(&info->rec_cache)))
83
80
if (!(info->opt_flag &
84
81
(READ_CACHE_USED | WRITE_CACHE_USED | MEMMAP_USED)))
86
83
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))))
84
my_default_record_cache_size);
85
if (!(init_io_cache(&info->rec_cache,info->dfile,
86
(uint) cmin(info->state->data_file_length+1,
88
READ_CACHE,0L,(bool) (info->lock_type != F_UNLCK),
89
MYF(share->write_flag & MY_WAIT_IF_FULL))))
92
91
info->opt_flag|=READ_CACHE_USED;
93
92
info->update&= ~HA_STATE_ROW_CHANGED;
99
98
case HA_EXTRA_REINIT_CACHE:
100
99
if (info->opt_flag & READ_CACHE_USED)
102
info->rec_cache.reinit_io_cache(internal::READ_CACHE,info->nextpos,
101
reinit_io_cache(&info->rec_cache,READ_CACHE,info->nextpos,
103
102
(bool) (info->lock_type != F_UNLCK),
104
103
(bool) test(info->update & HA_STATE_ROW_CHANGED));
105
104
info->update&= ~HA_STATE_ROW_CHANGED;
117
116
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))))
117
my_default_record_cache_size);
118
if (!(info->opt_flag &
119
(READ_CACHE_USED | WRITE_CACHE_USED | OPT_NO_ROWS)) &&
120
!share->state.header.uniques)
121
if (!(init_io_cache(&info->rec_cache,info->dfile, cache_size,
122
WRITE_CACHE,info->state->data_file_length,
123
(bool) (info->lock_type != F_UNLCK),
124
MYF(share->write_flag & MY_WAIT_IF_FULL))))
126
info->opt_flag|=WRITE_CACHE_USED;
127
info->update&= ~(HA_STATE_ROW_CHANGED |
126
info->opt_flag|=WRITE_CACHE_USED;
127
info->update&= ~(HA_STATE_ROW_CHANGED |
128
128
HA_STATE_WRITE_AT_END |
129
129
HA_STATE_EXTEND_BLOCK);
133
132
case HA_EXTRA_PREPARE_FOR_UPDATE:
134
133
if (info->s->data_file_type != DYNAMIC_RECORD)
138
137
if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
140
139
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
141
error= info->rec_cache.end_io_cache();
140
error=end_io_cache(&info->rec_cache);
142
141
/* Sergei will insert full text index caching here */
144
#if !defined(TARGET_OS_SOLARIS)
143
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE) && !defined(TARGET_OS_SOLARIS)
145
144
if (info->opt_flag & MEMMAP_USED)
146
145
madvise((char*) share->file_map, share->state.state.data_file_length,
239
238
case HA_EXTRA_FORCE_REOPEN:
240
THR_LOCK_myisam.lock();
239
pthread_mutex_lock(&THR_LOCK_myisam);
241
240
share->last_version= 0L; /* Impossible version */
242
THR_LOCK_myisam.unlock();
241
pthread_mutex_unlock(&THR_LOCK_myisam);
244
243
case HA_EXTRA_PREPARE_FOR_DROP:
245
THR_LOCK_myisam.lock();
244
pthread_mutex_lock(&THR_LOCK_myisam);
246
245
share->last_version= 0L; /* Impossible version */
247
246
#ifdef __WIN__REMOVE_OBSOLETE_WORKAROUND
248
247
/* Close the isam and data files as Win32 can't drop an open table */
248
pthread_mutex_lock(&share->intern_lock);
249
249
if (flush_key_blocks(share->key_cache, share->kfile,
250
250
(function == HA_EXTRA_FORCE_REOPEN ?
251
251
FLUSH_RELEASE : FLUSH_IGNORE_CHANGED)))
254
254
share->changed=1;
255
255
mi_print_error(info->s, HA_ERR_CRASHED);
256
256
mi_mark_crashed(info); /* Fatal error found */
265
265
info->was_locked=info->lock_type;
266
266
if (mi_lock_database(info,F_UNLCK))
268
268
info->lock_type = F_UNLCK;
270
270
if (share->kfile >= 0)
271
271
_mi_decrement_open_count(info);
272
if (share->kfile >= 0 && internal::my_close(share->kfile,MYF(0)))
272
if (share->kfile >= 0 && my_close(share->kfile,MYF(0)))
275
list<MI_INFO *>::iterator it= myisam_open_list.begin();
276
while (it != myisam_open_list.end())
276
for (list_element=myisam_open_list ;
278
list_element=list_element->next)
278
MI_INFO *tmpinfo= *it;
280
MI_INFO *tmpinfo=(MI_INFO*) list_element->data;
279
281
if (tmpinfo->s == info->s)
281
if (tmpinfo->dfile >= 0 && internal::my_close(tmpinfo->dfile,MYF(0)))
283
if (tmpinfo->dfile >= 0 && my_close(tmpinfo->dfile,MYF(0)))
283
285
tmpinfo->dfile= -1;
288
289
share->kfile= -1; /* Files aren't open anymore */
290
pthread_mutex_unlock(&share->intern_lock);
290
THR_LOCK_myisam.unlock();
292
pthread_mutex_unlock(&THR_LOCK_myisam);
292
294
case HA_EXTRA_FLUSH:
293
295
if (!share->temporary)
294
flush_key_blocks(share->getKeyCache(), share->kfile, FLUSH_KEEP);
296
flush_key_blocks(share->key_cache, share->kfile, FLUSH_KEEP);
295
297
#ifdef HAVE_PWRITE
296
298
_mi_decrement_open_count(info);
298
300
if (share->not_flushed)
300
share->not_flushed= false;
302
share->not_flushed=0;
303
if (my_sync(share->kfile, MYF(0)))
305
if (my_sync(info->dfile, MYF(0)))
310
mi_print_error(info->s, HA_ERR_CRASHED);
311
mi_mark_crashed(info); /* Fatal error found */
302
314
if (share->base.blobs)
303
mi_alloc_rec_buff(info, SIZE_MAX, &info->rec_buff);
315
mi_alloc_rec_buff(info, -1, &info->rec_buff);
305
317
case HA_EXTRA_NORMAL: /* Theese isn't in use */
306
318
info->quick_mode=0;
319
331
case HA_EXTRA_CHANGE_KEY_TO_DUP:
320
332
mi_extra_keyflag(info, function);
336
pthread_mutex_lock(&share->intern_lock);
338
Memory map the data file if it is not already mapped. It is safe
339
to memory map a file while other threads are using file I/O on it.
340
Assigning a new address to a function pointer is an atomic
341
operation. intern_lock prevents that two or more mappings are done
344
if (!share->file_map)
346
if (mi_dynmap_file(info, share->state.state.data_file_length))
348
error= my_errno= errno;
352
share->file_read= mi_mmap_pread;
353
share->file_write= mi_mmap_pwrite;
356
pthread_mutex_unlock(&share->intern_lock);
322
359
case HA_EXTRA_KEY_CACHE:
323
360
case HA_EXTRA_NO_KEY_CACHE:
369
void mi_set_index_cond_func(MI_INFO *info, index_cond_func_t func,
372
info->index_cond_func= func;
373
info->index_cond_func_arg= func_arg;
333
377
Start/Stop Inserting Duplicates Into a Table, WL#1648.
366
410
if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
368
412
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
369
error= info->rec_cache.end_io_cache();
413
error= end_io_cache(&info->rec_cache);
371
415
if (share->base.blobs)
372
mi_alloc_rec_buff(info, SIZE_MAX, &info->rec_buff);
373
#if !defined(TARGET_OS_SOLARIS)
416
mi_alloc_rec_buff(info, -1, &info->rec_buff);
417
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE) && !defined(TARGET_OS_SOLARIS)
374
418
if (info->opt_flag & MEMMAP_USED)
375
419
madvise((char*) share->file_map, share->state.state.data_file_length,