~jan-kneschke/mysql-proxy/packet-tracking-assertions

« back to all changes in this revision

Viewing changes to src/network-mysqld-binlog.h

  • Committer: Kay Roepke
  • Author(s): Jan Kneschke
  • Date: 2008-01-23 22:00:28 UTC
  • Revision ID: kay@mysql.com-20080123220028-hq2xqb69apa75fnx
first round on mysql-shell based on the proxy code

this is mostly a verification if the proxy-code is flexible enough to handle 
all three scenarios of: client, server and forwarding (proxy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $%BEGINLICENSE%$
2
 
 Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
3
 
 
4
 
 This program is free software; you can redistribute it and/or
5
 
 modify it under the terms of the GNU General Public License as
6
 
 published by the Free Software Foundation; version 2 of the
7
 
 License.
8
 
 
9
 
 This program is distributed in the hope that it will be useful,
10
 
 but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
 
 GNU General Public License for more details.
13
 
 
14
 
 You should have received a copy of the GNU General Public License
15
 
 along with this program; if not, write to the Free Software
16
 
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17
 
 02110-1301  USA
18
 
 
19
 
 $%ENDLICENSE%$ */
20
 
 
21
 
 
22
 
#ifndef _NETWORK_MYSQLD_BINLOG_H_
23
 
#define _NETWORK_MYSQLD_BINLOG_H_
24
 
 
25
 
#include "network-mysqld-proto.h"
26
 
 
27
 
/**
28
 
 * stolen from sql/log_event.h
29
 
 *
30
 
 * (MySQL 5.1.24)
31
 
 */
32
 
#define ST_SERVER_VER_LEN 50
33
 
 
34
 
enum Log_event_type
35
 
{
36
 
  /*
37
 
    Every time you update this enum (when you add a type), you have to
38
 
    fix Format_description_log_event::Format_description_log_event().
39
 
  */
40
 
  UNKNOWN_EVENT= 0,
41
 
  START_EVENT_V3= 1,
42
 
  QUERY_EVENT= 2,
43
 
  STOP_EVENT= 3,
44
 
  ROTATE_EVENT= 4,
45
 
  INTVAR_EVENT= 5,
46
 
  LOAD_EVENT= 6,
47
 
  SLAVE_EVENT= 7,
48
 
  CREATE_FILE_EVENT= 8,
49
 
  APPEND_BLOCK_EVENT= 9,
50
 
  EXEC_LOAD_EVENT= 10,
51
 
  DELETE_FILE_EVENT= 11,
52
 
  /*
53
 
    NEW_LOAD_EVENT is like LOAD_EVENT except that it has a longer
54
 
    sql_ex, allowing multibyte TERMINATED BY etc; both types share the
55
 
    same class (Load_log_event)
56
 
  */
57
 
  NEW_LOAD_EVENT= 12,
58
 
  RAND_EVENT= 13,
59
 
  USER_VAR_EVENT= 14,
60
 
  FORMAT_DESCRIPTION_EVENT= 15,
61
 
  XID_EVENT= 16,
62
 
  BEGIN_LOAD_QUERY_EVENT= 17,
63
 
  EXECUTE_LOAD_QUERY_EVENT= 18,
64
 
  TABLE_MAP_EVENT = 19,
65
 
 
66
 
  /*
67
 
    These event numbers were used for 5.1.0 to 5.1.15 and are
68
 
    therefore obsolete.
69
 
   */
70
 
  PRE_GA_WRITE_ROWS_EVENT = 20,
71
 
  PRE_GA_UPDATE_ROWS_EVENT = 21,
72
 
  PRE_GA_DELETE_ROWS_EVENT = 22,
73
 
 
74
 
  /*
75
 
    These event numbers are used from 5.1.16 and forward
76
 
   */
77
 
  WRITE_ROWS_EVENT = 23,
78
 
  UPDATE_ROWS_EVENT = 24,
79
 
  DELETE_ROWS_EVENT = 25,
80
 
 
81
 
  /*
82
 
    Something out of the ordinary happened on the master
83
 
   */
84
 
  INCIDENT_EVENT= 26,
85
 
 
86
 
 
87
 
  /*
88
 
    Add new events here - right above this comment!
89
 
    Existing events (except ENUM_END_EVENT) should never change their numbers
90
 
  */
91
 
 
92
 
  ENUM_END_EVENT /* end marker */
93
 
};
94
 
 
95
 
 
96
 
 
97
 
/**
98
 
 * replication
99
 
 */
100
 
 
101
 
typedef struct {
102
 
        guint64 table_id;
103
 
 
104
 
        GString *db_name;
105
 
        GString *table_name;
106
 
 
107
 
        GPtrArray *fields;
108
 
} network_mysqld_table;
109
 
 
110
 
NETWORK_API network_mysqld_table *network_mysqld_table_new();
111
 
NETWORK_API void network_mysqld_table_free(network_mysqld_table *tbl);
112
 
NETWORK_API guint64 *guint64_new(guint64 i);
113
 
 
114
 
typedef struct {
115
 
        gchar *filename;
116
 
 
117
 
        /* we have to store some information from the format description event 
118
 
         */
119
 
        guint header_len;
120
 
 
121
 
        /* ... and the table-ids */
122
 
        GHashTable *rbr_tables; /* hashed by table-id -> network_mysqld_table */
123
 
} network_mysqld_binlog;
124
 
 
125
 
NETWORK_API network_mysqld_binlog *network_mysqld_binlog_new();
126
 
NETWORK_API void network_mysqld_binlog_free(network_mysqld_binlog *binlog);
127
 
 
128
 
typedef struct {
129
 
        guint32 timestamp;
130
 
        enum Log_event_type event_type;
131
 
        guint32 server_id;
132
 
        guint32 event_size;
133
 
        guint32 log_pos;
134
 
        guint16 flags;
135
 
 
136
 
        union {
137
 
                struct {
138
 
                        guint32 thread_id;
139
 
                        guint32 exec_time;
140
 
                        guint8  db_name_len;
141
 
                        guint16 error_code;
142
 
 
143
 
                        gchar *db_name;
144
 
                        gchar *query;
145
 
                } query_event;
146
 
                struct {
147
 
                        gchar *binlog_file;
148
 
                        guint32 binlog_pos;
149
 
                } rotate_event;
150
 
                struct {
151
 
                        guint16 binlog_version;
152
 
                        gchar *master_version;
153
 
                        guint32 created_ts;
154
 
                        guint8  log_header_len;
155
 
                        gchar *perm_events;
156
 
                        gsize  perm_events_len;
157
 
                } format_event;
158
 
                struct {
159
 
                        guint32 name_len;
160
 
                        gchar *name;
161
 
 
162
 
                        guint8 is_null;
163
 
                        guint8 type;
164
 
                        guint32 charset; /* charset of the string */
165
 
 
166
 
                        guint32 value_len; 
167
 
                        gchar *value; /* encoded in binary speak, depends on .type */
168
 
                } user_var_event;
169
 
                struct {
170
 
                        guint64 table_id;
171
 
                        guint16 flags;
172
 
 
173
 
                        guint8 db_name_len;
174
 
                        gchar *db_name;
175
 
                        guint8 table_name_len;
176
 
                        gchar *table_name;
177
 
 
178
 
                        guint64 columns_len;
179
 
                        gchar *columns;
180
 
 
181
 
                        guint64 metadata_len;
182
 
                        gchar *metadata;
183
 
 
184
 
                        guint32 null_bits_len;
185
 
                        gchar *null_bits;
186
 
                } table_map_event;
187
 
 
188
 
                struct {
189
 
                        guint64 table_id;
190
 
                        guint16 flags;
191
 
                        
192
 
                        guint64 columns_len;
193
 
 
194
 
                        guint32 used_columns_len;
195
 
                        gchar *used_columns;
196
 
 
197
 
                        guint32 null_bits_len;
198
 
                        
199
 
                        guint32 row_len;
200
 
                        gchar *row;      /* raw row-buffer in the format:
201
 
                                            [null-bits] [field_0, ...]
202
 
                                            [null-bits] [field_0, ...]
203
 
                                            */
204
 
                } row_event;
205
 
 
206
 
                struct {
207
 
                        guint8  type;
208
 
                        guint64 value;
209
 
                } intvar;
210
 
 
211
 
                struct {
212
 
                        guint64 xid_id;
213
 
                } xid;
214
 
        } event;
215
 
} network_mysqld_binlog_event;
216
 
 
217
 
NETWORK_API network_mysqld_binlog_event *network_mysqld_binlog_event_new(void);
218
 
NETWORK_API void network_mysqld_binlog_event_free(network_mysqld_binlog_event *event);
219
 
NETWORK_API int network_mysqld_proto_get_binlog_event_header(network_packet *packet, network_mysqld_binlog_event *event);
220
 
NETWORK_API int network_mysqld_proto_get_binlog_event(network_packet *packet, 
221
 
                network_mysqld_binlog *binlog,
222
 
                network_mysqld_binlog_event *event);
223
 
NETWORK_API int network_mysqld_proto_get_binlog_status(network_packet *packet);
224
 
 
225
 
typedef struct {
226
 
        gchar *binlog_file;
227
 
        guint32 binlog_pos;
228
 
        guint16 flags;
229
 
        guint32 server_id;
230
 
} network_mysqld_binlog_dump;
231
 
 
232
 
NETWORK_API network_mysqld_binlog_dump *network_mysqld_binlog_dump_new();
233
 
NETWORK_API void network_mysqld_binlog_dump_free(network_mysqld_binlog_dump *dump);
234
 
NETWORK_API int network_mysqld_proto_append_binlog_dump(GString *packet, network_mysqld_binlog_dump *dump);
235
 
 
236
 
 
237
 
NETWORK_API int network_mysqld_binlog_event_tablemap_get(
238
 
                network_mysqld_binlog_event *event,
239
 
                network_mysqld_table *tbl);
240
 
 
241
 
#endif