1
by brian
clean slate |
1 |
/* Copyright (C) 2000-2004 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
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
16 |
/* close a isam-database */
|
|
17 |
/*
|
|
18 |
TODO:
|
|
19 |
We need to have a separate mutex on the closed file to allow other threads
|
|
20 |
to open other files during the time we flush the cache and close this file
|
|
21 |
*/
|
|
22 |
||
1130.3.28
by Monty Taylor
Moved heapdef.h and myisamdef.h to *_priv.h for easier filtering for include guard check. |
23 |
#include "myisam_priv.h" |
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
24 |
#include <cstdlib> |
1
by brian
clean slate |
25 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
26 |
using namespace drizzled; |
27 |
||
916.1.32
by Padraig O'Sullivan
Refactoring MyISAM storage engine again based on LIST replacement with |
28 |
int mi_close(MI_INFO *info) |
1
by brian
clean slate |
29 |
{
|
30 |
int error=0,flag; |
|
31 |
MYISAM_SHARE *share=info->s; |
|
32 |
||
1703.1.3
by Brian Aker
Replace pthread mutex with boost based one for myisam. |
33 |
THR_LOCK_myisam.lock(); |
1
by brian
clean slate |
34 |
if (info->lock_type == F_EXTRA_LCK) |
35 |
info->lock_type=F_UNLCK; /* HA_EXTRA_NO_USER_CHANGE */ |
|
36 |
||
37 |
if (share->reopen == 1 && share->kfile >= 0) |
|
38 |
_mi_decrement_open_count(info); |
|
39 |
||
40 |
if (info->lock_type != F_UNLCK) |
|
41 |
{
|
|
42 |
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. |
43 |
error=errno; |
1
by brian
clean slate |
44 |
}
|
45 |
||
46 |
if (share->options & HA_OPTION_READ_ONLY_DATA) |
|
47 |
{
|
|
48 |
share->r_locks--; |
|
49 |
share->tot_locks--; |
|
50 |
}
|
|
51 |
if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED)) |
|
52 |
{
|
|
53 |
if (end_io_cache(&info->rec_cache)) |
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
54 |
error=errno; |
1
by brian
clean slate |
55 |
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED); |
56 |
}
|
|
57 |
flag= !--share->reopen; |
|
916.1.32
by Padraig O'Sullivan
Refactoring MyISAM storage engine again based on LIST replacement with |
58 |
myisam_open_list.remove(info); |
1
by brian
clean slate |
59 |
|
477
by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that. |
60 |
void * rec_buff_ptr= mi_get_rec_buff_ptr(info, info->rec_buff); |
61 |
if (rec_buff_ptr != NULL) |
|
62 |
free(rec_buff_ptr); |
|
1
by brian
clean slate |
63 |
if (flag) |
64 |
{
|
|
65 |
if (share->kfile >= 0 && |
|
1689.2.15
by Brian Aker
Encapsulate the key cache object in myisam. |
66 |
flush_key_blocks(share->getKeyCache(), share->kfile, |
1
by brian
clean slate |
67 |
share->temporary ? FLUSH_IGNORE_CHANGED : |
68 |
FLUSH_RELEASE)) |
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
69 |
error=errno; |
1689.2.16
by Brian Aker
This places keycache directly into the table (ie it is now mapped 1=1). |
70 |
end_key_cache(share->getKeyCache(), true); |
1
by brian
clean slate |
71 |
if (share->kfile >= 0) |
72 |
{
|
|
73 |
/*
|
|
74 |
If we are crashed, we can safely flush the current state as it will
|
|
75 |
not change the crashed state.
|
|
76 |
We can NOT write the state in other cases as other threads
|
|
77 |
may be using the file at this point
|
|
78 |
*/
|
|
79 |
if (share->mode != O_RDONLY && mi_is_crashed(info)) |
|
80 |
mi_state_info_write(share->kfile, &share->state, 1); |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
81 |
if (internal::my_close(share->kfile,MYF(0))) |
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
82 |
error = errno; |
1
by brian
clean slate |
83 |
}
|
84 |
if (share->decode_trees) |
|
85 |
{
|
|
481
by Brian Aker
Remove all of uchar. |
86 |
free((unsigned char*) share->decode_trees); |
87 |
free((unsigned char*) share->decode_tables); |
|
1
by brian
clean slate |
88 |
}
|
916.1.36
by Padraig O'Sullivan
Make sure to free the memory allocated for the list of threads using a |
89 |
delete info->s->in_use; |
481
by Brian Aker
Remove all of uchar. |
90 |
free((unsigned char*) info->s); |
1
by brian
clean slate |
91 |
}
|
1703.1.3
by Brian Aker
Replace pthread mutex with boost based one for myisam. |
92 |
THR_LOCK_myisam.unlock(); |
79
by Brian Aker
USE_RAID cleanup, along with ftbench tools. |
93 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
94 |
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. |
95 |
error = errno; |
1
by brian
clean slate |
96 |
|
481
by Brian Aker
Remove all of uchar. |
97 |
free((unsigned char*) info); |
1
by brian
clean slate |
98 |
|
99 |
if (error) |
|
100 |
{
|
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
101 |
return(errno=error); |
1
by brian
clean slate |
102 |
}
|
51.1.86
by Jay Pipes
Removed/replaced DBUG symbols |
103 |
return(0); |
1
by brian
clean slate |
104 |
} /* mi_close */ |