mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 23:04:20 +01:00
2f6f08ed88
Changed info->s -> share to get more efficent code Updated arguments to page accessor functions to use MARIA_SHARE * instead of MARIA_HA *. Tested running tests in quick mode (no balance page on insert and only when critical on delete) Fixed bug in underflow handling in quick mode Fixed bug in log handler where it accessed not initialized variable Fixed bug in log handler where it didn't free mutex in unlikely error condition Removed double write of page in case of of some underflow conditions Added DBUG_PRINT in safemutex lock/unlock dbug/dbug.c: Compile without SAFE_MUTEX (to be able to use DBUG_PRINT in safe_mutex code) Use calls to get/set my_thread_var->dbug. (Make dbug independent of compile time options for mysys) include/my_pthread.h: Added prototypes for my_thread_var_get_dbug() & my_thread_var_set_dbug() mysql-test/lib/mtr_report.pl: Don't check warnings in log files if we are using --extern mysys/my_thr_init.c: Added my_thread_var_get_dbug() & my_thread_var_set_dbug() mysys/thr_mutex.c: Added DBUG printing of addresses to mutex for lock/unlock storage/maria/ma_blockrec.c: Fixed comment storage/maria/ma_check.c: Added MARIA_SHARE *share to a lot of places to make code simpler info->s -> share Updated arguments to page accessor functions storage/maria/ma_close.c: Indentation fixes storage/maria/ma_create.c: Calculate min_key_length correctly storage/maria/ma_dbug.c: Indentation fixes storage/maria/ma_delete.c: Added MARIA_SHARE *share to a lot of places to make code simpler info->s -> share Updated arguments to page accessor functions Removed some writing of key pages that underflow (will be written by caller) Fixed crashing bug in underflow handling when using quick mode storage/maria/ma_delete_all.c: Indentation fixes storage/maria/ma_dynrec.c: Indentation fixes storage/maria/ma_extra.c: Fixed indentation Removed old useless code Reset share->changed if we have written state storage/maria/ma_ft_update.c: Added MARIA_SHARE *share to a lot of places to make code simpler info->s -> share Updated arguments to page accessor functions storage/maria/ma_info.c: Indentation fixes storage/maria/ma_key_recover.c: Added MARIA_SHARE *share to a lot of places to make code simpler info->s -> share Updated arguments to page accessor functions storage/maria/ma_locking.c: Indentation fixes storage/maria/ma_loghandler.c: Removed wrapper functions translog_mutex_lock and translog_mutex_unlock (safemutex now does same kind of printing) Renamed LOGREC_REDO_INSERT_ROW_BLOB to LOGREC_REDO_INSERT_NOT_USED to mark it free Fixed some DBUG_PRINT to ensure that convert-dbug-for-diff works Fixed bug in translog_flush() that caused log to stop syncing to disk Added missing mutex_unlock in case of error storage/maria/ma_loghandler.h: Renamed LOGREC_REDO_INSERT_ROW_BLOB to LOGREC_REDO_INSERT_NOT_USED to mark it free storage/maria/ma_open.c: Indentation fixes storage/maria/ma_packrec.c: Indentation fixes storage/maria/ma_page.c: Added MARIA_SHARE *share to a lot of places to make code simpler info->s -> share Updated arguments to page accessor functions Added check that we never write a key page without content (except in recovery where a key page may temporary be without content) storage/maria/ma_preload.c: Updated arguments to page accessor functions storage/maria/ma_range.c: Updated arguments to page accessor functions storage/maria/ma_rkey.c: Indentation fixes storage/maria/ma_rprev.c: Indentation fixes storage/maria/ma_rt_index.c: Added MARIA_SHARE *share to a lot of places to make code simpler info->s -> share Updated arguments to page accessor functions storage/maria/ma_rt_index.h: Updated arguments to page accessor functions storage/maria/ma_rt_key.c: Added MARIA_SHARE *share to a lot of places to make code simpler info->s -> share Updated arguments to page accessor functions storage/maria/ma_rt_mbr.c: Added MARIA_SHARE *share to a lot of places to make code simpler info->s -> share Updated arguments to page accessor functions storage/maria/ma_rt_split.c: Added MARIA_SHARE *share to a lot of places to make code simpler info->s -> share Updated arguments to page accessor functions storage/maria/ma_search.c: Added MARIA_SHARE *share to a lot of places to make code simpler info->s -> share Updated arguments to page accessor functions storage/maria/ma_sort.c: Indentation fixes storage/maria/ma_statrec.c: Indentation fixes storage/maria/ma_test1.c: Added extra undo test Flush also keys in -u1, to ensure that the full log is flushed storage/maria/ma_test2.c: Added extra undo test Flush also keys in -u1, to ensure that the full log is flushed storage/maria/ma_test_recovery.expected: Updated results storage/maria/ma_test_recovery: Added extra undo test storage/maria/ma_update.c: Indentation fixes storage/maria/ma_write.c: Added MARIA_SHARE *share to a lot of places to make code simpler info->s -> share Updated arguments to page accessor functions Prepare for quick mode for insert (don't balance page) storage/maria/maria_chk.c: Added MARIA_SHARE *share to a lot of places to make code simpler info->s -> share Updated arguments to page accessor functions storage/maria/maria_def.h: Updated arguments to page accessor functions
157 lines
4.8 KiB
C
157 lines
4.8 KiB
C
/* Copyright (C) 2006 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
/* close a isam-database */
|
|
/*
|
|
TODO:
|
|
We need to have a separate mutex on the closed file to allow other threads
|
|
to open other files during the time we flush the cache and close this file
|
|
*/
|
|
|
|
#include "maria_def.h"
|
|
|
|
int maria_close(register MARIA_HA *info)
|
|
{
|
|
int error=0,flag;
|
|
my_bool share_can_be_freed= FALSE;
|
|
MARIA_SHARE *share= info->s;
|
|
DBUG_ENTER("maria_close");
|
|
DBUG_PRINT("enter",("base: 0x%lx reopen: %u locks: %u",
|
|
(long) info, (uint) share->reopen,
|
|
(uint) share->tot_locks));
|
|
|
|
pthread_mutex_lock(&THR_LOCK_maria);
|
|
if (info->lock_type == F_EXTRA_LCK)
|
|
info->lock_type=F_UNLCK; /* HA_EXTRA_NO_USER_CHANGE */
|
|
|
|
if (share->reopen == 1 && share->kfile.file >= 0)
|
|
_ma_decrement_open_count(info);
|
|
|
|
if (info->lock_type != F_UNLCK)
|
|
{
|
|
if (maria_lock_database(info,F_UNLCK))
|
|
error=my_errno;
|
|
}
|
|
pthread_mutex_lock(&share->intern_lock);
|
|
|
|
if (share->options & HA_OPTION_READ_ONLY_DATA)
|
|
{
|
|
share->r_locks--;
|
|
share->tot_locks--;
|
|
}
|
|
if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
|
|
{
|
|
if (end_io_cache(&info->rec_cache))
|
|
error=my_errno;
|
|
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
|
|
}
|
|
flag= !--share->reopen;
|
|
maria_open_list=list_delete(maria_open_list,&info->open_list);
|
|
|
|
my_free(info->rec_buff, MYF(MY_ALLOW_ZERO_PTR));
|
|
(*share->end)(info);
|
|
|
|
if (flag)
|
|
{
|
|
/* Last close of file; Flush everything */
|
|
if (share->kfile.file >= 0)
|
|
{
|
|
if ((*share->once_end)(share))
|
|
error= my_errno;
|
|
if (flush_pagecache_blocks(share->pagecache, &share->kfile,
|
|
(share->temporary ?
|
|
FLUSH_IGNORE_CHANGED :
|
|
FLUSH_RELEASE)))
|
|
error= my_errno;
|
|
#ifdef HAVE_MMAP
|
|
if (share->file_map)
|
|
_ma_unmap_file(info);
|
|
#endif
|
|
/*
|
|
If we are crashed, we can safely flush the current state as it will
|
|
not change the crashed state.
|
|
We can NOT write the state in other cases as other threads
|
|
may be using the file at this point
|
|
IF using --external-locking, which does not apply to Maria.
|
|
*/
|
|
if (((share->changed && share->base.born_transactional) ||
|
|
maria_is_crashed(info)))
|
|
{
|
|
/*
|
|
State must be written to file as it was not done at table's
|
|
unlocking.
|
|
*/
|
|
if (_ma_state_info_write(share, 1))
|
|
error= my_errno;
|
|
}
|
|
/*
|
|
File must be synced as it is going out of the maria_open_list and so
|
|
becoming unknown to future Checkpoints.
|
|
*/
|
|
if (my_sync(share->kfile.file, MYF(MY_WME)))
|
|
error= my_errno;
|
|
if (my_close(share->kfile.file, MYF(0)))
|
|
error= my_errno;
|
|
}
|
|
#ifdef THREAD
|
|
thr_lock_delete(&share->lock);
|
|
{
|
|
int i,keys;
|
|
keys = share->state.header.keys;
|
|
VOID(rwlock_destroy(&share->mmap_lock));
|
|
for(i=0; i<keys; i++) {
|
|
VOID(rwlock_destroy(&share->key_root_lock[i]));
|
|
}
|
|
}
|
|
#endif
|
|
DBUG_ASSERT(share->now_transactional == share->base.born_transactional);
|
|
if (share->in_checkpoint == MARIA_CHECKPOINT_LOOKS_AT_ME)
|
|
{
|
|
share->kfile.file= -1; /* because Checkpoint does not need to flush */
|
|
/* we cannot my_free() the share, Checkpoint would see a bad pointer */
|
|
share->in_checkpoint|= MARIA_CHECKPOINT_SHOULD_FREE_ME;
|
|
}
|
|
else
|
|
share_can_be_freed= TRUE;
|
|
}
|
|
pthread_mutex_unlock(&THR_LOCK_maria);
|
|
pthread_mutex_unlock(&share->intern_lock);
|
|
if (share_can_be_freed)
|
|
{
|
|
VOID(pthread_mutex_destroy(&share->intern_lock));
|
|
my_free((uchar *)share, MYF(0));
|
|
}
|
|
if (info->ftparser_param)
|
|
{
|
|
my_free((uchar*)info->ftparser_param, MYF(0));
|
|
info->ftparser_param= 0;
|
|
}
|
|
if (info->dfile.file >= 0)
|
|
{
|
|
/*
|
|
This is outside of mutex so would confuse a concurrent
|
|
Checkpoint. Fortunately in BLOCK_RECORD we close earlier under mutex.
|
|
*/
|
|
if (my_close(info->dfile.file, MYF(0)))
|
|
error = my_errno;
|
|
}
|
|
|
|
delete_dynamic(&info->pinned_pages);
|
|
my_free(info, MYF(0));
|
|
|
|
if (error)
|
|
DBUG_RETURN(my_errno= error);
|
|
DBUG_RETURN(0);
|
|
} /* maria_close */
|