~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_locking.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:
20
20
  isamdatabase.
21
21
*/
22
22
 
23
 
#include "myisam_priv.h"
24
 
#include "drizzled/charset_info.h"
25
 
#include <drizzled/util/test.h>
26
 
 
27
 
using namespace std;
 
23
#include "myisamdef.h"
 
24
#include <mystrings/m_ctype.h>
 
25
#include <mysys/my_tree.h>
 
26
#include <mysys/queues.h>
28
27
 
29
28
        /* lock table by F_UNLCK, F_RDLCK or F_WRLCK */
30
29
 
31
30
int mi_lock_database(MI_INFO *info, int lock_type)
32
31
{
33
32
  int error;
34
 
  uint32_t count;
 
33
  uint count;
35
34
  MYISAM_SHARE *share=info->s;
36
 
  uint32_t flag;
37
 
 
38
 
  pthread_mutex_lock(&share->intern_lock);
39
 
  if (!info->s->in_use)
40
 
    info->s->in_use= new list<Session *>;
41
 
 
 
35
  uint flag;
 
36
 
 
37
  if (share->options & HA_OPTION_READ_ONLY_DATA ||
 
38
      info->lock_type == lock_type)
 
39
    return(0);
42
40
  if (lock_type == F_EXTRA_LCK)                 /* Used by TMP tables */
43
41
  {
44
 
    pthread_mutex_unlock(&share->intern_lock);
45
42
    ++share->w_locks;
46
43
    ++share->tot_locks;
47
44
    info->lock_type= lock_type;
48
 
    info->s->in_use->push_front(info->in_use);
 
45
    info->s->in_use= list_add(info->s->in_use, &info->in_use);
49
46
    return(0);
50
47
  }
51
48
 
52
49
  flag=error=0;
 
50
  pthread_mutex_lock(&share->intern_lock);
53
51
  if (share->kfile >= 0)                /* May only be false on windows */
54
52
  {
55
53
    switch (lock_type) {
63
61
          !share->delay_key_write && flush_key_blocks(share->key_cache,
64
62
                                                      share->kfile,FLUSH_KEEP))
65
63
      {
66
 
        error=errno;
 
64
        error=my_errno;
67
65
        mi_print_error(info->s, HA_ERR_CRASHED);
68
66
        mi_mark_crashed(info);          /* Mark that table must be checked */
69
67
      }
71
69
      {
72
70
        if (end_io_cache(&info->rec_cache))
73
71
        {
74
 
          error=errno;
 
72
          error=my_errno;
75
73
          mi_print_error(info->s, HA_ERR_CRASHED);
76
74
          mi_mark_crashed(info);
77
75
        }
80
78
      {
81
79
        if (share->changed && !share->w_locks)
82
80
        {
 
81
#ifdef HAVE_MMAP
83
82
    if ((info->s->mmaped_length != info->s->state.state.data_file_length) &&
84
83
        (info->s->nonmmaped_inserts > MAX_NONMAPPED_INSERTS))
85
84
    {
86
85
      if (info->s->concurrent_insert)
87
 
        pthread_rwlock_wrlock(&info->s->mmap_lock);
 
86
        rw_wrlock(&info->s->mmap_lock);
88
87
      mi_remap_file(info, info->s->state.state.data_file_length);
89
88
      info->s->nonmmaped_inserts= 0;
90
89
      if (info->s->concurrent_insert)
91
 
        pthread_rwlock_unlock(&info->s->mmap_lock);
 
90
        rw_unlock(&info->s->mmap_lock);
92
91
    }
 
92
#endif
93
93
          share->state.process= share->last_process=share->this_process;
94
94
          share->state.unique=   info->last_unique=  info->this_unique;
95
95
          share->state.update_count= info->last_loop= ++info->this_loop;
96
96
          if (mi_state_info_write(share->kfile, &share->state, 1))
97
 
            error=errno;
 
97
            error=my_errno;
98
98
          share->changed=0;
99
 
          share->not_flushed=1;
 
99
          if (myisam_flush)
 
100
          {
 
101
            if (my_sync(share->kfile, MYF(0)))
 
102
              error= my_errno;
 
103
            if (my_sync(info->dfile, MYF(0)))
 
104
              error= my_errno;
 
105
          }
 
106
          else
 
107
            share->not_flushed=1;
100
108
          if (error)
101
109
          {
102
110
            mi_print_error(info->s, HA_ERR_CRASHED);
117
125
      }
118
126
      info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
119
127
      info->lock_type= F_UNLCK;
120
 
      info->s->in_use->remove(info->in_use);
 
128
      info->s->in_use= list_delete(info->s->in_use, &info->in_use);
121
129
      break;
122
130
    case F_RDLCK:
123
131
      if (info->lock_type == F_WRLCK)
142
150
        flag=1;
143
151
        if (mi_state_info_read_dsk(share->kfile, &share->state, 1))
144
152
        {
145
 
          error=errno;
 
153
          error=my_errno;
146
154
          break;
147
155
        }
148
156
        if (mi_state_info_read_dsk(share->kfile, &share->state, 1))
149
157
        {
150
 
          error=errno;
151
 
          errno=error;
 
158
          error=my_errno;
 
159
          my_errno=error;
152
160
          break;
153
161
        }
154
162
      }
155
 
      _mi_test_if_changed(info);
 
163
      VOID(_mi_test_if_changed(info));
156
164
      share->r_locks++;
157
165
      share->tot_locks++;
158
166
      info->lock_type=lock_type;
159
 
      info->s->in_use->push_front(info->in_use);
 
167
      info->s->in_use= list_add(info->s->in_use, &info->in_use);
160
168
      break;
161
169
    case F_WRLCK:
162
170
      if (info->lock_type == F_RDLCK)
179
187
          {
180
188
            if (mi_state_info_read_dsk(share->kfile, &share->state, 1))
181
189
            {
182
 
              error=errno;
183
 
              errno=error;
 
190
              error=my_errno;
 
191
              my_errno=error;
184
192
              break;
185
193
            }
186
194
          }
187
195
        }
188
196
      }
189
 
      _mi_test_if_changed(info);
190
 
 
 
197
      VOID(_mi_test_if_changed(info));
 
198
        
191
199
      info->lock_type=lock_type;
 
200
      info->invalidator=info->s->invalidator;
192
201
      share->w_locks++;
193
202
      share->tot_locks++;
194
 
      info->s->in_use->push_front(info->in_use);
 
203
      info->s->in_use= list_add(info->s->in_use, &info->in_use);
195
204
      break;
196
205
    default:
197
206
      break;                            /* Impossible */
203
212
    /*
204
213
       Check for bad file descriptors if this table is part
205
214
       of a merge union. Failing to capture this may cause
206
 
       a crash on windows if the table is renamed and
 
215
       a crash on windows if the table is renamed and 
207
216
       later on referenced by the merge table.
208
217
     */
209
218
    if( info->owned_by_merge && (info->s)->kfile < 0 )
215
224
  pthread_mutex_unlock(&share->intern_lock);
216
225
#if defined(FULL_LOG) || defined(_lint)
217
226
  lock_type|=(int) (flag << 8);         /* Set bit to set if real lock */
218
 
  myisam_log_command(MI_LOG_LOCK,info,(unsigned char*) &lock_type,sizeof(lock_type),
 
227
  myisam_log_command(MI_LOG_LOCK,info,(uchar*) &lock_type,sizeof(lock_type),
219
228
                     error);
220
229
#endif
221
230
  return(error);
298
307
 
299
308
  IMPLEMENTATION
300
309
    Allow concurrent inserts if we don't have a hole in the table or
301
 
    if there is no active write lock and there is active read locks and
 
310
    if there is no active write lock and there is active read locks and 
302
311
    myisam_concurrent_insert == 2. In this last case the new
303
312
    row('s) are inserted at end of file instead of filling up the hole.
304
313
 
322
331
    external lock (in other words: w_locks == 1 means no other threads has
323
332
    a write lock)
324
333
  */
325
 
  return (bool) !(info->s->state.dellink == HA_OFFSET_ERROR ||
 
334
  return (my_bool) !(info->s->state.dellink == HA_OFFSET_ERROR ||
326
335
                     (myisam_concurrent_insert == 2 && info->s->r_locks &&
327
336
                      info->s->w_locks == 1));
328
337
}
341
350
    {
342
351
      if (mi_state_info_read_dsk(share->kfile, &share->state, 1))
343
352
      {
344
 
        int error=errno ? errno : -1;
345
 
        errno=error;
 
353
        int error=my_errno ? my_errno : -1;
 
354
        my_errno=error;
346
355
        return(1);
347
356
      }
348
357
    }
349
358
    if (check_keybuffer)
350
 
      _mi_test_if_changed(info);
 
359
      VOID(_mi_test_if_changed(info));
 
360
    info->invalidator=info->s->invalidator;
351
361
  }
352
362
  else if (lock_type == F_WRLCK && info->lock_type == F_RDLCK)
353
363
  {
354
 
    errno=EACCES;                               /* Not allowed to change */
 
364
    my_errno=EACCES;                            /* Not allowed to change */
355
365
    return(-1);                         /* when have read_lock() */
356
366
  }
357
367
  return(0);
363
373
  request
364
374
*/
365
375
 
366
 
int _mi_writeinfo(register MI_INFO *info, uint32_t operation)
 
376
int _mi_writeinfo(register MI_INFO *info, uint operation)
367
377
{
368
378
  int error,olderror;
369
379
  MYISAM_SHARE *share=info->s;
371
381
  error=0;
372
382
  if (share->tot_locks == 0)
373
383
  {
374
 
    olderror=errno;                     /* Remember last error */
 
384
    olderror=my_errno;                  /* Remember last error */
375
385
    if (operation)
376
386
    {                                   /* Two threads can't be here */
377
387
      share->state.process= share->last_process=   share->this_process;
378
388
      share->state.unique=  info->last_unique=     info->this_unique;
379
389
      share->state.update_count= info->last_loop= ++info->this_loop;
380
390
      if ((error=mi_state_info_write(share->kfile, &share->state, 1)))
381
 
        olderror=errno;
 
391
        olderror=my_errno;
 
392
#ifdef __WIN__
 
393
      if (myisam_flush)
 
394
      {
 
395
        _commit(share->kfile);
 
396
        _commit(info->dfile);
 
397
      }
 
398
#endif
382
399
    }
383
 
    errno=olderror;
 
400
    my_errno=olderror;
384
401
  }
385
402
  else if (operation)
386
403
    share->changed= 1;                  /* Mark keyfile changed */
399
416
      share->state.update_count != info->last_loop)
400
417
  {                                             /* Keyfile has changed */
401
418
    if (share->state.process != share->this_process)
402
 
      flush_key_blocks(share->key_cache, share->kfile, FLUSH_RELEASE);
 
419
      VOID(flush_key_blocks(share->key_cache, share->kfile, FLUSH_RELEASE));
403
420
    share->last_process=share->state.process;
404
421
    info->last_unique=  share->state.unique;
405
422
    info->last_loop=    share->state.update_count;
432
449
 
433
450
int _mi_mark_file_changed(MI_INFO *info)
434
451
{
435
 
  unsigned char buff[3];
 
452
  uchar buff[3];
436
453
  register MYISAM_SHARE *share=info->s;
437
454
 
438
455
  if (!(share->state.changed & STATE_CHANGED) || ! share->global_changed)
464
481
 
465
482
int _mi_decrement_open_count(MI_INFO *info)
466
483
{
467
 
  unsigned char buff[2];
 
484
  uchar buff[2];
468
485
  register MYISAM_SHARE *share=info->s;
469
486
  int lock_error=0,write_error=0;
470
487
  if (share->global_changed)
471
488
  {
472
 
    uint32_t old_lock=info->lock_type;
 
489
    uint old_lock=info->lock_type;
473
490
    share->global_changed=0;
474
491
    lock_error=mi_lock_database(info,F_WRLCK);
475
492
    /* Its not fatal even if we couldn't get the lock ! */