~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_log.c

  • Committer: Brian Aker
  • Date: 2008-07-06 15:03:34 UTC
  • Revision ID: brian@tangent.org-20080706150334-xv3xa202trvs0712
USE_RAID cleanup, along with ftbench tools.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000-2001, 2004 MySQL AB
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
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 */
 
15
 
 
16
/*
 
17
  Logging of MyISAM commands and records on logfile for debugging
 
18
  The log can be examined with help of the myisamlog command.
 
19
*/
 
20
 
 
21
#include "myisamdef.h"
 
22
#if defined(MSDOS) || defined(__WIN__)
 
23
#include <fcntl.h>
 
24
#ifndef __WIN__
 
25
#include <process.h>
 
26
#endif
 
27
#endif
 
28
#ifdef VMS
 
29
#include <processes.h>
 
30
#endif
 
31
 
 
32
#undef GETPID                                   /* For HPUX */
 
33
#define GETPID() (log_type == 1 ? (long) myisam_pid : (long) my_thread_dbug_id())
 
34
 
 
35
        /* Activate logging if flag is 1 and reset logging if flag is 0 */
 
36
 
 
37
static int log_type=0;
 
38
ulong myisam_pid=0;
 
39
 
 
40
int mi_log(int activate_log)
 
41
{
 
42
  int error=0;
 
43
  char buff[FN_REFLEN];
 
44
  DBUG_ENTER("mi_log");
 
45
 
 
46
  log_type=activate_log;
 
47
  if (activate_log)
 
48
  {
 
49
    if (!myisam_pid)
 
50
      myisam_pid=(ulong) getpid();
 
51
    if (myisam_log_file < 0)
 
52
    {
 
53
      if ((myisam_log_file = my_create(fn_format(buff,myisam_log_filename,
 
54
                                                "",".log",4),
 
55
                                      0,(O_RDWR | O_BINARY | O_APPEND),MYF(0)))
 
56
          < 0)
 
57
        DBUG_RETURN(my_errno);
 
58
    }
 
59
  }
 
60
  else if (myisam_log_file >= 0)
 
61
  {
 
62
    error=my_close(myisam_log_file,MYF(0)) ? my_errno : 0 ;
 
63
    myisam_log_file= -1;
 
64
  }
 
65
  DBUG_RETURN(error);
 
66
}
 
67
 
 
68
 
 
69
        /* Logging of records and commands on logfile */
 
70
        /* All logs starts with command(1) dfile(2) process(4) result(2) */
 
71
 
 
72
void _myisam_log(enum myisam_log_commands command, MI_INFO *info,
 
73
                 const uchar *buffert, uint length)
 
74
{
 
75
  uchar buff[11];
 
76
  int error,old_errno;
 
77
  ulong pid=(ulong) GETPID();
 
78
  old_errno=my_errno;
 
79
  bzero(buff,sizeof(buff));
 
80
  buff[0]=(char) command;
 
81
  mi_int2store(buff+1,info->dfile);
 
82
  mi_int4store(buff+3,pid);
 
83
  mi_int2store(buff+9,length);
 
84
 
 
85
  pthread_mutex_lock(&THR_LOCK_myisam);
 
86
  error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
 
87
  VOID(my_write(myisam_log_file,buff,sizeof(buff),MYF(0)));
 
88
  VOID(my_write(myisam_log_file,buffert,length,MYF(0)));
 
89
  if (!error)
 
90
    error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
 
91
  pthread_mutex_unlock(&THR_LOCK_myisam);
 
92
  my_errno=old_errno;
 
93
}
 
94
 
 
95
 
 
96
void _myisam_log_command(enum myisam_log_commands command, MI_INFO *info,
 
97
                         const uchar *buffert, uint length, int result)
 
98
{
 
99
  uchar buff[9];
 
100
  int error,old_errno;
 
101
  ulong pid=(ulong) GETPID();
 
102
 
 
103
  old_errno=my_errno;
 
104
  buff[0]=(char) command;
 
105
  mi_int2store(buff+1,info->dfile);
 
106
  mi_int4store(buff+3,pid);
 
107
  mi_int2store(buff+7,result);
 
108
  pthread_mutex_lock(&THR_LOCK_myisam);
 
109
  error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
 
110
  VOID(my_write(myisam_log_file,buff,sizeof(buff),MYF(0)));
 
111
  if (buffert)
 
112
    VOID(my_write(myisam_log_file,buffert,length,MYF(0)));
 
113
  if (!error)
 
114
    error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
 
115
  pthread_mutex_unlock(&THR_LOCK_myisam);
 
116
  my_errno=old_errno;
 
117
}
 
118
 
 
119
 
 
120
void _myisam_log_record(enum myisam_log_commands command, MI_INFO *info,
 
121
                        const uchar *record, my_off_t filepos, int result)
 
122
{
 
123
  uchar buff[21],*pos;
 
124
  int error,old_errno;
 
125
  uint length;
 
126
  ulong pid=(ulong) GETPID();
 
127
 
 
128
  old_errno=my_errno;
 
129
  if (!info->s->base.blobs)
 
130
    length=info->s->base.reclength;
 
131
  else
 
132
    length=info->s->base.reclength+ _my_calc_total_blob_length(info,record);
 
133
  buff[0]=(uchar) command;
 
134
  mi_int2store(buff+1,info->dfile);
 
135
  mi_int4store(buff+3,pid);
 
136
  mi_int2store(buff+7,result);
 
137
  mi_sizestore(buff+9,filepos);
 
138
  mi_int4store(buff+17,length);
 
139
  pthread_mutex_lock(&THR_LOCK_myisam);
 
140
  error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
 
141
  VOID(my_write(myisam_log_file, buff,sizeof(buff),MYF(0)));
 
142
  VOID(my_write(myisam_log_file, record,info->s->base.reclength,MYF(0)));
 
143
  if (info->s->base.blobs)
 
144
  {
 
145
    MI_BLOB *blob,*end;
 
146
 
 
147
    for (end=info->blobs+info->s->base.blobs, blob= info->blobs;
 
148
         blob != end ;
 
149
         blob++)
 
150
    {
 
151
      memcpy_fixed((uchar*) &pos, record+blob->offset+blob->pack_length,
 
152
                   sizeof(char*));
 
153
      VOID(my_write(myisam_log_file,pos,blob->length,MYF(0)));
 
154
    }
 
155
  }
 
156
  if (!error)
 
157
    error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
 
158
  pthread_mutex_unlock(&THR_LOCK_myisam);
 
159
  my_errno=old_errno;
 
160
}