Commit c719e1fd authored by unknown's avatar unknown

Added wrapper for chmod(): my_chmod()

Automaticly disable ma_test_recovery if not compiled with debugging. This fixes that make test works in Maria.
Fixed wrong merge of ma_init.c from 5.1
Portability fixes:
- Use my_chmod() instead of my_chmod()
- Use my_access() instead of my_stat() to test if file exists
- Don't test result value of pthread_mutex_lock() and pthread_mutex_unlock() as this is not portable
- No reason to test if file exists before we delete it



include/my_sys.h:
  Added my_chmod
include/mysys_err.h:
  Added error for my_chmod
mysys/Makefile.am:
  Added my_chmod
mysys/errors.c:
  Added error for my_chmod
mysys/my_init.c:
  Syncronize with 5.1 to fix setting of QueryPerformanceFrequency()
storage/maria/ma_test1.c:
  Changed short option of --skip-delete and --skip-update to be more logical
storage/maria/ma_test_recovery.expected:
  Updated results after adding more tests
storage/maria/ma_test_recovery:
  Abort test nicely if we are runnning without debugging
  Added more tests
  Changed temporary file names so that one can run maria_chk on them
  Removed some old comments
storage/maria/maria_read_log.c:
  Added note if maria_read_log will not be able to create byte-to-byte identical tables compared to normal execution
storage/maria/unittest/ma_pagecache_consist.c:
  Removed wrong setting of buff that caused memory overwrite
  Use my_chmod() instead of chmod()
  Don't test result value of pthread_mutex_lock() and pthread_mutex_unlock() as this is not portable
storage/maria/unittest/ma_pagecache_single.c:
  Use my_chmod() instead of chmod()
  Don't test result value of pthread_mutex_lock() and pthread_mutex_unlock() as this is not portable
storage/maria/unittest/ma_test_loghandler_first_lsn-t.c:
  No reason to test if file exists before we delete it
storage/maria/unittest/ma_test_loghandler_multithread-t.c:
  Don't test result value of pthread_mutex_lock() and pthread_mutex_unlock() as this is not portable
storage/maria/unittest/ma_test_loghandler_noflush-t.c:
  No reason to test if file exists before we delete it
storage/maria/unittest/ma_test_loghandler_nologs-t.c:
  Use my_access() instead of my_stat() to test if file exists
storage/maria/unittest/ma_test_loghandler_pagecache-t.c:
  No reason to test if file exists before we delete it
  chmod -> my_chmod
mysys/my_chmod.c:
  Added wrapper for chmod()
