~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_extra.c

  • Committer: Monty Taylor
  • Date: 2008-08-01 22:33:44 UTC
  • mto: (236.1.42 codestyle)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080801223344-vzhlflfmtijp1imv
First pass at gettexizing the error messages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 */
15
15
 
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>
20
 
 
21
 
#include <string.h>
22
 
#include <algorithm>
23
 
 
24
 
using namespace std;
 
19
#endif
25
20
 
26
21
static void mi_extra_keyflag(MI_INFO *info, enum ha_extra_function function);
27
22
 
33
28
    mi_extra()
34
29
    info        open table
35
30
    function    operation
36
 
    extra_arg   Pointer to extra argument (normally pointer to uint32_t)
 
31
    extra_arg   Pointer to extra argument (normally pointer to ulong)
37
32
                Used when function is one of:
38
33
                HA_EXTRA_WRITE_CACHE
39
34
                HA_EXTRA_CACHE
45
40
int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
46
41
{
47
42
  int error=0;
48
 
  uint32_t cache_size;
 
43
  ulong cache_size;
49
44
  MYISAM_SHARE *share=info->s;
50
45
 
51
46
  switch (function) {
69
64
        (share->options & HA_OPTION_PACK_RECORD))
70
65
    {
71
66
      error=1;                  /* Not possibly if not locked */
72
 
      errno=EACCES;
 
67
      my_errno=EACCES;
73
68
      break;
74
69
    }
75
70
    if (info->s->file_map) /* Don't use cache if mmap */
76
71
      break;
 
72
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE)
 
73
    if ((share->options & HA_OPTION_COMPRESS_RECORD))
 
74
    {
 
75
      pthread_mutex_lock(&share->intern_lock);
 
76
      if (_mi_memmap_file(info))
 
77
      {
 
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);
 
83
        break;
 
84
      }
 
85
      pthread_mutex_unlock(&share->intern_lock);
 
86
    }
 
87
#endif
77
88
    if (info->opt_flag & WRITE_CACHE_USED)
78
89
    {
79
90
      info->opt_flag&= ~WRITE_CACHE_USED;
83
94
    if (!(info->opt_flag &
84
95
          (READ_CACHE_USED | WRITE_CACHE_USED | MEMMAP_USED)))
85
96
    {
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,
90
101
                                    cache_size),
91
102
                          READ_CACHE,0L,(bool) (info->lock_type != F_UNLCK),
92
103
                          MYF(share->write_flag & MY_WAIT_IF_FULL))))
116
127
      break;
117
128
    }
118
129
 
119
 
    cache_size= (extra_arg ? *(uint32_t*) extra_arg :
 
130
    cache_size= (extra_arg ? *(ulong*) extra_arg :
120
131
                 my_default_record_cache_size);
121
132
    if (!(info->opt_flag &
122
133
          (READ_CACHE_USED | WRITE_CACHE_USED | OPT_NO_ROWS)) &&
143
154
      error=end_io_cache(&info->rec_cache);
144
155
      /* Sergei will insert full text index caching here */
145
156
    }
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,
149
160
              MADV_RANDOM);
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)
187
198
    {
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))
215
226
    {
216
227
      MI_KEYDEF *key=share->keyinfo;
217
 
      uint32_t i;
 
228
      uint i;
218
229
      for (i=0 ; i < share->base.keys ; i++,key++)
219
230
      {
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)))
255
266
    {
256
 
      error=errno;
 
267
      error=my_errno;
257
268
      share->changed=1;
258
269
      mi_print_error(info->s, HA_ERR_CRASHED);
259
270
      mi_mark_crashed(info);                    /* Fatal error found */
267
278
    {
268
279
      info->was_locked=info->lock_type;
269
280
      if (mi_lock_database(info,F_UNLCK))
270
 
        error=errno;
 
281
        error=my_errno;
271
282
      info->lock_type = F_UNLCK;
272
283
    }
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)))
276
 
      error=errno;
 
287
      error=my_errno;
277
288
    {
278
 
      list<MI_INFO *>::iterator it= myisam_open_list.begin();
279
 
      while (it != myisam_open_list.end())
 
289
      LIST *list_element ;
 
290
      for (list_element=myisam_open_list ;
 
291
           list_element ;
 
292
           list_element=list_element->next)
280
293
      {
281
 
        MI_INFO *tmpinfo= *it;
 
294
        MI_INFO *tmpinfo=(MI_INFO*) list_element->data;
282
295
        if (tmpinfo->s == info->s)
283
296
        {
284
297
          if (tmpinfo->dfile >= 0 && my_close(tmpinfo->dfile,MYF(0)))
285
 
            error = errno;
 
298
            error = my_errno;
286
299
          tmpinfo->dfile= -1;
287
300
        }
288
 
        ++it;
289
301
      }
290
302
    }
291
303
    share->kfile= -1;                           /* Files aren't open anymore */
303
315
    {
304
316
      share->not_flushed=0;
305
317
      if (my_sync(share->kfile, MYF(0)))
306
 
        error= errno;
 
318
        error= my_errno;
307
319
      if (my_sync(info->dfile, MYF(0)))
308
 
        error= errno;
 
320
        error= my_errno;
309
321
      if (error)
310
322
      {
311
323
        share->changed=1;
327
339
      info->opt_flag|= OPT_NO_ROWS;
328
340
    break;
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); 
331
343
    break;
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);
335
347
    break;
 
348
  case HA_EXTRA_MMAP:
 
349
#ifdef HAVE_MMAP
 
350
    pthread_mutex_lock(&share->intern_lock);
 
351
    /*
 
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
 
356
      at the same time.
 
357
    */
 
358
    if (!share->file_map)
 
359
    {
 
360
      if (mi_dynmap_file(info, share->state.state.data_file_length))
 
361
      {
 
362
        error= my_errno= errno;
 
363
      }
 
364
      else
 
365
      {
 
366
        share->file_read= mi_mmap_pread;
 
367
        share->file_write= mi_mmap_pwrite;
 
368
      }
 
369
    }
 
370
    pthread_mutex_unlock(&share->intern_lock);
 
371
#endif
 
372
    break;
336
373
  case HA_EXTRA_KEY_CACHE:
337
374
  case HA_EXTRA_NO_KEY_CACHE:
338
375
  default:
339
376
    break;
340
377
  }
341
 
 
 
378
  {
 
379
    char tmp[1];
 
380
    tmp[0]=function;
 
381
    myisam_log_command(MI_LOG_EXTRA,info,(uchar*) tmp,1,error);
 
382
  }
342
383
  return(error);
343
384
} /* mi_extra */
344
385
 
345
386
 
 
387
void mi_set_index_cond_func(MI_INFO *info, index_cond_func_t func,
 
388
                            void *func_arg)
 
389
{
 
390
  info->index_cond_func= func;
 
391
  info->index_cond_func_arg= func_arg;
 
392
}
 
393
 
346
394
/*
347
395
    Start/Stop Inserting Duplicates Into a Table, WL#1648.
348
396
 */
349
397
static void mi_extra_keyflag(MI_INFO *info, enum ha_extra_function function)
350
398
{
351
 
  uint32_t  idx;
 
399
  uint  idx;
352
400
 
353
401
  for (idx= 0; idx< info->s->base.keys; idx++)
354
402
  {
384
432
  }
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,
390
438
            MADV_RANDOM);