1 /* Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23 #include "fulltext.h"
24
25 /* if flag == HA_PANIC_CLOSE then all misam files are closed */
26 /* if flag == HA_PANIC_WRITE then all misam files are unlocked and
27 all changed data in single user misam is written to file */
28 /* if flag == HA_PANIC_READ then all misam files that was locked when
29 mi_panic(HA_PANIC_WRITE) was done is locked. A mi_readinfo() is
30 done for all single user files to get changes in database */
31
32
mi_panic(enum ha_panic_function flag)33 int mi_panic(enum ha_panic_function flag)
34 {
35 int error=0;
36 LIST *list_element,*next_open;
37 MI_INFO *info;
38 DBUG_ENTER("mi_panic");
39
40 mysql_mutex_lock(&THR_LOCK_myisam);
41 for (list_element=myisam_open_list ; list_element ; list_element=next_open)
42 {
43 next_open=list_element->next; /* Save if close */
44 info=(MI_INFO*) list_element->data;
45 switch (flag) {
46 case HA_PANIC_CLOSE:
47 mysql_mutex_unlock(&THR_LOCK_myisam); /* Not exactly right... */
48 if (mi_close(info))
49 error=my_errno();
50 mysql_mutex_lock(&THR_LOCK_myisam);
51 break;
52 case HA_PANIC_WRITE: /* Do this to free databases */
53 if (flush_key_blocks(info->s->key_cache, keycache_thread_var(),
54 info->s->kfile, FLUSH_RELEASE))
55 error=my_errno();
56 if (info->opt_flag & WRITE_CACHE_USED)
57 if (flush_io_cache(&info->rec_cache))
58 error=my_errno();
59 if (info->opt_flag & READ_CACHE_USED)
60 {
61 if (flush_io_cache(&info->rec_cache))
62 error=my_errno();
63 if (reinit_io_cache(&info->rec_cache, READ_CACHE, 0,
64 (info->lock_type != F_UNLCK), 1))
65 error= my_errno();
66 }
67 if (info->lock_type != F_UNLCK && ! info->was_locked)
68 {
69 info->was_locked=info->lock_type;
70 if (mi_lock_database(info,F_UNLCK))
71 error=my_errno();
72 }
73 break;
74 case HA_PANIC_READ: /* Restore to before WRITE */
75 if (info->was_locked)
76 {
77 if (mi_lock_database(info, info->was_locked))
78 error=my_errno();
79 info->was_locked=0;
80 }
81 break;
82 }
83 }
84 if (flag == HA_PANIC_CLOSE)
85 {
86 (void) mi_log(0); /* Close log if neaded */
87 ft_free_stopwords();
88 }
89 mysql_mutex_unlock(&THR_LOCK_myisam);
90 if (!error)
91 DBUG_RETURN(0);
92 set_my_errno(error);
93 DBUG_RETURN(error);
94 } /* mi_panic */
95