1
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or
6
(at your option) any later version.
8
This program is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License
14
along with this program; if not, write to the Free Software
15
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
/* Logging of isamcommands and records on logfile */
19
#include "myisamdef.h"
20
#if defined(MSDOS) || defined(__WIN__)
28
#include <processes.h>
31
#undef GETPID /* For HPUX */
33
#define GETPID() (log_type == 1 ? getpid() : (long) my_thread_id());
35
#define GETPID() getpid()
38
/* Activate logging if flag is 1 and reset logging if flag is 0 */
40
static int log_type=0;
42
int mi_log(int activate_log)
48
log_type=activate_log;
51
if (myisam_log_file < 0)
53
if ((myisam_log_file = my_create(fn_format(buff,myisam_log_filename,
55
0,(O_RDWR | O_BINARY | O_APPEND),MYF(0)))
57
DBUG_RETURN(my_errno);
60
else if (myisam_log_file >= 0)
62
error=my_close(myisam_log_file,MYF(0)) ? my_errno : 0 ;
69
/* Logging of records and commands on logfile */
70
/* All logs starts with command(1) dfile(2) process(4) result(2) */
72
void _myisam_log(enum myisam_log_commands command, MI_INFO *info, const byte *buffert, uint length)
76
ulong pid=(ulong) GETPID();
78
bzero(buff,sizeof(buff));
79
buff[0]=(char) command;
80
mi_int2store(buff+1,info->dfile);
81
mi_int4store(buff+3,pid);
82
mi_int2store(buff+9,length);
84
pthread_mutex_lock(&THR_LOCK_myisam);
85
error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
86
VOID(my_write(myisam_log_file,buff,sizeof(buff),MYF(0)));
87
VOID(my_write(myisam_log_file,buffert,length,MYF(0)));
89
error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
90
pthread_mutex_unlock(&THR_LOCK_myisam);
95
void _myisam_log_command(enum myisam_log_commands command, MI_INFO *info,
96
const byte *buffert, uint length, int result)
100
ulong pid=(ulong) GETPID();
103
buff[0]=(char) command;
104
mi_int2store(buff+1,info->dfile);
105
mi_int4store(buff+3,pid);
106
mi_int2store(buff+7,result);
107
pthread_mutex_lock(&THR_LOCK_myisam);
108
error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
109
VOID(my_write(myisam_log_file,buff,sizeof(buff),MYF(0)));
111
VOID(my_write(myisam_log_file,buffert,length,MYF(0)));
113
error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
114
pthread_mutex_unlock(&THR_LOCK_myisam);
119
void _myisam_log_record(enum myisam_log_commands command, MI_INFO *info,
120
const byte *record, my_off_t filepos, int result)
125
ulong pid=(ulong) GETPID();
128
if (!info->s->base.blobs)
129
length=info->s->base.reclength;
131
length=info->s->base.reclength+ _my_calc_total_blob_length(info,record);
132
buff[0]=(char) command;
133
mi_int2store(buff+1,info->dfile);
134
mi_int4store(buff+3,pid);
135
mi_int2store(buff+7,result);
136
mi_sizestore(buff+9,filepos);
137
mi_int4store(buff+17,length);
138
pthread_mutex_lock(&THR_LOCK_myisam);
139
error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
140
VOID(my_write(myisam_log_file,buff,sizeof(buff),MYF(0)));
141
VOID(my_write(myisam_log_file,(byte*) record,info->s->base.reclength,MYF(0)));
142
if (info->s->base.blobs)
146
for (end=info->blobs+info->s->base.blobs, blob= info->blobs;
150
memcpy_fixed(&pos,record+blob->offset+blob->pack_length,sizeof(char*));
151
VOID(my_write(myisam_log_file,pos,blob->length,MYF(0)));
155
error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
156
pthread_mutex_unlock(&THR_LOCK_myisam);