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 |
||
23 |
#include "myisamdef.h" |
|
24 |
||
25 |
int mi_close(register MI_INFO *info) |
|
26 |
{
|
|
27 |
int error=0,flag; |
|
28 |
MYISAM_SHARE *share=info->s; |
|
29 |
||
30 |
pthread_mutex_lock(&THR_LOCK_myisam); |
|
31 |
if (info->lock_type == F_EXTRA_LCK) |
|
32 |
info->lock_type=F_UNLCK; /* HA_EXTRA_NO_USER_CHANGE */ |
|
33 |
||
34 |
if (share->reopen == 1 && share->kfile >= 0) |
|
35 |
_mi_decrement_open_count(info); |
|
36 |
||
37 |
if (info->lock_type != F_UNLCK) |
|
38 |
{
|
|
39 |
if (mi_lock_database(info,F_UNLCK)) |
|
40 |
error=my_errno; |
|
41 |
}
|
|
42 |
pthread_mutex_lock(&share->intern_lock); |
|
43 |
||
44 |
if (share->options & HA_OPTION_READ_ONLY_DATA) |
|
45 |
{
|
|
46 |
share->r_locks--; |
|
47 |
share->tot_locks--; |
|
48 |
}
|
|
49 |
if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED)) |
|
50 |
{
|
|
51 |
if (end_io_cache(&info->rec_cache)) |
|
52 |
error=my_errno; |
|
53 |
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED); |
|
54 |
}
|
|
55 |
flag= !--share->reopen; |
|
56 |
myisam_open_list=list_delete(myisam_open_list,&info->open_list); |
|
57 |
pthread_mutex_unlock(&share->intern_lock); |
|
58 |
||
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. |
59 |
void * rec_buff_ptr= mi_get_rec_buff_ptr(info, info->rec_buff); |
60 |
if (rec_buff_ptr != NULL) |
|
61 |
free(rec_buff_ptr); |
|
1
by brian
clean slate |
62 |
if (flag) |
63 |
{
|
|
64 |
if (share->kfile >= 0 && |
|
65 |
flush_key_blocks(share->key_cache, share->kfile, |
|
66 |
share->temporary ? FLUSH_IGNORE_CHANGED : |
|
67 |
FLUSH_RELEASE)) |
|
68 |
error=my_errno; |
|
69 |
if (share->kfile >= 0) |
|
70 |
{
|
|
71 |
/*
|
|
72 |
If we are crashed, we can safely flush the current state as it will
|
|
73 |
not change the crashed state.
|
|
74 |
We can NOT write the state in other cases as other threads
|
|
75 |
may be using the file at this point
|
|
76 |
*/
|
|
77 |
if (share->mode != O_RDONLY && mi_is_crashed(info)) |
|
78 |
mi_state_info_write(share->kfile, &share->state, 1); |
|
79 |
if (my_close(share->kfile,MYF(0))) |
|
80 |
error = my_errno; |
|
81 |
}
|
|
82 |
if (share->decode_trees) |
|
83 |
{
|
|
481
by Brian Aker
Remove all of uchar. |
84 |
free((unsigned char*) share->decode_trees); |
85 |
free((unsigned char*) share->decode_tables); |
|
1
by brian
clean slate |
86 |
}
|
87 |
thr_lock_delete(&share->lock); |
|
398.1.10
by Monty Taylor
Actually removed VOID() this time. |
88 |
pthread_mutex_destroy(&share->intern_lock); |
1
by brian
clean slate |
89 |
{
|
90 |
int i,keys; |
|
91 |
keys = share->state.header.keys; |
|
658
by Brian Aker
Part removal of my_pthread.h |
92 |
pthread_rwlock_destroy(&share->mmap_lock); |
1
by brian
clean slate |
93 |
for(i=0; i<keys; i++) { |
658
by Brian Aker
Part removal of my_pthread.h |
94 |
pthread_rwlock_destroy(&share->key_root_lock[i]); |
1
by brian
clean slate |
95 |
}
|
96 |
}
|
|
481
by Brian Aker
Remove all of uchar. |
97 |
free((unsigned char*) info->s); |
1
by brian
clean slate |
98 |
}
|
99 |
pthread_mutex_unlock(&THR_LOCK_myisam); |
|
79
by Brian Aker
USE_RAID cleanup, along with ftbench tools. |
100 |
|
1
by brian
clean slate |
101 |
if (info->dfile >= 0 && my_close(info->dfile,MYF(0))) |
102 |
error = my_errno; |
|
103 |
||
481
by Brian Aker
Remove all of uchar. |
104 |
free((unsigned char*) info); |
1
by brian
clean slate |
105 |
|
106 |
if (error) |
|
107 |
{
|
|
51.1.86
by Jay Pipes
Removed/replaced DBUG symbols |
108 |
return(my_errno=error); |
1
by brian
clean slate |
109 |
}
|
51.1.86
by Jay Pipes
Removed/replaced DBUG symbols |
110 |
return(0); |
1
by brian
clean slate |
111 |
} /* mi_close */ |