~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/mi_panic.cc

  • Committer: Brian Aker
  • Date: 2010-05-27 01:25:56 UTC
  • mfrom: (1567.1.4 new-staging)
  • Revision ID: brian@gaz-20100527012556-5zgkirkl7swbigd6
Merge of Brian, Paul. PBXT compile issue, and test framework cleanup. 

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 "myisamdef.h"
 
16
#include "myisam_priv.h"
 
17
 
 
18
using namespace std;
 
19
using namespace drizzled;
17
20
 
18
21
        /* if flag == HA_PANIC_CLOSE then all misam files are closed */
19
22
        /* if flag == HA_PANIC_WRITE then all misam files are unlocked and
26
29
int mi_panic(enum ha_panic_function flag)
27
30
{
28
31
  int error=0;
29
 
  LIST *list_element,*next_open;
30
32
  MI_INFO *info;
31
33
 
32
34
  pthread_mutex_lock(&THR_LOCK_myisam);
33
 
  for (list_element=myisam_open_list ; list_element ; list_element=next_open)
 
35
  list<MI_INFO *>::iterator it= myisam_open_list.begin();
 
36
  while (it != myisam_open_list.end())
34
37
  {
35
 
    next_open=list_element->next;               /* Save if close */
36
 
    info=(MI_INFO*) list_element->data;
 
38
    info= *it;
37
39
    switch (flag) {
38
40
    case HA_PANIC_CLOSE:
39
41
      pthread_mutex_unlock(&THR_LOCK_myisam);   /* Not exactly right... */
40
42
      if (mi_close(info))
41
 
        error=my_errno;
 
43
        error=errno;
42
44
      pthread_mutex_lock(&THR_LOCK_myisam);
43
45
      break;
44
46
    case HA_PANIC_WRITE:                /* Do this to free databases */
47
49
        break;
48
50
#endif
49
51
      if (flush_key_blocks(info->s->key_cache, info->s->kfile, FLUSH_RELEASE))
50
 
        error=my_errno;
 
52
        error=errno;
51
53
      if (info->opt_flag & WRITE_CACHE_USED)
52
54
        if (flush_io_cache(&info->rec_cache))
53
 
          error=my_errno;
 
55
          error=errno;
54
56
      if (info->opt_flag & READ_CACHE_USED)
55
57
      {
56
58
        if (flush_io_cache(&info->rec_cache))
57
 
          error=my_errno;
58
 
        reinit_io_cache(&info->rec_cache,READ_CACHE,0,
 
59
          error=errno;
 
60
        reinit_io_cache(&info->rec_cache,internal::READ_CACHE,0,
59
61
                       (bool) (info->lock_type != F_UNLCK),1);
60
62
      }
61
63
      if (info->lock_type != F_UNLCK && ! info->was_locked)
62
64
      {
63
65
        info->was_locked=info->lock_type;
64
66
        if (mi_lock_database(info,F_UNLCK))
65
 
          error=my_errno;
 
67
          error=errno;
66
68
      }
67
69
#ifdef CANT_OPEN_FILES_TWICE
68
 
      if (info->s->kfile >= 0 && my_close(info->s->kfile,MYF(0)))
69
 
        error = my_errno;
70
 
      if (info->dfile >= 0 && my_close(info->dfile,MYF(0)))
71
 
        error = my_errno;
 
70
      if (info->s->kfile >= 0 && internal::my_close(info->s->kfile,MYF(0)))
 
71
        error = errno;
 
72
      if (info->dfile >= 0 && internal::my_close(info->dfile,MYF(0)))
 
73
        error = errno;
72
74
      info->s->kfile=info->dfile= -1;   /* Files aren't open anymore */
73
75
      break;
74
76
#endif
77
79
      {                                 /* Open closed files */
78
80
        char name_buff[FN_REFLEN];
79
81
        if (info->s->kfile < 0)
80
 
          if ((info->s->kfile= my_open(fn_format(name_buff,info->filename,"",
 
82
          if ((info->s->kfile= internal::my_open(internal::fn_format(name_buff,info->filename,"",
81
83
                                              N_NAME_IEXT,4),info->mode,
82
84
                                    MYF(MY_WME))) < 0)
83
 
            error = my_errno;
 
85
            error = errno;
84
86
        if (info->dfile < 0)
85
87
        {
86
 
          if ((info->dfile= my_open(fn_format(name_buff,info->filename,"",
 
88
          if ((info->dfile= internal::my_open(internal::fn_format(name_buff,info->filename,"",
87
89
                                              N_NAME_DEXT,4),info->mode,
88
90
                                    MYF(MY_WME))) < 0)
89
 
            error = my_errno;
 
91
            error = errno;
90
92
          info->rec_cache.file=info->dfile;
91
93
        }
92
94
      }
94
96
      if (info->was_locked)
95
97
      {
96
98
        if (mi_lock_database(info, info->was_locked))
97
 
          error=my_errno;
 
99
          error=errno;
98
100
        info->was_locked=0;
99
101
      }
100
102
      break;
101
103
    }
 
104
    ++it;
102
105
  }
103
106
  pthread_mutex_unlock(&THR_LOCK_myisam);
104
107
  if (!error)
105
108
    return(0);
106
 
  return(my_errno=error);
 
109
  return(errno=error);
107
110
} /* mi_panic */