~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/rpl_utility.h

  • 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
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
 
1
/* Copyright (C) 2006 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
19
15
 
20
16
#ifndef RPL_UTILITY_H
21
17
#define RPL_UTILITY_H
22
18
 
23
 
#include <drizzled/server_includes.h>
 
19
#ifndef __cplusplus
 
20
#error "Don't include this C++ header file from a non-C++ file!"
 
21
#endif
 
22
 
 
23
#include "mysql_priv.h"
24
24
 
25
25
class Relay_log_info;
26
26
 
58
58
    @param metadata_size Size of the field_metadata array
59
59
    @param null_bitmap The bitmap of fields that can be null
60
60
   */
61
 
  table_def(field_type *types, uint32_t size, unsigned char *field_metadata, 
62
 
      int metadata_size, unsigned char *null_bitmap)
 
61
  table_def(field_type *types, ulong size, uchar *field_metadata, 
 
62
      int metadata_size, uchar *null_bitmap)
63
63
    : m_size(size), m_type(0), m_field_metadata_size(metadata_size),
64
64
      m_field_metadata(0), m_null_bits(0), m_memory(NULL)
65
65
  {
66
 
    m_memory= (unsigned char *)my_multi_malloc(MYF(MY_WME),
 
66
    m_memory= (uchar *)my_multi_malloc(MYF(MY_WME),
67
67
                                       &m_type, size,
68
68
                                       &m_field_metadata,
69
 
                                       size * sizeof(uint16_t),
 
69
                                       size * sizeof(uint16),
70
70
                                       &m_null_bits, (size + 7) / 8,
71
71
                                       NULL);
72
72
 
73
 
    memset(m_field_metadata, 0, size * sizeof(uint16_t));
 
73
    bzero(m_field_metadata, size * sizeof(uint16));
74
74
 
75
75
    if (m_type)
76
76
      memcpy(m_type, types, size);
89
89
      for (unsigned int i= 0; i < m_size; i++)
90
90
      {
91
91
        switch (m_type[i]) {
92
 
        case DRIZZLE_TYPE_BLOB:
93
 
        case DRIZZLE_TYPE_DOUBLE:
 
92
        case MYSQL_TYPE_TINY_BLOB:
 
93
        case MYSQL_TYPE_BLOB:
 
94
        case MYSQL_TYPE_MEDIUM_BLOB:
 
95
        case MYSQL_TYPE_LONG_BLOB:
 
96
        case MYSQL_TYPE_DOUBLE:
 
97
        case MYSQL_TYPE_FLOAT:
94
98
        {
95
99
          /*
96
100
            These types store a single byte.
99
103
          index++;
100
104
          break;
101
105
        }
102
 
        case DRIZZLE_TYPE_ENUM:
 
106
        case MYSQL_TYPE_SET:
 
107
        case MYSQL_TYPE_ENUM:
 
108
        case MYSQL_TYPE_STRING:
103
109
        {
104
 
          uint16_t x= field_metadata[index++] << 8U; // real_type
 
110
          uint16 x= field_metadata[index++] << 8U; // real_type
105
111
          x+= field_metadata[index++];            // pack or field length
106
112
          m_field_metadata[i]= x;
107
113
          break;
108
114
        }
109
 
        case DRIZZLE_TYPE_VARCHAR:
 
115
        case MYSQL_TYPE_VARCHAR:
110
116
        {
111
117
          /*
112
118
            These types store two bytes.
116
122
          index= index + 2;
117
123
          break;
118
124
        }
119
 
        case DRIZZLE_TYPE_NEWDECIMAL:
 
125
        case MYSQL_TYPE_NEWDECIMAL:
120
126
        {
121
 
          uint16_t x= field_metadata[index++] << 8U; // precision
 
127
          uint16 x= field_metadata[index++] << 8U; // precision
122
128
          x+= field_metadata[index++];            // decimals
123
129
          m_field_metadata[i]= x;
124
130
          break;
134
140
  }
135
141
 
136
142
  ~table_def() {
137
 
    free(m_memory);
 
143
    my_free(m_memory, MYF(0));
 
144
#ifndef DBUG_OFF
138
145
    m_type= 0;
139
146
    m_size= 0;
 
147
#endif
140
148
  }
141
149
 
142
150
  /**
144
152
 
145
153
    @return The number of fields that there is type data for.
146
154
   */
147
 
  uint32_t size() const { return m_size; }
 
155
  ulong size() const { return m_size; }
148
156
 
149
157
 
150
158
  /*
156
164
    <code>index</code>. Currently, only the type identifier is
157
165
    returned.
158
166
   */
159
 
  field_type type(uint32_t index) const
 
167
  field_type type(ulong index) const
160
168
  {
161
 
    assert(index < m_size);
 
169
    DBUG_ASSERT(index < m_size);
162
170
    return m_type[index];
163
171
  }
164
172
 
175
183
    corresponding fields to properly extract the data from the binary log 
176
184
    in the event that the master's field is smaller than the slave.
177
185
  */
178
 
  uint16_t field_metadata(uint32_t index) const
 
186
  uint16 field_metadata(uint index) const
179
187
  {
180
 
    assert(index < m_size);
 
188
    DBUG_ASSERT(index < m_size);
181
189
    if (m_field_metadata_size)
182
190
      return m_field_metadata[index];
183
191
    else
188
196
    This function returns whether the field on the master can be null.
189
197
    This value is derived from field->maybe_null().
190
198
  */
191
 
  bool maybe_null(uint32_t index) const
 
199
  my_bool maybe_null(uint index) const
192
200
  {
193
 
    assert(index < m_size);
 
201
    DBUG_ASSERT(index < m_size);
194
202
    return ((m_null_bits[(index / 8)] & 
195
203
            (1 << (index % 8))) == (1 << (index %8)));
196
204
  }
202
210
    WL#3915) or needs to advance the pointer for the fields in the raw 
203
211
    data from the master to a specific column.
204
212
  */
205
 
  uint32_t calc_field_size(uint32_t col, unsigned char *master_data) const;
 
213
  uint32 calc_field_size(uint col, uchar *master_data) const;
206
214
 
207
215
  /**
208
216
    Decide if the table definition is compatible with a table.
221
229
    @retval 1  if the table definition is not compatible with @c table
222
230
    @retval 0  if the table definition is compatible with @c table
223
231
  */
224
 
  int compatible_with(Relay_log_info const *rli, Table *table) const;
 
232
  int compatible_with(Relay_log_info const *rli, TABLE *table) const;
225
233
 
226
234
private:
227
 
  uint32_t m_size;           // Number of elements in the types array
 
235
  ulong m_size;           // Number of elements in the types array
228
236
  field_type *m_type;                     // Array of type descriptors
229
 
  uint32_t m_field_metadata_size;
230
 
  uint16_t *m_field_metadata;
231
 
  unsigned char *m_null_bits;
232
 
  unsigned char *m_memory;
 
237
  uint m_field_metadata_size;
 
238
  uint16 *m_field_metadata;
 
239
  uchar *m_null_bits;
 
240
  uchar *m_memory;
233
241
};
234
242
 
235
243
/**
236
244
   Extend the normal table list with a few new fields needed by the
237
245
   slave thread, but nowhere else.
238
246
 */
239
 
struct RPL_TableList
240
 
  : public TableList
 
247
struct RPL_TABLE_LIST
 
248
  : public TABLE_LIST
241
249
{
242
250
  bool m_tabledef_valid;
243
251
  table_def m_tabledef;
266
274
    ~auto_afree_ptr() { if (m_ptr) my_afree(m_ptr); }
267
275
    void assign(Obj* ptr) {
268
276
      /* Only to be called if it hasn't been given a value before. */
269
 
      assert(m_ptr == NULL);
 
277
      DBUG_ASSERT(m_ptr == NULL);
270
278
      m_ptr= ptr;
271
279
    }
272
280
    Obj* get() { return m_ptr; }
274
282
 
275
283
}
276
284
 
 
285
/*
 
286
  One test in mysqldump.test has 330 columns!
 
287
  So have a sufficient buffer and check its limit anyway.
 
288
*/
 
289
#define DBUG_PRINT_BITSET(N,FRM,BS)                             \
 
290
  do {                                                          \
 
291
    char buf[MAX_FIELDS+1];                                     \
 
292
    uint i;                                                     \
 
293
    for (i = 0 ; i < (BS)->n_bits && i < MAX_FIELDS ; ++i)      \
 
294
      buf[i] = bitmap_is_set((BS), i) ? '1' : '0';              \
 
295
    buf[i] = '\0';                                              \
 
296
    DBUG_PRINT((N), ((FRM), buf));                              \
 
297
  } while (0)
 
298
 
277
299
#endif /* RPL_UTILITY_H */