~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/rpl_utility.h

Removed dead variable, sorted authors file.

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>
24
 
#include <drizzled/table_list.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"
25
24
 
26
25
class Relay_log_info;
27
26
 
59
58
    @param metadata_size Size of the field_metadata array
60
59
    @param null_bitmap The bitmap of fields that can be null
61
60
   */
62
 
  table_def(field_type *types, uint32_t size, unsigned char *field_metadata,
 
61
  table_def(field_type *types, uint32_t size, unsigned char *field_metadata, 
63
62
      int metadata_size, unsigned char *null_bitmap)
64
63
    : m_size(size), m_type(0), m_field_metadata_size(metadata_size),
65
64
      m_field_metadata(0), m_null_bits(0), m_memory(NULL)
71
70
                                       &m_null_bits, (size + 7) / 8,
72
71
                                       NULL);
73
72
 
74
 
    memset(m_field_metadata, 0, size * sizeof(uint16_t));
 
73
    bzero(m_field_metadata, size * sizeof(uint16_t));
75
74
 
76
75
    if (m_type)
77
76
      memcpy(m_type, types, size);
81
80
      Extract the data from the table map into the field metadata array
82
81
      iff there is field metadata. The variable metadata_size will be
83
82
      0 if we are replicating from an older version server since no field
84
 
      metadata was written to the table map. This can also happen if
 
83
      metadata was written to the table map. This can also happen if 
85
84
      there were no fields in the master that needed extra metadata.
86
85
    */
87
86
    if (m_size && metadata_size)
88
 
    {
 
87
    { 
89
88
      int index= 0;
90
89
      for (unsigned int i= 0; i < m_size; i++)
91
90
      {
92
91
        switch (m_type[i]) {
93
 
        case DRIZZLE_TYPE_BLOB:
94
 
        case DRIZZLE_TYPE_DOUBLE:
 
92
        case MYSQL_TYPE_BLOB:
 
93
        case MYSQL_TYPE_DOUBLE:
95
94
        {
96
95
          /*
97
96
            These types store a single byte.
100
99
          index++;
101
100
          break;
102
101
        }
103
 
        case DRIZZLE_TYPE_ENUM:
 
102
        case MYSQL_TYPE_SET:
 
103
        case MYSQL_TYPE_ENUM:
 
104
        case MYSQL_TYPE_STRING:
104
105
        {
105
106
          uint16_t x= field_metadata[index++] << 8U; // real_type
106
107
          x+= field_metadata[index++];            // pack or field length
107
108
          m_field_metadata[i]= x;
108
109
          break;
109
110
        }
110
 
        case DRIZZLE_TYPE_VARCHAR:
 
111
        case MYSQL_TYPE_VARCHAR:
111
112
        {
112
113
          /*
113
114
            These types store two bytes.
117
118
          index= index + 2;
118
119
          break;
119
120
        }
120
 
        case DRIZZLE_TYPE_NEWDECIMAL:
 
121
        case MYSQL_TYPE_NEWDECIMAL:
121
122
        {
122
123
          uint16_t x= field_metadata[index++] << 8U; // precision
123
124
          x+= field_metadata[index++];            // decimals
135
136
  }
136
137
 
137
138
  ~table_def() {
138
 
    free(m_memory);
 
139
    my_free(m_memory, MYF(0));
139
140
    m_type= 0;
140
141
    m_size= 0;
141
142
  }
169
170
    table map for a given field. If there is no metadata for that field
170
171
    or there is no extra metadata at all, the function returns 0.
171
172
 
172
 
    The function returns the value for the field metadata for column at
173
 
    position indicated by index. As mentioned, if the field was a type
174
 
    that stores field metadata, that value is returned else zero (0) is
175
 
    returned. This method is used in the unpack() methods of the
176
 
    corresponding fields to properly extract the data from the binary log
 
173
    The function returns the value for the field metadata for column at 
 
174
    position indicated by index. As mentioned, if the field was a type 
 
175
    that stores field metadata, that value is returned else zero (0) is 
 
176
    returned. This method is used in the unpack() methods of the 
 
177
    corresponding fields to properly extract the data from the binary log 
177
178
    in the event that the master's field is smaller than the slave.
178
179
  */
179
180
  uint16_t field_metadata(uint32_t index) const
189
190
    This function returns whether the field on the master can be null.
190
191
    This value is derived from field->maybe_null().
191
192
  */
192
 
  bool maybe_null(uint32_t index) const
 
193
  my_bool maybe_null(uint32_t index) const
193
194
  {
194
195
    assert(index < m_size);
195
 
    return ((m_null_bits[(index / 8)] &
 
196
    return ((m_null_bits[(index / 8)] & 
196
197
            (1 << (index % 8))) == (1 << (index %8)));
197
198
  }
198
199
 
199
200
  /*
200
201
    This function returns the field size in raw bytes based on the type
201
 
    and the encoded field data from the master's raw data. This method can
202
 
    be used for situations where the slave needs to skip a column (e.g.,
203
 
    WL#3915) or needs to advance the pointer for the fields in the raw
 
202
    and the encoded field data from the master's raw data. This method can 
 
203
    be used for situations where the slave needs to skip a column (e.g., 
 
204
    WL#3915) or needs to advance the pointer for the fields in the raw 
204
205
    data from the master to a specific column.
205
206
  */
206
 
  uint32_t calc_field_size(uint32_t col, unsigned char *master_data) const;
 
207
  uint32 calc_field_size(uint32_t col, unsigned char *master_data) const;
207
208
 
208
209
  /**
209
210
    Decide if the table definition is compatible with a table.
222
223
    @retval 1  if the table definition is not compatible with @c table
223
224
    @retval 0  if the table definition is compatible with @c table
224
225
  */
225
 
  int compatible_with(Relay_log_info const *rli, Table *table) const;
 
226
  int compatible_with(Relay_log_info const *rli, TABLE *table) const;
226
227
 
227
228
private:
228
229
  uint32_t m_size;           // Number of elements in the types array
237
238
   Extend the normal table list with a few new fields needed by the
238
239
   slave thread, but nowhere else.
239
240
 */
240
 
struct RPL_TableList
241
 
  : public TableList
 
241
struct RPL_TABLE_LIST
 
242
  : public TABLE_LIST
242
243
{
243
244
  bool m_tabledef_valid;
244
245
  table_def m_tabledef;
245
246
};
246
247
 
 
248
 
 
249
/* Anonymous namespace for template functions/classes */
 
250
namespace {
 
251
 
 
252
  /*
 
253
    Smart pointer that will automatically call my_afree (a macro) when
 
254
    the pointer goes out of scope.  This is used so that I do not have
 
255
    to remember to call my_afree() before each return.  There is no
 
256
    overhead associated with this, since all functions are inline.
 
257
 
 
258
    I (Matz) would prefer to use the free function as a template
 
259
    parameter, but that is not possible when the "function" is a
 
260
    macro.
 
261
  */
 
262
  template <class Obj>
 
263
  class auto_afree_ptr
 
264
  {
 
265
    Obj* m_ptr;
 
266
  public:
 
267
    auto_afree_ptr(Obj* ptr) : m_ptr(ptr) { }
 
268
    ~auto_afree_ptr() { if (m_ptr) my_afree(m_ptr); }
 
269
    void assign(Obj* ptr) {
 
270
      /* Only to be called if it hasn't been given a value before. */
 
271
      assert(m_ptr == NULL);
 
272
      m_ptr= ptr;
 
273
    }
 
274
    Obj* get() { return m_ptr; }
 
275
  };
 
276
 
 
277
}
 
278
 
247
279
#endif /* RPL_UTILITY_H */