~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2001, 2003 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
1130.3.28 by Monty Taylor
Moved heapdef.h and myisamdef.h to *_priv.h for easier filtering for include guard check.
16
#include "myisam_priv.h"
1 by brian
clean slate
17
916.1.32 by Padraig O'Sullivan
Refactoring MyISAM storage engine again based on LIST replacement with
18
using namespace std;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
19
using namespace drizzled;
916.1.32 by Padraig O'Sullivan
Refactoring MyISAM storage engine again based on LIST replacement with
20
1 by brian
clean slate
21
	/* if flag == HA_PANIC_CLOSE then all misam files are closed */
22
	/* if flag == HA_PANIC_WRITE then all misam files are unlocked and
23
	   all changed data in single user misam is written to file */
24
	/* if flag == HA_PANIC_READ then all misam files that was locked when
25
	   mi_panic(HA_PANIC_WRITE) was done is locked. A mi_readinfo() is
26
	   done for all single user files to get changes in database */
27
28
29
int mi_panic(enum ha_panic_function flag)
30
{
31
  int error=0;
32
  MI_INFO *info;
33
1703.1.3 by Brian Aker
Replace pthread mutex with boost based one for myisam.
34
  THR_LOCK_myisam.lock();
916.1.32 by Padraig O'Sullivan
Refactoring MyISAM storage engine again based on LIST replacement with
35
  list<MI_INFO *>::iterator it= myisam_open_list.begin();
36
  while (it != myisam_open_list.end())
1 by brian
clean slate
37
  {
916.1.32 by Padraig O'Sullivan
Refactoring MyISAM storage engine again based on LIST replacement with
38
    info= *it;
1 by brian
clean slate
39
    switch (flag) {
40
    case HA_PANIC_CLOSE:
1703.1.3 by Brian Aker
Replace pthread mutex with boost based one for myisam.
41
      THR_LOCK_myisam.unlock();	/* Not exactly right... */
1 by brian
clean slate
42
      if (mi_close(info))
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
43
	error=errno;
1703.1.3 by Brian Aker
Replace pthread mutex with boost based one for myisam.
44
      THR_LOCK_myisam.lock();
1 by brian
clean slate
45
      break;
46
    case HA_PANIC_WRITE:		/* Do this to free databases */
47
#ifdef CANT_OPEN_FILES_TWICE
48
      if (info->s->options & HA_OPTION_READ_ONLY_DATA)
49
	break;
50
#endif
1689.2.15 by Brian Aker
Encapsulate the key cache object in myisam.
51
      if (flush_key_blocks(info->s->getKeyCache(), info->s->kfile, FLUSH_RELEASE))
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
52
	error=errno;
1 by brian
clean slate
53
      if (info->opt_flag & WRITE_CACHE_USED)
54
	if (flush_io_cache(&info->rec_cache))
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
55
	  error=errno;
1 by brian
clean slate
56
      if (info->opt_flag & READ_CACHE_USED)
57
      {
58
	if (flush_io_cache(&info->rec_cache))
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
59
	  error=errno;
1909.1.1 by Brian Aker
Encapsulation of IO_CACHE.
60
        info->rec_cache.reinit_io_cache(internal::READ_CACHE,0, (bool) (info->lock_type != F_UNLCK),1);
1 by brian
clean slate
61
      }
62
      if (info->lock_type != F_UNLCK && ! info->was_locked)
63
      {
64
	info->was_locked=info->lock_type;
65
	if (mi_lock_database(info,F_UNLCK))
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
66
	  error=errno;
1 by brian
clean slate
67
      }
68
#ifdef CANT_OPEN_FILES_TWICE
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
69
      if (info->s->kfile >= 0 && internal::my_close(info->s->kfile,MYF(0)))
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
70
	error = errno;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
71
      if (info->dfile >= 0 && internal::my_close(info->dfile,MYF(0)))
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
72
	error = errno;
1 by brian
clean slate
73
      info->s->kfile=info->dfile= -1;	/* Files aren't open anymore */
74
      break;
75
#endif
76
    case HA_PANIC_READ:			/* Restore to before WRITE */
77
#ifdef CANT_OPEN_FILES_TWICE
78
      {					/* Open closed files */
79
	char name_buff[FN_REFLEN];
80
	if (info->s->kfile < 0)
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
81
	  if ((info->s->kfile= internal::my_open(internal::fn_format(name_buff,info->filename,"",
1 by brian
clean slate
82
					      N_NAME_IEXT,4),info->mode,
83
				    MYF(MY_WME))) < 0)
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
84
	    error = errno;
1 by brian
clean slate
85
	if (info->dfile < 0)
86
	{
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
87
	  if ((info->dfile= internal::my_open(internal::fn_format(name_buff,info->filename,"",
1 by brian
clean slate
88
					      N_NAME_DEXT,4),info->mode,
89
				    MYF(MY_WME))) < 0)
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
90
	    error = errno;
1 by brian
clean slate
91
	  info->rec_cache.file=info->dfile;
92
	}
93
      }
94
#endif
95
      if (info->was_locked)
96
      {
97
	if (mi_lock_database(info, info->was_locked))
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
98
	  error=errno;
1 by brian
clean slate
99
	info->was_locked=0;
100
      }
101
      break;
102
    }
916.1.32 by Padraig O'Sullivan
Refactoring MyISAM storage engine again based on LIST replacement with
103
    ++it;
1 by brian
clean slate
104
  }
1703.1.3 by Brian Aker
Replace pthread mutex with boost based one for myisam.
105
  THR_LOCK_myisam.unlock();
1 by brian
clean slate
106
  if (!error)
51.1.106 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
107
    return(0);
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
108
  return(errno=error);
1 by brian
clean slate
109
} /* mi_panic */