~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/rpl_utility.cc

  • Committer: Brian Aker
  • Date: 2009-12-29 01:38:38 UTC
  • mfrom: (1251.1.1 drizzle)
  • Revision ID: brian@gaz-20091229013838-03kb2z5xbqw03ddt
Merge of Diego fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 */
15
 
 
16
 
#include <drizzled/server_includes.h>
17
 
#include "rpl_utility.h"
18
 
#include "rpl_rli.h"
19
 
#include <drizzled/drizzled_error_messages.h>
20
 
 
21
 
/*********************************************************************
22
 
 *                   table_def member definitions                    *
23
 
 *********************************************************************/
24
 
 
25
 
/*
26
 
  This function returns the field size in raw bytes based on the type
27
 
  and the encoded field data from the master's raw data.
28
 
*/
29
 
uint32_t table_def::calc_field_size(uint col, uchar *master_data) const
30
 
{
31
 
  uint32_t length= 0;
32
 
 
33
 
  switch (type(col)) {
34
 
  case DRIZZLE_TYPE_NEWDECIMAL:
35
 
    length= my_decimal_get_binary_size(m_field_metadata[col] >> 8, 
36
 
                                       m_field_metadata[col] & 0xff);
37
 
    break;
38
 
  case DRIZZLE_TYPE_DOUBLE:
39
 
    length= m_field_metadata[col];
40
 
    break;
41
 
  /*
42
 
    The cases for SET and ENUM are include for completeness, however
43
 
    both are mapped to type DRIZZLE_TYPE_STRING and their real types
44
 
    are encoded in the field metadata.
45
 
  */
46
 
  case DRIZZLE_TYPE_ENUM:
47
 
  {
48
 
    length= m_field_metadata[col] & 0x00ff;
49
 
    break;
50
 
  }
51
 
  case DRIZZLE_TYPE_TINY:
52
 
    length= 1;
53
 
    break;
54
 
  case DRIZZLE_TYPE_SHORT:
55
 
    length= 2;
56
 
    break;
57
 
  case DRIZZLE_TYPE_LONG:
58
 
    length= 4;
59
 
    break;
60
 
  case DRIZZLE_TYPE_LONGLONG:
61
 
    length= 8;
62
 
    break;
63
 
  case DRIZZLE_TYPE_NULL:
64
 
    length= 0;
65
 
    break;
66
 
  case DRIZZLE_TYPE_NEWDATE:
67
 
    length= 3;
68
 
    break;
69
 
  case DRIZZLE_TYPE_TIME:
70
 
    length= 3;
71
 
    break;
72
 
  case DRIZZLE_TYPE_TIMESTAMP:
73
 
    length= 4;
74
 
    break;
75
 
  case DRIZZLE_TYPE_DATETIME:
76
 
    length= 8;
77
 
    break;
78
 
  case DRIZZLE_TYPE_VARCHAR:
79
 
  {
80
 
    length= m_field_metadata[col] > 255 ? 2 : 1; // c&p of Field_varstring::data_length()
81
 
    assert(uint2korr(master_data) > 0);
82
 
    length+= length == 1 ? (uint32_t) *master_data : uint2korr(master_data);
83
 
    break;
84
 
  }
85
 
  case DRIZZLE_TYPE_BLOB:
86
 
  {
87
 
    length= uint4korr(master_data);
88
 
    length+= m_field_metadata[col];
89
 
    break;
90
 
  }
91
 
  default:
92
 
    length= ~(uint32_t) 0;
93
 
  }
94
 
  return length;
95
 
}
96
 
 
97
 
/*
98
 
  Is the definition compatible with a table?
99
 
 
100
 
*/
101
 
int
102
 
table_def::compatible_with(Relay_log_info const *rli_arg, TABLE *table)
103
 
  const
104
 
{
105
 
  /*
106
 
    We only check the initial columns for the tables.
107
 
  */
108
 
  uint const cols_to_check= min(table->s->fields, size());
109
 
  int error= 0;
110
 
  Relay_log_info const *rli= const_cast<Relay_log_info*>(rli_arg);
111
 
 
112
 
  TABLE_SHARE const *const tsh= table->s;
113
 
 
114
 
  for (uint col= 0 ; col < cols_to_check ; ++col)
115
 
  {
116
 
    if (table->field[col]->type() != type(col))
117
 
    {
118
 
      assert(col < size() && col < tsh->fields);
119
 
      assert(tsh->db.str && tsh->table_name.str);
120
 
      error= 1;
121
 
      char buf[256];
122
 
      snprintf(buf, sizeof(buf), _("Column %d type mismatch - "
123
 
                "received type %d, %s.%s has type %d"),
124
 
                col, type(col), tsh->db.str, tsh->table_name.str,
125
 
                table->field[col]->type());
126
 
      rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF,
127
 
                  ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf);
128
 
    }
129
 
    /*
130
 
      Check the slave's field size against that of the master.
131
 
    */
132
 
    if (!error && 
133
 
        !table->field[col]->compatible_field_size(field_metadata(col)))
134
 
    {
135
 
      error= 1;
136
 
      char buf[256];
137
 
      snprintf(buf, sizeof(buf), _("Column %d size mismatch - "
138
 
               "master has size %d, %s.%s on slave has size %d."
139
 
               " Master's column size should be <= the slave's "
140
 
               "column size."), col,
141
 
               table->field[col]->pack_length_from_metadata(
142
 
                                    m_field_metadata[col]),
143
 
               tsh->db.str, tsh->table_name.str, 
144
 
               table->field[col]->row_pack_length());
145
 
      rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF,
146
 
                  ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf);
147
 
    }
148
 
  }
149
 
 
150
 
  return error;
151
 
}