mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 20:42:30 +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
158 lines
4.8 KiB
C
158 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 */
|
|
|
|
/* Remove all rows from a MARIA table */
|
|
/* This clears the status information and truncates files */
|
|
|
|
#include "maria_def.h"
|
|
#include "trnman.h"
|
|
|
|
/**
|
|
@brief deletes all rows from a table
|
|
|
|
@param info Maria handler
|
|
|
|
@return Operation status
|
|
@retval 0 ok
|
|
@retval 1 error
|
|
*/
|
|
|
|
int maria_delete_all_rows(MARIA_HA *info)
|
|
{
|
|
MARIA_SHARE *share= info->s;
|
|
my_bool log_record;
|
|
DBUG_ENTER("maria_delete_all_rows");
|
|
|
|
if (share->options & HA_OPTION_READ_ONLY_DATA)
|
|
{
|
|
DBUG_RETURN(my_errno=EACCES);
|
|
}
|
|
/**
|
|
@todo LOCK take X-lock on table here.
|
|
When we have versioning, if some other thread is looking at this table,
|
|
we cannot shrink the file like this.
|
|
*/
|
|
if (_ma_readinfo(info,F_WRLCK,1))
|
|
DBUG_RETURN(my_errno);
|
|
log_record= share->now_transactional && !share->temporary;
|
|
if (_ma_mark_file_changed(info))
|
|
goto err;
|
|
|
|
if (log_record)
|
|
{
|
|
/*
|
|
This record will be used by Recovery to finish the deletion if it
|
|
crashed. We force it because it's a non-undoable operation.
|
|
*/
|
|
LSN lsn;
|
|
LEX_STRING log_array[TRANSLOG_INTERNAL_PARTS + 1];
|
|
uchar log_data[FILEID_STORE_SIZE];
|
|
log_array[TRANSLOG_INTERNAL_PARTS + 0].str= (char*) log_data;
|
|
log_array[TRANSLOG_INTERNAL_PARTS + 0].length= sizeof(log_data);
|
|
if (unlikely(translog_write_record(&lsn, LOGREC_REDO_DELETE_ALL,
|
|
info->trn, info, 0,
|
|
sizeof(log_array)/sizeof(log_array[0]),
|
|
log_array, log_data, NULL) ||
|
|
translog_flush(lsn)))
|
|
goto err;
|
|
/*
|
|
If we fail in this function after this point, log and table will be
|
|
inconsistent.
|
|
*/
|
|
}
|
|
|
|
/*
|
|
For recovery it matters that this is called after writing the log record,
|
|
so that resetting state.records and state.checksum actually happens under
|
|
log's mutex.
|
|
*/
|
|
_ma_reset_status(info);
|
|
|
|
/*
|
|
If we are using delayed keys or if the user has done changes to the tables
|
|
since it was locked then there may be key blocks in the page cache. Or
|
|
there may be data blocks there. We need to throw them away or they may
|
|
re-enter the emptied table later.
|
|
*/
|
|
if (_ma_flush_table_files(info, MARIA_FLUSH_DATA|MARIA_FLUSH_INDEX,
|
|
FLUSH_IGNORE_CHANGED, FLUSH_IGNORE_CHANGED) ||
|
|
my_chsize(info->dfile.file, 0, 0, MYF(MY_WME)) ||
|
|
my_chsize(share->kfile.file, share->base.keystart, 0, MYF(MY_WME)) )
|
|
goto err;
|
|
|
|
if (_ma_initialize_data_file(share, info->dfile.file))
|
|
goto err;
|
|
|
|
/*
|
|
The operations above on the index/data file will be forced to disk at
|
|
Checkpoint or maria_close() time. So we can reset:
|
|
*/
|
|
if (log_record)
|
|
info->trn->rec_lsn= LSN_IMPOSSIBLE;
|
|
|
|
VOID(_ma_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
|
|
#ifdef HAVE_MMAP
|
|
/* Resize mmaped area */
|
|
rw_wrlock(&info->s->mmap_lock);
|
|
_ma_remap_file(info, (my_off_t)0);
|
|
rw_unlock(&info->s->mmap_lock);
|
|
#endif
|
|
allow_break(); /* Allow SIGHUP & SIGINT */
|
|
DBUG_RETURN(0);
|
|
|
|
err:
|
|
{
|
|
int save_errno=my_errno;
|
|
VOID(_ma_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
|
|
info->update|=HA_STATE_WRITTEN; /* Buffer changed */
|
|
allow_break(); /* Allow SIGHUP & SIGINT */
|
|
DBUG_RETURN(my_errno=save_errno);
|
|
}
|
|
} /* maria_delete_all_rows */
|
|
|
|
|
|
/*
|
|
Reset status information
|
|
|
|
SYNOPSIS
|
|
_ma_reset_status()
|
|
maria Maria handler
|
|
|
|
DESCRIPTION
|
|
Resets data and index file information as if the file would be empty
|
|
Files are not touched.
|
|
*/
|
|
|
|
void _ma_reset_status(MARIA_HA *info)
|
|
{
|
|
MARIA_SHARE *share= info->s;
|
|
MARIA_STATE_INFO *state= &share->state;
|
|
uint i;
|
|
|
|
info->state->records= info->state->del= state->split= 0;
|
|
state->changed= 0; /* File is optimized */
|
|
state->dellink= HA_OFFSET_ERROR;
|
|
state->sortkey= (ushort) ~0;
|
|
info->state->key_file_length= share->base.keystart;
|
|
info->state->data_file_length= 0;
|
|
info->state->empty= info->state->key_empty= 0;
|
|
info->state->checksum= 0;
|
|
|
|
/* Drop the delete key chain. */
|
|
state->key_del= HA_OFFSET_ERROR;
|
|
/* Clear all keys */
|
|
for (i=0 ; i < share->base.keys ; i++)
|
|
state->key_root[i]= HA_OFFSET_ERROR;
|
|
}
|