13
13
along with this program; if not, write to the Free Software
14
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>
26
21
static void mi_extra_keyflag(MI_INFO *info, enum ha_extra_function function);
69
64
(share->options & HA_OPTION_PACK_RECORD))
71
66
error=1; /* Not possibly if not locked */
75
70
if (info->s->file_map) /* Don't use cache if mmap */
72
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE)
73
if ((share->options & HA_OPTION_COMPRESS_RECORD))
75
pthread_mutex_lock(&share->intern_lock);
76
if (_mi_memmap_file(info))
78
/* We don't nead MADV_SEQUENTIAL if small file */
79
madvise((char*) share->file_map, share->state.state.data_file_length,
80
share->state.state.data_file_length <= RECORD_CACHE_SIZE*16 ?
81
MADV_RANDOM : MADV_SEQUENTIAL);
82
pthread_mutex_unlock(&share->intern_lock);
85
pthread_mutex_unlock(&share->intern_lock);
77
88
if (info->opt_flag & WRITE_CACHE_USED)
79
90
info->opt_flag&= ~WRITE_CACHE_USED;
83
94
if (!(info->opt_flag &
84
95
(READ_CACHE_USED | WRITE_CACHE_USED | MEMMAP_USED)))
86
cache_size= (extra_arg ? *(uint32_t*) extra_arg :
97
cache_size= (extra_arg ? *(ulong*) extra_arg :
87
98
my_default_record_cache_size);
88
99
if (!(init_io_cache(&info->rec_cache,info->dfile,
89
(uint) min((uint32_t)info->state->data_file_length+1,
100
(uint) min(info->state->data_file_length+1,
91
102
READ_CACHE,0L,(bool) (info->lock_type != F_UNLCK),
92
103
MYF(share->write_flag & MY_WAIT_IF_FULL))))
143
154
error=end_io_cache(&info->rec_cache);
144
155
/* Sergei will insert full text index caching here */
146
#if !defined(TARGET_OS_SOLARIS)
157
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE)
147
158
if (info->opt_flag & MEMMAP_USED)
148
159
madvise((char*) share->file_map, share->state.state.data_file_length,
168
179
case HA_EXTRA_KEYREAD: /* Read only keys to record */
169
180
case HA_EXTRA_REMEMBER_POS:
170
181
info->opt_flag |= REMEMBER_OLD_POS;
171
memmove(info->lastkey+share->base.max_key_length*2,
172
info->lastkey,info->lastkey_length);
182
memcpy((uchar*) info->lastkey+share->base.max_key_length*2,
183
(uchar*) info->lastkey,info->lastkey_length);
173
184
info->save_update= info->update;
174
185
info->save_lastinx= info->lastinx;
175
186
info->save_lastpos= info->lastpos;
185
196
case HA_EXTRA_RESTORE_POS:
186
197
if (info->opt_flag & REMEMBER_OLD_POS)
188
memmove(info->lastkey,
189
info->lastkey+share->base.max_key_length*2,
190
info->save_lastkey_length);
199
memcpy((uchar*) info->lastkey,
200
(uchar*) info->lastkey+share->base.max_key_length*2,
201
info->save_lastkey_length);
191
202
info->update= info->save_update | HA_STATE_WRITTEN;
192
203
info->lastinx= info->save_lastinx;
193
204
info->lastpos= info->save_lastpos;
214
225
if (mi_is_any_key_active(share->state.key_map))
216
227
MI_KEYDEF *key=share->keyinfo;
218
229
for (i=0 ; i < share->base.keys ; i++,key++)
220
231
if (!(key->flag & HA_NOSAME) && info->s->base.auto_key != i+1)
253
264
(function == HA_EXTRA_FORCE_REOPEN ?
254
265
FLUSH_RELEASE : FLUSH_IGNORE_CHANGED)))
257
268
share->changed=1;
258
269
mi_print_error(info->s, HA_ERR_CRASHED);
259
270
mi_mark_crashed(info); /* Fatal error found */
268
279
info->was_locked=info->lock_type;
269
280
if (mi_lock_database(info,F_UNLCK))
271
282
info->lock_type = F_UNLCK;
273
284
if (share->kfile >= 0)
274
285
_mi_decrement_open_count(info);
275
286
if (share->kfile >= 0 && my_close(share->kfile,MYF(0)))
278
list<MI_INFO *>::iterator it= myisam_open_list.begin();
279
while (it != myisam_open_list.end())
290
for (list_element=myisam_open_list ;
292
list_element=list_element->next)
281
MI_INFO *tmpinfo= *it;
294
MI_INFO *tmpinfo=(MI_INFO*) list_element->data;
282
295
if (tmpinfo->s == info->s)
284
297
if (tmpinfo->dfile >= 0 && my_close(tmpinfo->dfile,MYF(0)))
286
299
tmpinfo->dfile= -1;
291
303
share->kfile= -1; /* Files aren't open anymore */
327
339
info->opt_flag|= OPT_NO_ROWS;
329
341
case HA_EXTRA_PRELOAD_BUFFER_SIZE:
330
info->preload_buff_size= *((uint32_t *) extra_arg);
342
info->preload_buff_size= *((ulong *) extra_arg);
332
344
case HA_EXTRA_CHANGE_KEY_TO_UNIQUE:
333
345
case HA_EXTRA_CHANGE_KEY_TO_DUP:
334
346
mi_extra_keyflag(info, function);
350
pthread_mutex_lock(&share->intern_lock);
352
Memory map the data file if it is not already mapped. It is safe
353
to memory map a file while other threads are using file I/O on it.
354
Assigning a new address to a function pointer is an atomic
355
operation. intern_lock prevents that two or more mappings are done
358
if (!share->file_map)
360
if (mi_dynmap_file(info, share->state.state.data_file_length))
362
error= my_errno= errno;
366
share->file_read= mi_mmap_pread;
367
share->file_write= mi_mmap_pwrite;
370
pthread_mutex_unlock(&share->intern_lock);
336
373
case HA_EXTRA_KEY_CACHE:
337
374
case HA_EXTRA_NO_KEY_CACHE:
381
myisam_log_command(MI_LOG_EXTRA,info,(uchar*) tmp,1,error);
387
void mi_set_index_cond_func(MI_INFO *info, index_cond_func_t func,
390
info->index_cond_func= func;
391
info->index_cond_func_arg= func_arg;
347
395
Start/Stop Inserting Duplicates Into a Table, WL#1648.
349
397
static void mi_extra_keyflag(MI_INFO *info, enum ha_extra_function function)
353
401
for (idx= 0; idx< info->s->base.keys; idx++)
385
433
if (share->base.blobs)
386
434
mi_alloc_rec_buff(info, -1, &info->rec_buff);
387
#if !defined(TARGET_OS_SOLARIS)
435
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE)
388
436
if (info->opt_flag & MEMMAP_USED)
389
437
madvise((char*) share->file_map, share->state.state.data_file_length,