parent f8b3e118
......@@ -645,6 +645,7 @@ extern FILE *my_fopen(const char *FileName,int Flags,myf MyFlags);
extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags);
extern int my_fclose(FILE *fd,myf MyFlags);
extern int my_chsize(File fd,my_off_t newlength, int filler, myf MyFlags);
extern int my_chmod(const char *name, mode_t mode, myf my_flags);
extern int my_sync(File fd, myf my_flags);
extern int my_sync_dir(const char *dir_name, myf my_flags);
extern int my_sync_dir_by_file(const char *file_name, myf my_flags);
......
......@@ -62,7 +62,8 @@ extern const char * NEAR globerrs[]; /* my_error_messages is here */
#define EE_UNKNOWN_COLLATION 28
#define EE_FILENOTFOUND 29
#define EE_FILE_NOT_CLOSED 30
#define EE_ERROR_LAST 30 /* Copy last error nr */
#define EE_CANT_CHMOD 31
#define EE_ERROR_LAST 31 /* Copy last error nr */
/* Add error numbers before EE_ERROR_LAST and change it accordingly. */
/* exit codes for all MySQL programs */
......
......@@ -45,7 +45,7 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c my_mmap.c \
tree.c trie.c list.c hash.c array.c string.c typelib.c \
my_copy.c my_append.c my_lib.c \
my_delete.c my_rename.c my_redel.c \
my_chsize.c my_clock.c \
my_chsize.c my_chmod.c my_clock.c \
my_quick.c my_lockmem.c my_static.c \
my_sync.c my_getopt.c my_mkdir.c \
default_modify.c default.c \
......
......@@ -49,7 +49,8 @@ const char * NEAR globerrs[GLOBERRS]=
"Can't sync file '%s' to disk (Errcode: %d)",
"Collation '%s' is not a compiled collation and is not specified in the '%s' file",
"File '%s' not found (Errcode: %d)",
"File '%s' (fileno: %d) was not closed"
"File '%s' (fileno: %d) was not closed",
"Can't change mode for file '%s' to 0x%lx (Error: %d)"
};
void init_glob_errs(void)
......@@ -90,5 +91,6 @@ void init_glob_errs()
EE(EE_UNKNOWN_COLLATION)= "Collation '%s' is not a compiled collation and is not specified in the %s file";
EE(EE_FILENOTFOUND) = "File '%s' not found (Errcode: %d)";
EE(EE_FILE_NOT_CLOSED) = "File '%s' (fileno: %d) was not closed";
EE(EE_CANT_CHMOD) = "Can't change mode for file '%s' to 0x%lx (Error: %d)";
}
#endif
/* Copyright (C) 2000 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"
/**
@brief Change mode of file.
@fn my_chmod()
@param name Filename
@param mode_t Mode
@param my_flags Flags
@notes
The mode of the file given by path or referenced by fildes is changed
@retval 0 Ok
@retval # Error
*/
int my_chmod(const char *name, mode_t mode, myf my_flags)
{
DBUG_ENTER("my_chmod");
DBUG_PRINT("my",("name: %s mode: %lu flags: %d", name, (ulong) mode,
my_flags));
if (chmod(name, mode))
{
my_errno= errno;
if (my_flags & MY_WME)
my_error(EE_CANT_CHMOD, MYF(0), name, (ulong) mode, my_errno);
DBUG_RETURN(1);
}
DBUG_RETURN(0);
}
......@@ -356,6 +356,30 @@ static void my_win_init(void)
_tzset();
/* The following is used by time functions */
#define OFFSET_TO_EPOC ((__int64) 134774 * 24 * 60 * 60 * 1000 * 1000 * 10)
#define MS 10000000
{
FILETIME ft;
LARGE_INTEGER li, t_cnt;
DBUG_ASSERT(sizeof(LARGE_INTEGER) == sizeof(query_performance_frequency));
if (QueryPerformanceFrequency((LARGE_INTEGER *)&query_performance_frequency) == 0)
query_performance_frequency= 0;
else
{
GetSystemTimeAsFileTime(&ft);
li.LowPart= ft.dwLowDateTime;
li.HighPart= ft.dwHighDateTime;
query_performance_offset= li.QuadPart-OFFSET_TO_EPOC;
QueryPerformanceCounter(&t_cnt);
query_performance_offset-= (t_cnt.QuadPart /
query_performance_frequency * MS +
t_cnt.QuadPart %
query_performance_frequency * MS /
query_performance_frequency);
}
}
/* apre la chiave HKEY_LOCAL_MACHINES\software\MySQL */
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,(LPCTSTR)targetKey,0,
KEY_READ,&hSoftMysql) != ERROR_SUCCESS)
......@@ -393,27 +417,6 @@ static void my_win_init(void)
/* chiude la chiave */
RegCloseKey(hSoftMysql) ;
/* The following is used by time functions */
#define OFFSET_TO_EPOC ((__int64) 134774 * 24 * 60 * 60 * 1000 * 1000 * 10)
#define MS 10000000
{
FILETIME ft;
LARGE_INTEGER li, t_cnt;
DBUG_ASSERT(sizeof(LARGE_INTEGER) == sizeof(query_performance_frequency));
if (QueryPerformanceFrequency((LARGE_INTEGER *)&query_performance_frequency))
query_performance_frequency= 0;
else
{
GetSystemTimeAsFileTime(&ft);
li.LowPart= ft.dwLowDateTime;
li.HighPart= ft.dwHighDateTime;
query_performance_offset= li.QuadPart-OFFSET_TO_EPOC;
QueryPerformanceCounter(&t_cnt);
query_performance_offset-= (t_cnt.QuadPart / query_performance_frequency * MS +
t_cnt.QuadPart % query_performance_frequency * MS /
query_performance_frequency);
}
}
DBUG_VOID_RETURN ;
}
......
......@@ -752,9 +752,9 @@ static struct my_option my_long_options[] =
{"silent", 's', "Undocumented",
(uchar**) &silent, (uchar**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
0, 0},
{"skip-delete", 'U', "Don't test deletes", (uchar**) &skip_delete,
{"skip-delete", 'D', "Don't test deletes", (uchar**) &skip_delete,
(uchar**) &skip_delete, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"skip-update", 'D', "Don't test updates", (uchar**) &skip_update,
{"skip-update", 'U', "Don't test updates", (uchar**) &skip_update,
(uchar**) &skip_update, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"testflag", 't', "Stop test at specified stage", (uchar**) &testflag,
(uchar**) &testflag, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
......
......@@ -20,6 +20,13 @@ fi
echo "MARIA RECOVERY TESTS"
if $maria_path/maria_read_log --help | grep IDENTICAL_PAGES_AFTER_RECOVERY
then
echo "Recovery tests require compilation with DBUG"
echo "Aborting test"
exit 0
fi
check_table_is_same()
{
# Computes checksum of new table and compares to checksum of old table
......@@ -90,7 +97,7 @@ echo "Testing the REDO PHASE ALONE"
# identical to the saved original.
# Does not test the index file as we don't have logging for it yet.
set -- "ma_test1 $silent -M -T -c" "ma_test2 $silent -L -K -W -P -M -T -c" "ma_test2 $silent -M -T -c -b65000"
set -- "ma_test1 $silent -M -T -c" "ma_test2 $silent -L -K -W -P -M -T -c -d500" "ma_test2 $silent -M -T -c -b65000" "ma_test2 $silent -M -T -c -b65000 -d800"
while [ $# != 0 ]
do
prog=$1
......@@ -153,8 +160,8 @@ do
rm maria_log.* maria_log_control
echo "TEST WITH $prog $abort_run_args$test_undo (additional aborted work)"
$maria_path/$prog $abort_run_args$test_undo
cp $table.MAD $tmp/$table.MAD.before_undo
cp $table.MAI $tmp/$table.MAI.before_undo
cp $table.MAD $tmp/$table-before_undo.MAD
cp $table.MAI $tmp/$table-before_undo.MAI
# The lines below seem unneeded, will be removed soon
# We have to copy and restore logs, as running maria_read_log will
......@@ -169,8 +176,8 @@ do
# probably nothing to undo went to log or data file
apply_log "dontknow"
fi
cp $table.MAD $tmp/$table.MAD.after_undo
cp $table.MAI $tmp/$table.MAI.after_undo
cp $table.MAD $tmp/$table-after_undo.MAD
cp $table.MAI $tmp/$table-after_undo.MAI
# It is impossible to do a "cmp" between .good and .after_undo,
# because the UNDO phase generated log
......@@ -184,18 +191,15 @@ do
# We can't do a binary compary as there may have been different number
# of calls to compact_page. We can enable this if we first call
# maria-check to generate identically compacted pages.
# cmp $table.MAD $tmp/$table.MAD.after_undo
# can't do this, creation time differs at least; enable it if you
# have a "cmp" which ignores the header.
cmp $table.MAI $tmp/$table.MAI.after_undo
# cmp $table.MAD $tmp/$table-after_undo.MAD
cmp $table.MAI $tmp/$table-after_undo.MAI
check_table_is_same
echo "testing applying of CLRs to recreate table"
rm $table.MA?
# cp $tmp/maria_log* $maria_path #unneeded
apply_log "shouldnotchangelog"
# cmp $table.MAD $tmp/$table.MAD.after_undo
# can't do this, creation time differs at least
cmp $table.MAI $tmp/$table.MAI.after_undo
# cmp $table.MAD $tmp/$table-after_undo.MAD
cmp $table.MAI $tmp/$table-after_undo.MAI
check_table_is_same
shift 3
done
......
......@@ -3,7 +3,7 @@ TEST WITH ma_test1 -s -M -T -c
applying log
testing idempotency
applying log
TEST WITH ma_test2 -s -L -K -W -P -M -T -c
TEST WITH ma_test2 -s -L -K -W -P -M -T -c -d500
applying log
testing idempotency
applying log
......@@ -11,6 +11,10 @@ TEST WITH ma_test2 -s -M -T -c -b65000
applying log
testing idempotency
applying log
TEST WITH ma_test2 -s -M -T -c -b65000 -d800
applying log
testing idempotency
applying log
Testing the REDO AND UNDO PHASE
TEST WITH ma_test1 -s -M -T -c -N --testflag=1 (commit at end)
TEST WITH ma_test1 -s -M -T -c -N --testflag=2 --test-undo=1 (additional aborted work)
......
......@@ -217,6 +217,12 @@ static void usage(void)
puts("Display and apply log records from a MARIA transaction log");
puts("found in the current directory (for now)");
#ifndef IDENTICAL_PAGES_AFTER_RECOVERY
puts("\nNote: Maria is compiled without -DIDENTICAL_PAGES_AFTER_RECOVERY\n"
"which means that the table files are not byte-to-byte identical to\n"
"files created during normal execution. This should be ok, except for\n"
"test scripts that tries to compare files before and after recovery.");
#endif
VOID(printf("\nUsage: %s OPTIONS\n", my_progname_short));
puts("You need to use one of -o or -a");
my_print_help(my_long_options);
......
......@@ -183,7 +183,6 @@ void put_rec(uchar *buff, uint end, uint len, uint tag)
end+= sizeof(uint);
num++;
*((uint *)buff)= num;
*((uint*)(buff + end))= len;
for (i= end; i < (len + end); i++)
{
buff[i]= (uchar) num % 256;
......@@ -348,12 +347,8 @@ int main(int argc __attribute__((unused)),
pagecache_file_init(file1, &dummy_callback, &dummy_callback,
&dummy_fail_callback, &dummy_callback, NULL);
DBUG_PRINT("info", ("file1: %d", file1.file));
if (chmod(file1_name, S_IRWXU | S_IRWXG | S_IRWXO) != 0)
{
fprintf(stderr, "Got error during file1 chmod() (errno: %d)\n",
errno);
if (my_chmod(file1_name, S_IRWXU | S_IRWXG | S_IRWXO, MYF(MY_WME)))
exit(1);
}
my_pwrite(file1.file, "test file", 9, 0, MYF(0));
if ((error= pthread_cond_init(&COND_thread_count, NULL)))
......@@ -411,12 +406,7 @@ int main(int argc __attribute__((unused)),
flush_pagecache_blocks(&pagecache, &file1, FLUSH_FORCE_WRITE);
free(buffr);
}
if ((error= pthread_mutex_lock(&LOCK_thread_count)))
{
fprintf(stderr,"LOCK_thread_count: %d from pthread_mutex_lock (errno: %d)\n",
error,errno);
exit(1);
}
pthread_mutex_lock(&LOCK_thread_count);
while (number_of_readers != 0 || number_of_writers != 0)
{
if (number_of_readers != 0)
......@@ -454,15 +444,13 @@ int main(int argc __attribute__((unused)),
pthread_attr_destroy(&thr_attr);
/* wait finishing */
if ((error= pthread_mutex_lock(&LOCK_thread_count)))
fprintf(stderr,"LOCK_thread_count: %d from pthread_mutex_lock\n",error);
pthread_mutex_lock(&LOCK_thread_count);
while (thread_count)
{
if ((error= pthread_cond_wait(&COND_thread_count,&LOCK_thread_count)))
fprintf(stderr,"COND_thread_count: %d from pthread_cond_wait\n",error);
}
if ((error= pthread_mutex_unlock(&LOCK_thread_count)))
fprintf(stderr,"LOCK_thread_count: %d from pthread_mutex_unlock\n",error);
pthread_mutex_unlock(&LOCK_thread_count);
DBUG_PRINT("info", ("thread ended"));
end_pagecache(&pagecache, 1);
......
......@@ -537,13 +537,9 @@ int main(int argc __attribute__((unused)),
my_delete(file2_name, MYF(0));
DBUG_PRINT("info", ("file1: %d", file1.file));
if (chmod(file1_name, S_IRWXU | S_IRWXG | S_IRWXO) != 0)
{
fprintf(stderr, "Got error during file1 chmod() (errno: %d)\n",
errno);
if (my_chmod(file1_name, S_IRWXU | S_IRWXG | S_IRWXO, MYF(MY_WME)))
exit(1);
}
my_pwrite(file1.file, "test file", 9, 0, MYF(0));
my_pwrite(file1.file, "test file", 9, 0, MYF(MY_WME));
if ((error= pthread_cond_init(&COND_thread_count, NULL)))
{
......@@ -587,12 +583,7 @@ int main(int argc __attribute__((unused)),
}
DBUG_PRINT("info", ("Page cache %d pages", pagen));
if ((error=pthread_mutex_lock(&LOCK_thread_count)))
{
fprintf(stderr,"Got error: %d from pthread_mutex_lock (errno: %d)\n",
error,errno);
exit(1);
}
pthread_mutex_lock(&LOCK_thread_count);
param=(int*) malloc(sizeof(int));
*param= 1;
if ((error= pthread_create(&tid, &thr_attr, test_thread, (void*) param)))
......@@ -607,15 +598,13 @@ int main(int argc __attribute__((unused)),
pthread_attr_destroy(&thr_attr);
if ((error= pthread_mutex_lock(&LOCK_thread_count)))
fprintf(stderr,"Got error: %d from pthread_mutex_lock\n",error);
pthread_mutex_lock(&LOCK_thread_count);
while (thread_count)
{
if ((error= pthread_cond_wait(&COND_thread_count,&LOCK_thread_count)))
fprintf(stderr,"Got error: %d from pthread_cond_wait\n",error);
}
if ((error= pthread_mutex_unlock(&LOCK_thread_count)))
fprintf(stderr,"Got error: %d from pthread_mutex_unlock\n",error);
pthread_mutex_unlock(&LOCK_thread_count);
DBUG_PRINT("info", ("thread ended"));
end_pagecache(&pagecache, 1);
......@@ -628,7 +617,6 @@ int main(int argc __attribute__((unused)),
my_end(0);
DBUG_PRINT("info", ("file1 (%d) closed", file1.file));
DBUG_PRINT("info", ("Program end"));
DBUG_RETURN(exit_status());
......
......@@ -24,7 +24,6 @@ int main(int argc __attribute__((unused)), char *argv[])
uchar long_tr_id[6];
PAGECACHE pagecache;
LSN lsn, first_lsn, theor_lsn;
MY_STAT st;
LEX_STRING parts[TRANSLOG_INTERNAL_PARTS + 1];
MY_INIT(argv[0]);
......@@ -36,10 +35,8 @@ int main(int argc __attribute__((unused)), char *argv[])
if (maria_log_remove())
exit(1);
/* be sure that we have no logs in the directory*/
if (my_stat(CONTROL_FILE_BASE_NAME, &st, MYF(0)))
my_delete(CONTROL_FILE_BASE_NAME, MYF(0));
if (my_stat(first_translog_file, &st, MYF(0)))
my_delete(first_translog_file, MYF(0));
my_delete(CONTROL_FILE_BASE_NAME, MYF(0));
my_delete(first_translog_file, MYF(0));
bzero(long_tr_id, 6);
#ifndef DBUG_OFF
......
......@@ -317,13 +317,7 @@ int main(int argc __attribute__((unused)),
}
if ((error= pthread_mutex_lock(&LOCK_thread_count)))
{
fprintf(stderr, "LOCK_thread_count: %d from pthread_mutex_lock "
"(errno: %d)\n", error, errno);
exit(1);
}
pthread_mutex_lock(&LOCK_thread_count);
while (number_of_writers != 0)
{
param= (int*) malloc(sizeof(int));
......@@ -343,15 +337,13 @@ int main(int argc __attribute__((unused)),
pthread_attr_destroy(&thr_attr);
/* wait finishing */
if ((error= pthread_mutex_lock(&LOCK_thread_count)))
fprintf(stderr, "LOCK_thread_count: %d from pthread_mutex_lock\n", error);
pthread_mutex_lock(&LOCK_thread_count);
while (thread_count)
{
if ((error= pthread_cond_wait(&COND_thread_count, &LOCK_thread_count)))
fprintf(stderr, "COND_thread_count: %d from pthread_cond_wait\n", error);
}
if ((error= pthread_mutex_unlock(&LOCK_thread_count)))
fprintf(stderr, "LOCK_thread_count: %d from pthread_mutex_unlock\n", error);
pthread_mutex_unlock(&LOCK_thread_count);
/* Find last LSN and flush up to it (all our log) */
{
......
......@@ -25,7 +25,6 @@ int main(int argc __attribute__((unused)), char *argv[])
uchar long_tr_id[6];
PAGECACHE pagecache;
LSN first_lsn;
MY_STAT st;
TRANSLOG_HEADER_BUFFER rec;
LEX_STRING parts[TRANSLOG_INTERNAL_PARTS + 1];
......@@ -38,10 +37,8 @@ int main(int argc __attribute__((unused)), char *argv[])
if (maria_log_remove())
exit(1);
/* be sure that we have no logs in the directory*/
if (my_stat(CONTROL_FILE_BASE_NAME, &st, MYF(0)))
my_delete(CONTROL_FILE_BASE_NAME, MYF(0));
if (my_stat(first_translog_file, &st, MYF(0)))
my_delete(first_translog_file, MYF(0));
my_delete(CONTROL_FILE_BASE_NAME, MYF(0));
my_delete(first_translog_file, MYF(0));
bzero(long_tr_id, 6);
#ifndef DBUG_OFF
......
......@@ -107,12 +107,11 @@ int main(int argc __attribute__((unused)), char *argv[])
ma_control_file_end();
{
MY_STAT stat_buff;
char file_name[FN_REFLEN];
for (i= 1; i <= 2; i++)
{
translog_filename_by_fileno(i, file_name);
if (my_stat(file_name, &stat_buff, MY_WME) == NULL)
if (my_access(file_name, W_OK))
{
fprintf(stderr, "No file '%s'\n", file_name);
exit(1);
......
......@@ -63,10 +63,8 @@ int main(int argc __attribute__((unused)), char *argv[])
if (maria_log_remove())
exit(1);
/* be sure that we have no logs in the directory*/
if (my_stat(CONTROL_FILE_BASE_NAME, &st, MYF(0)))
my_delete(CONTROL_FILE_BASE_NAME, MYF(0));
if (my_stat(first_translog_file, &st, MYF(0)))
my_delete(first_translog_file, MYF(0));
my_delete(CONTROL_FILE_BASE_NAME, MYF(0));
my_delete(first_translog_file, MYF(0));
bzero(long_tr_id, 6);
#ifndef DBUG_OFF
......@@ -139,12 +137,8 @@ int main(int argc __attribute__((unused)), char *argv[])
}
pagecache_file_init(file1, &dummy_callback, &dummy_callback,
&dummy_fail_callback, maria_flush_log_for_page, NULL);
if (chmod(file1_name, S_IRWXU | S_IRWXG | S_IRWXO) != 0)
{
fprintf(stderr, "Got error during file1 chmod() (errno: %d)\n",
errno);
if (my_chmod(file1_name, S_IRWXU | S_IRWXG | S_IRWXO, MYF(MY_WME)))
exit(1);
}
{
uchar page[PCACHE_PAGE];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment