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"
17
#include <drizzled/util/test.h>
18
#include <sys/types.h>
16
#include "myisamdef.h"
17
#ifdef HAVE_SYS_MMAN_H
19
18
#include <sys/mman.h>
24
using namespace drizzled;
27
21
static void mi_extra_keyflag(MI_INFO *info, enum ha_extra_function function);
57
51
/* Next/prev gives first/last */
58
52
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));
54
reinit_io_cache(&info->rec_cache,READ_CACHE,0,
55
(bool) (info->lock_type != F_UNLCK),
56
(bool) test(info->update & HA_STATE_ROW_CHANGED)
64
59
info->update= ((info->update & HA_STATE_CHANGED) | HA_STATE_NEXT_FOUND |
65
60
HA_STATE_PREV_FOUND);
77
72
if (info->opt_flag & WRITE_CACHE_USED)
79
74
info->opt_flag&= ~WRITE_CACHE_USED;
80
if ((error= info->rec_cache.end_io_cache()))
75
if ((error=end_io_cache(&info->rec_cache)))
83
78
if (!(info->opt_flag &
84
79
(READ_CACHE_USED | WRITE_CACHE_USED | MEMMAP_USED)))
86
81
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))))
82
my_default_record_cache_size);
83
if (!(init_io_cache(&info->rec_cache,info->dfile,
84
(uint) min(info->state->data_file_length+1,
86
READ_CACHE,0L,(bool) (info->lock_type != F_UNLCK),
87
MYF(share->write_flag & MY_WAIT_IF_FULL))))
92
89
info->opt_flag|=READ_CACHE_USED;
93
90
info->update&= ~HA_STATE_ROW_CHANGED;
99
96
case HA_EXTRA_REINIT_CACHE:
100
97
if (info->opt_flag & READ_CACHE_USED)
102
info->rec_cache.reinit_io_cache(internal::READ_CACHE,info->nextpos,
99
reinit_io_cache(&info->rec_cache,READ_CACHE,info->nextpos,
103
100
(bool) (info->lock_type != F_UNLCK),
104
101
(bool) test(info->update & HA_STATE_ROW_CHANGED));
105
102
info->update&= ~HA_STATE_ROW_CHANGED;
117
114
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))))
115
my_default_record_cache_size);
116
if (!(info->opt_flag &
117
(READ_CACHE_USED | WRITE_CACHE_USED | OPT_NO_ROWS)) &&
118
!share->state.header.uniques)
119
if (!(init_io_cache(&info->rec_cache,info->dfile, cache_size,
120
WRITE_CACHE,info->state->data_file_length,
121
(bool) (info->lock_type != F_UNLCK),
122
MYF(share->write_flag & MY_WAIT_IF_FULL))))
126
info->opt_flag|=WRITE_CACHE_USED;
127
info->update&= ~(HA_STATE_ROW_CHANGED |
124
info->opt_flag|=WRITE_CACHE_USED;
125
info->update&= ~(HA_STATE_ROW_CHANGED |
128
126
HA_STATE_WRITE_AT_END |
129
127
HA_STATE_EXTEND_BLOCK);
133
130
case HA_EXTRA_PREPARE_FOR_UPDATE:
134
131
if (info->s->data_file_type != DYNAMIC_RECORD)
138
135
if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
140
137
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
141
error= info->rec_cache.end_io_cache();
138
error=end_io_cache(&info->rec_cache);
142
139
/* Sergei will insert full text index caching here */
144
#if !defined(TARGET_OS_SOLARIS)
141
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE)
145
142
if (info->opt_flag & MEMMAP_USED)
146
143
madvise((char*) share->file_map, share->state.state.data_file_length,
166
163
case HA_EXTRA_KEYREAD: /* Read only keys to record */
167
164
case HA_EXTRA_REMEMBER_POS:
168
165
info->opt_flag |= REMEMBER_OLD_POS;
169
memmove(info->lastkey+share->base.max_key_length*2,
170
info->lastkey,info->lastkey_length);
166
memcpy(info->lastkey+share->base.max_key_length*2,
167
info->lastkey,info->lastkey_length);
171
168
info->save_update= info->update;
172
169
info->save_lastinx= info->lastinx;
173
170
info->save_lastpos= info->lastpos;
183
180
case HA_EXTRA_RESTORE_POS:
184
181
if (info->opt_flag & REMEMBER_OLD_POS)
186
memmove(info->lastkey,
187
info->lastkey+share->base.max_key_length*2,
188
info->save_lastkey_length);
183
memcpy(info->lastkey,
184
info->lastkey+share->base.max_key_length*2,
185
info->save_lastkey_length);
189
186
info->update= info->save_update | HA_STATE_WRITTEN;
190
187
info->lastinx= info->save_lastinx;
191
188
info->lastpos= info->save_lastpos;
212
209
if (mi_is_any_key_active(share->state.key_map))
214
211
MI_KEYDEF *key=share->keyinfo;
216
213
for (i=0 ; i < share->base.keys ; i++,key++)
218
215
if (!(key->flag & HA_NOSAME) && info->s->base.auto_key != i+1)
239
236
case HA_EXTRA_FORCE_REOPEN:
240
THR_LOCK_myisam.lock();
237
pthread_mutex_lock(&THR_LOCK_myisam);
241
238
share->last_version= 0L; /* Impossible version */
242
THR_LOCK_myisam.unlock();
239
pthread_mutex_unlock(&THR_LOCK_myisam);
244
241
case HA_EXTRA_PREPARE_FOR_DROP:
245
THR_LOCK_myisam.lock();
242
pthread_mutex_lock(&THR_LOCK_myisam);
246
243
share->last_version= 0L; /* Impossible version */
247
244
#ifdef __WIN__REMOVE_OBSOLETE_WORKAROUND
248
245
/* Close the isam and data files as Win32 can't drop an open table */
246
pthread_mutex_lock(&share->intern_lock);
249
247
if (flush_key_blocks(share->key_cache, share->kfile,
250
248
(function == HA_EXTRA_FORCE_REOPEN ?
251
249
FLUSH_RELEASE : FLUSH_IGNORE_CHANGED)))
254
252
share->changed=1;
255
253
mi_print_error(info->s, HA_ERR_CRASHED);
256
254
mi_mark_crashed(info); /* Fatal error found */
265
263
info->was_locked=info->lock_type;
266
264
if (mi_lock_database(info,F_UNLCK))
268
266
info->lock_type = F_UNLCK;
270
268
if (share->kfile >= 0)
271
269
_mi_decrement_open_count(info);
272
if (share->kfile >= 0 && internal::my_close(share->kfile,MYF(0)))
270
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())
274
for (list_element=myisam_open_list ;
276
list_element=list_element->next)
278
MI_INFO *tmpinfo= *it;
278
MI_INFO *tmpinfo=(MI_INFO*) list_element->data;
279
279
if (tmpinfo->s == info->s)
281
if (tmpinfo->dfile >= 0 && internal::my_close(tmpinfo->dfile,MYF(0)))
281
if (tmpinfo->dfile >= 0 && my_close(tmpinfo->dfile,MYF(0)))
283
283
tmpinfo->dfile= -1;
288
287
share->kfile= -1; /* Files aren't open anymore */
288
pthread_mutex_unlock(&share->intern_lock);
290
THR_LOCK_myisam.unlock();
290
pthread_mutex_unlock(&THR_LOCK_myisam);
292
292
case HA_EXTRA_FLUSH:
293
293
if (!share->temporary)
294
flush_key_blocks(share->getKeyCache(), share->kfile, FLUSH_KEEP);
294
flush_key_blocks(share->key_cache, share->kfile, FLUSH_KEEP);
295
295
#ifdef HAVE_PWRITE
296
296
_mi_decrement_open_count(info);
298
298
if (share->not_flushed)
300
share->not_flushed= false;
300
share->not_flushed=0;
301
if (my_sync(share->kfile, MYF(0)))
303
if (my_sync(info->dfile, MYF(0)))
308
mi_print_error(info->s, HA_ERR_CRASHED);
309
mi_mark_crashed(info); /* Fatal error found */
302
312
if (share->base.blobs)
303
mi_alloc_rec_buff(info, SIZE_MAX, &info->rec_buff);
313
mi_alloc_rec_buff(info, -1, &info->rec_buff);
305
315
case HA_EXTRA_NORMAL: /* Theese isn't in use */
306
316
info->quick_mode=0;
313
323
info->opt_flag|= OPT_NO_ROWS;
315
325
case HA_EXTRA_PRELOAD_BUFFER_SIZE:
316
info->preload_buff_size= *((uint32_t *) extra_arg);
326
info->preload_buff_size= *((uint32_t *) extra_arg);
318
328
case HA_EXTRA_CHANGE_KEY_TO_UNIQUE:
319
329
case HA_EXTRA_CHANGE_KEY_TO_DUP:
320
330
mi_extra_keyflag(info, function);
334
pthread_mutex_lock(&share->intern_lock);
336
Memory map the data file if it is not already mapped. It is safe
337
to memory map a file while other threads are using file I/O on it.
338
Assigning a new address to a function pointer is an atomic
339
operation. intern_lock prevents that two or more mappings are done
342
if (!share->file_map)
344
if (mi_dynmap_file(info, share->state.state.data_file_length))
346
error= my_errno= errno;
350
share->file_read= mi_mmap_pread;
351
share->file_write= mi_mmap_pwrite;
354
pthread_mutex_unlock(&share->intern_lock);
322
357
case HA_EXTRA_KEY_CACHE:
323
358
case HA_EXTRA_NO_KEY_CACHE:
367
void mi_set_index_cond_func(MI_INFO *info, index_cond_func_t func,
370
info->index_cond_func= func;
371
info->index_cond_func_arg= func_arg;
333
375
Start/Stop Inserting Duplicates Into a Table, WL#1648.
335
377
static void mi_extra_keyflag(MI_INFO *info, enum ha_extra_function function)
339
381
for (idx= 0; idx< info->s->base.keys; idx++)
366
408
if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
368
410
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
369
error= info->rec_cache.end_io_cache();
411
error= end_io_cache(&info->rec_cache);
371
413
if (share->base.blobs)
372
mi_alloc_rec_buff(info, SIZE_MAX, &info->rec_buff);
373
#if !defined(TARGET_OS_SOLARIS)
414
mi_alloc_rec_buff(info, -1, &info->rec_buff);
415
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE)
374
416
if (info->opt_flag & MEMMAP_USED)
375
417
madvise((char*) share->file_map, share->state.state.data_file_length,