1/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
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
14 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15
16/* close a isam-database */
17
18#include "myrg_def.h"
19
20int myrg_close(MYRG_INFO *info)
21{
22 int error=0,new_error;
23 MYRG_TABLE *file;
24 DBUG_ENTER("myrg_close");
25
26 /*
27 Assume that info->children_attached means that this is called from
28 direct use of MERGE, not from a MySQL server. In this case the
29 children must be closed and info->rec_per_key_part is part of the
30 'info' multi_alloc.
31 If info->children_attached is false, this is called from a MySQL
32 server. Children are closed independently but info->rec_per_key_part
33 must be freed.
34 Just in case of a server panic (myrg_panic()) info->children_attached
35 might be true. We would close the children though they should be
36 closed independently and info->rec_per_key_part is not freed.
37 This should be acceptable for a panic.
38 In case of a MySQL server and no children, children_attached is
39 always true. In this case no rec_per_key_part has been allocated.
40 So it is correct to use the branch where an empty list of tables is
41 (not) closed.
42 */
43 if (info->children_attached)
44 {
45 for (file= info->open_tables; file != info->end_table; file++)
46 {
47 /* purecov: begin inspected */
48 if ((new_error= mi_close(file->table)))
49 error= new_error;
50 else
51 file->table= NULL;
52 /* purecov: end */
53 }
54 }
55 else
56 my_free(info->rec_per_key_part);
57 delete_queue(&info->by_key);
58 mysql_mutex_lock(&THR_LOCK_open);
59 myrg_open_list=list_delete(myrg_open_list,&info->open_list);
60 mysql_mutex_unlock(&THR_LOCK_open);
61 mysql_mutex_destroy(&info->mutex);
62 my_free(info);
63 if (error)
64 {
65 DBUG_RETURN(my_errno=error);
66 }
67 DBUG_RETURN(0);
68}
69