~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_binlog.cc

  • Committer: Monty Taylor
  • Date: 2008-08-02 01:03:15 UTC
  • mto: (236.1.42 codestyle)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080802010315-65h5938pymg9d99z
Moved m4 macros to top-level m4 dir, per GNU standards (and where gettext wanted it :)

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
 
#include <drizzled/server_includes.h>
17
 
#include <drizzled/replication/rli.h>
18
 
#include <drizzled/replication/binlog.h>
 
16
#include "mysql_priv.h"
 
17
#include "rpl_rli.h"
19
18
#include <mysys/base64.h>
20
 
#include <drizzled/error.h>
21
 
#include <drizzled/slave.h>
22
 
#include <drizzled/session.h>
23
19
 
24
20
/**
25
21
  Execute a BINLOG statement
32
28
  rli->description_event_for_exec.
33
29
*/
34
30
 
35
 
void mysql_client_binlog_statement(Session* session)
 
31
void mysql_client_binlog_statement(THD* thd)
36
32
{
37
 
  size_t coded_len= session->lex->comment.length + 1;
 
33
  size_t coded_len= thd->lex->comment.length + 1;
38
34
  size_t decoded_len= base64_needed_decoded_length(coded_len);
39
35
  assert(coded_len > 0);
40
36
 
48
44
    Format_description_event.
49
45
  */
50
46
  bool have_fd_event= true;
51
 
  if (!session->rli_fake)
 
47
  if (!thd->rli_fake)
52
48
  {
53
 
    session->rli_fake= new Relay_log_info;
 
49
    thd->rli_fake= new Relay_log_info;
54
50
#ifdef HAVE_purify
55
 
    session->rli_fake->is_fake= true;
 
51
    thd->rli_fake->is_fake= true;
56
52
#endif
57
53
    have_fd_event= false;
58
54
  }
59
 
  if (session->rli_fake && !session->rli_fake->relay_log.description_event_for_exec)
 
55
  if (thd->rli_fake && !thd->rli_fake->relay_log.description_event_for_exec)
60
56
  {
61
 
    session->rli_fake->relay_log.description_event_for_exec=
 
57
    thd->rli_fake->relay_log.description_event_for_exec=
62
58
      new Format_description_log_event(4);
63
59
    have_fd_event= false;
64
60
  }
65
61
 
66
62
  const char *error= 0;
67
 
  char *buf= (char *) malloc(decoded_len);
 
63
  char *buf= (char *) my_malloc(decoded_len, MYF(MY_WME));
68
64
  Log_event *ev = 0;
69
65
 
70
66
  /*
71
67
    Out of memory check
72
68
  */
73
 
  if (!(session->rli_fake &&
74
 
        session->rli_fake->relay_log.description_event_for_exec &&
 
69
  if (!(thd->rli_fake &&
 
70
        thd->rli_fake->relay_log.description_event_for_exec &&
75
71
        buf))
76
72
  {
77
73
    my_error(ER_OUTOFMEMORY, MYF(0), 1);  /* needed 1 bytes */
78
74
    goto end;
79
75
  }
80
76
 
81
 
  session->rli_fake->sql_session= session;
82
 
  session->rli_fake->no_storage= true;
 
77
  thd->rli_fake->sql_thd= thd;
 
78
  thd->rli_fake->no_storage= true;
83
79
 
84
 
  for (char const *strptr= session->lex->comment.str ;
85
 
       strptr < session->lex->comment.str + session->lex->comment.length ; )
 
80
  for (char const *strptr= thd->lex->comment.str ;
 
81
       strptr < thd->lex->comment.str + thd->lex->comment.length ; )
86
82
  {
87
83
    char const *endptr= 0;
88
84
    int bytes_decoded= base64_decode(strptr, coded_len, buf, &endptr);
120
116
      /*
121
117
        Checking that the first event in the buffer is not truncated.
122
118
      */
123
 
      uint32_t event_len= uint4korr(bufptr + EVENT_LEN_OFFSET);
 
119
      ulong event_len= uint4korr(bufptr + EVENT_LEN_OFFSET);
124
120
      if (bytes_decoded < EVENT_LEN_OFFSET || (uint) bytes_decoded < event_len)
125
121
      {
126
122
        my_error(ER_SYNTAX_ERROR, MYF(0));
146
142
      }
147
143
 
148
144
      ev= Log_event::read_log_event(bufptr, event_len, &error,
149
 
                                    session->rli_fake->relay_log.
 
145
                                    thd->rli_fake->relay_log.
150
146
                                      description_event_for_exec);
151
147
 
152
148
      if (!ev)
162
158
      bytes_decoded -= event_len;
163
159
      bufptr += event_len;
164
160
 
165
 
      ev->session= session;
 
161
      ev->thd= thd;
166
162
      /*
167
163
        We go directly to the application phase, since we don't need
168
164
        to check if the event shall be skipped or not.
171
167
        not used at all: the rli_fake instance is used only for error
172
168
        reporting.
173
169
      */
174
 
      if (apply_event_and_update_pos(ev, session, session->rli_fake, false))
 
170
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
 
171
      if (apply_event_and_update_pos(ev, thd, thd->rli_fake, false))
175
172
      {
176
173
        /*
177
174
          TODO: Maybe a better error message since the BINLOG statement
180
177
        my_error(ER_UNKNOWN_ERROR, MYF(0), "Error executing BINLOG statement");
181
178
        goto end;
182
179
      }
 
180
#endif
183
181
 
184
182
      /*
185
183
        Format_description_log_event should not be deleted because it
193
191
    }
194
192
  }
195
193
 
196
 
  my_ok(session);
 
194
  my_ok(thd);
197
195
 
198
196
end:
199
 
  session->rli_fake->clear_tables_to_lock();
200
 
  free(buf);
 
197
  thd->rli_fake->clear_tables_to_lock();
 
198
  my_free(buf, MYF(MY_ALLOW_ZERO_PTR));
201
199
  return;
202
200
}