1
/* Copyright (C) 2000-2001, 2004 MySQL AB
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.
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.
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 */
17
Logging of MyISAM commands and records on logfile for debugging
18
The log can be examined with help of the myisamlog command.
21
#include "myisamdef.h"
22
#if defined(MSDOS) || defined(__WIN__)
29
#include <processes.h>
32
#undef GETPID /* For HPUX */
34
#define GETPID() (log_type == 1 ? (long) myisam_pid : (long) my_thread_dbug_id())
36
#define GETPID() myisam_pid
39
/* Activate logging if flag is 1 and reset logging if flag is 0 */
41
static int log_type=0;
44
int mi_log(int activate_log)
50
log_type=activate_log;
54
myisam_pid=(ulong) getpid();
55
if (myisam_log_file < 0)
57
if ((myisam_log_file = my_create(fn_format(buff,myisam_log_filename,
59
0,(O_RDWR | O_BINARY | O_APPEND),MYF(0)))
61
DBUG_RETURN(my_errno);
64
else if (myisam_log_file >= 0)
66
error=my_close(myisam_log_file,MYF(0)) ? my_errno : 0 ;
73
/* Logging of records and commands on logfile */
74
/* All logs starts with command(1) dfile(2) process(4) result(2) */
76
void _myisam_log(enum myisam_log_commands command, MI_INFO *info,
77
const uchar *buffert, uint length)
81
ulong pid=(ulong) GETPID();
83
bzero(buff,sizeof(buff));
84
buff[0]=(char) command;
85
mi_int2store(buff+1,info->dfile);
86
mi_int4store(buff+3,pid);
87
mi_int2store(buff+9,length);
89
pthread_mutex_lock(&THR_LOCK_myisam);
90
error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
91
VOID(my_write(myisam_log_file,buff,sizeof(buff),MYF(0)));
92
VOID(my_write(myisam_log_file,buffert,length,MYF(0)));
94
error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
95
pthread_mutex_unlock(&THR_LOCK_myisam);
100
void _myisam_log_command(enum myisam_log_commands command, MI_INFO *info,
101
const uchar *buffert, uint length, int result)
105
ulong pid=(ulong) GETPID();
108
buff[0]=(char) command;
109
mi_int2store(buff+1,info->dfile);
110
mi_int4store(buff+3,pid);
111
mi_int2store(buff+7,result);
112
pthread_mutex_lock(&THR_LOCK_myisam);
113
error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
114
VOID(my_write(myisam_log_file,buff,sizeof(buff),MYF(0)));
116
VOID(my_write(myisam_log_file,buffert,length,MYF(0)));
118
error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
119
pthread_mutex_unlock(&THR_LOCK_myisam);
124
void _myisam_log_record(enum myisam_log_commands command, MI_INFO *info,
125
const uchar *record, my_off_t filepos, int result)
130
ulong pid=(ulong) GETPID();
133
if (!info->s->base.blobs)
134
length=info->s->base.reclength;
136
length=info->s->base.reclength+ _my_calc_total_blob_length(info,record);
137
buff[0]=(uchar) command;
138
mi_int2store(buff+1,info->dfile);
139
mi_int4store(buff+3,pid);
140
mi_int2store(buff+7,result);
141
mi_sizestore(buff+9,filepos);
142
mi_int4store(buff+17,length);
143
pthread_mutex_lock(&THR_LOCK_myisam);
144
error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
145
VOID(my_write(myisam_log_file, buff,sizeof(buff),MYF(0)));
146
VOID(my_write(myisam_log_file, record,info->s->base.reclength,MYF(0)));
147
if (info->s->base.blobs)
151
for (end=info->blobs+info->s->base.blobs, blob= info->blobs;
155
memcpy_fixed((uchar*) &pos, record+blob->offset+blob->pack_length,
157
VOID(my_write(myisam_log_file,pos,blob->length,MYF(0)));
161
error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
162
pthread_mutex_unlock(&THR_LOCK_myisam);