~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_panic.c

  • Committer: Monty Taylor
  • Date: 2008-11-16 05:36:13 UTC
  • mto: (584.1.9 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081116053613-bld4rqxhlkb49c02
Split out cache_row and type_holder.

Show diffs side-by-side

added added

removed removed

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