~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/replication/utility.h

  • Committer: Mark Atwood
  • Date: 2009-01-05 04:37:22 UTC
  • mto: (758.1.1 devel)
  • mto: This revision was merged to the branch mainline in revision 759.
  • Revision ID: me@mark.atwood.name-20090105043722-03l4mzcxi4yjjjih
replace sql_print_error etc with errmsg_print

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#ifndef RPL_UTILITY_H
21
21
#define RPL_UTILITY_H
22
22
 
23
 
#ifndef __cplusplus
24
 
#error "Don't include this C++ header file from a non-C++ file!"
25
 
#endif
26
 
 
27
23
#include <drizzled/server_includes.h>
 
24
#include <drizzled/table_list.h>
28
25
 
29
26
class Relay_log_info;
30
27
 
62
59
    @param metadata_size Size of the field_metadata array
63
60
    @param null_bitmap The bitmap of fields that can be null
64
61
   */
65
 
  table_def(field_type *types, uint32_t size, unsigned char *field_metadata, 
 
62
  table_def(field_type *types, uint32_t size, unsigned char *field_metadata,
66
63
      int metadata_size, unsigned char *null_bitmap)
67
64
    : m_size(size), m_type(0), m_field_metadata_size(metadata_size),
68
65
      m_field_metadata(0), m_null_bits(0), m_memory(NULL)
84
81
      Extract the data from the table map into the field metadata array
85
82
      iff there is field metadata. The variable metadata_size will be
86
83
      0 if we are replicating from an older version server since no field
87
 
      metadata was written to the table map. This can also happen if 
 
84
      metadata was written to the table map. This can also happen if
88
85
      there were no fields in the master that needed extra metadata.
89
86
    */
90
87
    if (m_size && metadata_size)
91
 
    { 
 
88
    {
92
89
      int index= 0;
93
90
      for (unsigned int i= 0; i < m_size; i++)
94
91
      {
172
169
    table map for a given field. If there is no metadata for that field
173
170
    or there is no extra metadata at all, the function returns 0.
174
171
 
175
 
    The function returns the value for the field metadata for column at 
176
 
    position indicated by index. As mentioned, if the field was a type 
177
 
    that stores field metadata, that value is returned else zero (0) is 
178
 
    returned. This method is used in the unpack() methods of the 
179
 
    corresponding fields to properly extract the data from the binary log 
 
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
180
177
    in the event that the master's field is smaller than the slave.
181
178
  */
182
179
  uint16_t field_metadata(uint32_t index) const
195
192
  bool maybe_null(uint32_t index) const
196
193
  {
197
194
    assert(index < m_size);
198
 
    return ((m_null_bits[(index / 8)] & 
 
195
    return ((m_null_bits[(index / 8)] &
199
196
            (1 << (index % 8))) == (1 << (index %8)));
200
197
  }
201
198
 
202
199
  /*
203
200
    This function returns the field size in raw bytes based on the type
204
 
    and the encoded field data from the master's raw data. This method can 
205
 
    be used for situations where the slave needs to skip a column (e.g., 
206
 
    WL#3915) or needs to advance the pointer for the fields in the raw 
 
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
207
204
    data from the master to a specific column.
208
205
  */
209
206
  uint32_t calc_field_size(uint32_t col, unsigned char *master_data) const;
247
244
  table_def m_tabledef;
248
245
};
249
246
 
250
 
 
251
 
/* Anonymous namespace for template functions/classes */
252
 
namespace {
253
 
 
254
 
  /*
255
 
    Smart pointer that will automatically call my_afree (a macro) when
256
 
    the pointer goes out of scope.  This is used so that I do not have
257
 
    to remember to call my_afree() before each return.  There is no
258
 
    overhead associated with this, since all functions are inline.
259
 
 
260
 
    I (Matz) would prefer to use the free function as a template
261
 
    parameter, but that is not possible when the "function" is a
262
 
    macro.
263
 
  */
264
 
  template <class Obj>
265
 
  class auto_afree_ptr
266
 
  {
267
 
    Obj* m_ptr;
268
 
  public:
269
 
    auto_afree_ptr(Obj* ptr) : m_ptr(ptr) { }
270
 
    ~auto_afree_ptr() { if (m_ptr) my_afree(m_ptr); }
271
 
    void assign(Obj* ptr) {
272
 
      /* Only to be called if it hasn't been given a value before. */
273
 
      assert(m_ptr == NULL);
274
 
      m_ptr= ptr;
275
 
    }
276
 
    Obj* get() { return m_ptr; }
277
 
  };
278
 
 
279
 
}
280
 
 
281
247
#endif /* RPL_UTILITY_H */