~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-13 21:20:24 UTC
  • Revision ID: brian@tangent.org-20080713212024-o6263c1vha7yxdeu
More bool removal. More cow bell!

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