mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 04:53:01 +01:00
30d3d8d3fc
- Ignore CRC errors in REDO for potential new pages - Ignore CRC errors when repairing tables - Don't do readcheck callback on read error - Set my_errno to HA_ERR_WRONG_CRC if we find page with wrong CRC - Check index page for length before calculating CRC to catch bad pages Fixed bugs where we used wrong file descriptor to read/write bitmaps Fixed wrong hash key in 'files_in_flush' Fixed wrong lock method when writing bitmap Fixed some wrong printf statements in check/repair that caused core dumps Fixed argument to translog_page_validator that cause reading of log files to fail Store number of bytes used for delete-linked key pages to be able to use standard index CRC for deleted key pages. Use fast 'dummy' pagecheck callbacks for temporary tables Don't die silently if flush finds pinned pages Give error (for now) if one tries to create a transactional table with fulltext or spatial keys Removed some not needed calls to pagecache_file_init() Added checking of pagecache checksums to ma_test1 and ma_test2 More DBUG Fixed some DBUG_PRINT to be in line with rest of the code include/my_base.h: Added HA_ERR_INTERNAL_ERROR (used for flush with pinned pages) and HA_ERR_WRONG_CRC mysql-test/r/binlog_unsafe.result: Added missing DROP VIEW statement mysql-test/r/maria.result: Added TRANSACTIONAL=0 when testing with fulltext keys Added test that verifies we can't yet create transactional test with fulltext or spatial keys mysql-test/r/ps_maria.result: Added TRANSACTIONAL=0 when testing with fulltext keys mysql-test/t/binlog_unsafe.test: Added missing DROP VIEW statement mysql-test/t/maria.test: Added TRANSACTIONAL=0 when testing with fulltext keys Added test that verifies we can't yet create transactional test with fulltext or spatial keys mysql-test/t/ps_maria.test: Added TRANSACTIONAL=0 when testing with fulltext keys mysys/my_fopen.c: Fd: -> fd: mysys/my_handler.c: Added new error messages mysys/my_lock.c: Fd: -> fd: mysys/my_pread.c: Fd: -> fd: mysys/my_read.c: Fd: -> fd: mysys/my_seek.c: Fd: -> fd: mysys/my_sync.c: Fd: -> fd: mysys/my_write.c: Fd: -> fd: sql/mysqld.cc: Fixed wrong argument to my_uuid_init() sql/sql_plugin.cc: Unified DBUG_PRINT (for convert-dbug-for-diff) storage/maria/ma_bitmap.c: Fixed wrong lock method when writing bitmap Fixed valgrind error Use fast 'dummy' pagecheck callbacks for temporary tables Faster bitmap handling for non transational tables storage/maria/ma_blockrec.c: Fixed that bitmap reading is done with the correct filehandle Handle reading of pages with wrong CRC when page contect doesn't matter Use the page buffer also when we get WRONG CRC or FILE_TOO_SHORT. (Faster and fixed a couple of bugs) storage/maria/ma_check.c: Split long strings for readablity Fixed some wrong printf statements that caused core dumps Use bitmap.file for bitmaps Ignore pages with wrong CRC storage/maria/ma_close.c: More DBUG_PRINT storage/maria/ma_create.c: Give error (for now) if one tries to create a crash safe table with fulltext or spatial keys storage/maria/ma_key_recover.c: Ignore HA_ERR_WRONG_CRC for new pages info->s -> share Store number of bytes used for delete-linked key pages to be able to use standard index CRC for deleted key pages. storage/maria/ma_loghandler.c: Fixed argument to translog_page_validator() storage/maria/ma_open.c: Removed old VMS specific code Added function to setup pagecache callbacks Moved code around to set 'share->temporary' early Removed some not needed calls to pagecache_file_init() storage/maria/ma_page.c: Store number of bytes used for delete-linked key pages to be able to use standard index CRC for deleted key pages. storage/maria/ma_pagecache.c: Don't do readcheck callback on read error Reset PCBLOCK_ERROR in pagecache_unlock_by_link() if we write page Set my_errno to HA_ER_INTERNAL_ERROR if flush() finds pinned pages Don't die silently if flush finds pinned pages. Use correct file descriptor when flushing pages Fixed wrong hash key in 'files_in_flush'; This must be the file descriptor, not the PAGECACHE_FILE as there may be several PAGECACHE_FILE for same file descriptor More DBUG_PRINT storage/maria/ma_pagecrc.c: Removed inline from not tiny static function Set my_errno to HA_ERR_WRONG_CRC if we find page with wrong CRC (Otherwise my_errno may be 0, and a lot of other code will be confused) CRCerror -> error (to keep code uniform) Print crc with %lu, as in my_checksum() uchar* -> uchar * Check index page for length before calculating CRC to catch bad pages Added 'dummy' crc_check and filler functions that are used for temporary tables storage/maria/ma_recovery.c: More DBUG More message to users to give information what phase failed Better error message if recovery failed storage/maria/ma_test1.c: Added checking of page checksums (combined with 'c' to not have to add more test runs) storage/maria/ma_test2.c: Added checking of page checksums (combined with 'c' to not have to add more test runs) storage/maria/maria_chk.c: Fixed wrong argument to _ma_check_print_error() storage/maria/maria_def.h: Added format information to _ma_check_print_xxxx functions uchar* -> uchar *
194 lines
5.1 KiB
C
194 lines
5.1 KiB
C
/* Copyright (C) 2000-2003 MySQL 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 */
|
|
|
|
#include "mysys_priv.h"
|
|
#include "mysys_err.h"
|
|
#include <errno.h>
|
|
#undef MY_HOW_OFTEN_TO_ALARM
|
|
#define MY_HOW_OFTEN_TO_ALARM ((int) my_time_to_wait_for_lock)
|
|
#ifdef NO_ALARM_LOOP
|
|
#undef NO_ALARM_LOOP
|
|
#endif
|
|
#include <my_alarm.h>
|
|
#ifdef __WIN__
|
|
#include <sys/locking.h>
|
|
#endif
|
|
#ifdef __NETWARE__
|
|
#include <nks/fsio.h>
|
|
#endif
|
|
|
|
/*
|
|
Lock a part of a file
|
|
|
|
RETURN VALUE
|
|
0 Success
|
|
-1 An error has occured and 'my_errno' is set
|
|
to indicate the actual error code.
|
|
*/
|
|
|
|
int my_lock(File fd, int locktype, my_off_t start, my_off_t length,
|
|
myf MyFlags)
|
|
{
|
|
#ifdef HAVE_FCNTL
|
|
int value;
|
|
ALARM_VARIABLES;
|
|
#endif
|
|
#ifdef __NETWARE__
|
|
int nxErrno;
|
|
#endif
|
|
DBUG_ENTER("my_lock");
|
|
DBUG_PRINT("my",("fd: %d Op: %d start: %ld Length: %ld MyFlags: %d",
|
|
fd,locktype,(long) start,(long) length,MyFlags));
|
|
#ifdef VMS
|
|
DBUG_RETURN(0);
|
|
#else
|
|
if (my_disable_locking && ! (MyFlags & MY_FORCE_LOCK))
|
|
DBUG_RETURN(0);
|
|
|
|
#if defined(__NETWARE__)
|
|
{
|
|
NXSOffset_t nxLength = length;
|
|
unsigned long nxLockFlags = 0;
|
|
|
|
if (length == F_TO_EOF)
|
|
{
|
|
/* EOF is interpreted as a very large length. */
|
|
nxLength = 0x7FFFFFFFFFFFFFFF;
|
|
}
|
|
|
|
if (locktype == F_UNLCK)
|
|
{
|
|
/* The lock flags are currently ignored by NKS. */
|
|
if (!(nxErrno= NXFileRangeUnlock(fd, 0L, start, nxLength)))
|
|
DBUG_RETURN(0);
|
|
}
|
|
else
|
|
{
|
|
if (locktype == F_RDLCK)
|
|
{
|
|
/* A read lock is mapped to a shared lock. */
|
|
nxLockFlags = NX_RANGE_LOCK_SHARED;
|
|
}
|
|
else
|
|
{
|
|
/* A write lock is mapped to an exclusive lock. */
|
|
nxLockFlags = NX_RANGE_LOCK_EXCL;
|
|
}
|
|
|
|
if (MyFlags & MY_DONT_WAIT)
|
|
{
|
|
/* Don't block on the lock. */
|
|
nxLockFlags |= NX_RANGE_LOCK_TRYLOCK;
|
|
}
|
|
|
|
if (!(nxErrno= NXFileRangeLock(fd, nxLockFlags, start, nxLength)))
|
|
DBUG_RETURN(0);
|
|
}
|
|
}
|
|
#elif defined(HAVE_LOCKING)
|
|
/* Windows */
|
|
{
|
|
my_bool error= FALSE;
|
|
pthread_mutex_lock(&my_file_info[fd].mutex);
|
|
if (MyFlags & MY_SEEK_NOT_DONE)
|
|
{
|
|
if( my_seek(fd,start,MY_SEEK_SET,MYF(MyFlags & ~MY_SEEK_NOT_DONE))
|
|
== MY_FILEPOS_ERROR )
|
|
{
|
|
/*
|
|
If my_seek fails my_errno will already contain an error code;
|
|
just unlock and return error code.
|
|
*/
|
|
DBUG_PRINT("error",("my_errno: %d (%d)",my_errno,errno));
|
|
pthread_mutex_unlock(&my_file_info[fd].mutex);
|
|
DBUG_RETURN(-1);
|
|
}
|
|
}
|
|
error= locking(fd,locktype,(ulong) length) && errno != EINVAL;
|
|
pthread_mutex_unlock(&my_file_info[fd].mutex);
|
|
if (!error)
|
|
DBUG_RETURN(0);
|
|
}
|
|
#else
|
|
#if defined(HAVE_FCNTL)
|
|
{
|
|
struct flock lock;
|
|
|
|
lock.l_type= (short) locktype;
|
|
lock.l_whence= SEEK_SET;
|
|
lock.l_start= (off_t) start;
|
|
lock.l_len= (off_t) length;
|
|
|
|
if (MyFlags & (MY_NO_WAIT | MY_SHORT_WAIT))
|
|
{
|
|
if (fcntl(fd,F_SETLK,&lock) != -1) /* Check if we can lock */
|
|
DBUG_RETURN(0); /* Ok, file locked */
|
|
if (MyFlags & MY_NO_WAIT)
|
|
{
|
|
my_errno= (errno == EACCES) ? EAGAIN : errno ? errno : -1;
|
|
DBUG_RETURN(-1);
|
|
}
|
|
|
|
DBUG_PRINT("info",("Was locked, trying with alarm"));
|
|
ALARM_INIT;
|
|
while ((value=fcntl(fd,F_SETLKW,&lock)) && ! ALARM_TEST &&
|
|
errno == EINTR)
|
|
{ /* Setup again so we don`t miss it */
|
|
ALARM_REINIT;
|
|
}
|
|
ALARM_END;
|
|
if (value != -1)
|
|
DBUG_RETURN(0);
|
|
if (errno == EINTR)
|
|
errno=EAGAIN;
|
|
}
|
|
else if (fcntl(fd,F_SETLKW,&lock) != -1) /* Wait until a lock */
|
|
DBUG_RETURN(0);
|
|
}
|
|
#else
|
|
if (MyFlags & MY_SEEK_NOT_DONE)
|
|
{
|
|
if (my_seek(fd,start,MY_SEEK_SET,MYF(MyFlags & ~MY_SEEK_NOT_DONE))
|
|
== MY_FILEPOS_ERROR)
|
|
{
|
|
/*
|
|
If an error has occured in my_seek then we will already
|
|
have an error code in my_errno; Just return error code.
|
|
*/
|
|
DBUG_RETURN(-1);
|
|
}
|
|
}
|
|
if (lockf(fd,locktype,length) != -1)
|
|
DBUG_RETURN(0);
|
|
#endif /* HAVE_FCNTL */
|
|
#endif /* HAVE_LOCKING */
|
|
|
|
#ifdef __NETWARE__
|
|
my_errno = nxErrno;
|
|
#else
|
|
/* We got an error. We don't want EACCES errors */
|
|
my_errno=(errno == EACCES) ? EAGAIN : errno ? errno : -1;
|
|
#endif
|
|
if (MyFlags & MY_WME)
|
|
{
|
|
if (locktype == F_UNLCK)
|
|
my_error(EE_CANTUNLOCK,MYF(ME_BELL+ME_WAITTANG),my_errno);
|
|
else
|
|
my_error(EE_CANTLOCK,MYF(ME_BELL+ME_WAITTANG),my_errno);
|
|
}
|
|
DBUG_PRINT("error",("my_errno: %d (%d)",my_errno,errno));
|
|
DBUG_RETURN(-1);
|
|
#endif /* ! VMS */
|
|
} /* my_lock */
|