~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_panic.c

Merged in changes. 
Edited a the comment test case so deal with our version bump.

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