~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/rpl_utility.cc

  • Committer: Monty Taylor
  • Date: 2008-07-05 11:08:18 UTC
  • mto: This revision was merged to the branch mainline in revision 62.
  • Revision ID: monty@inaugust.com-20080705110818-xyc8ehdym3r7nf6t
Add Jay's test optoins at the target of make test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
 
#include <drizzled/server_includes.h>
17
16
#include "rpl_utility.h"
18
17
#include "rpl_rli.h"
19
 
#include <drizzled/drizzled_error_messages.h>
20
18
 
21
19
/*********************************************************************
22
20
 *                   table_def member definitions                    *
26
24
  This function returns the field size in raw bytes based on the type
27
25
  and the encoded field data from the master's raw data.
28
26
*/
29
 
uint32_t table_def::calc_field_size(uint32_t col, unsigned char *master_data) const
 
27
uint32 table_def::calc_field_size(uint col, uchar *master_data) const
30
28
{
31
 
  uint32_t length= 0;
 
29
  uint32 length= 0;
32
30
 
33
31
  switch (type(col)) {
34
 
  case DRIZZLE_TYPE_NEWDECIMAL:
 
32
  case MYSQL_TYPE_NEWDECIMAL:
35
33
    length= my_decimal_get_binary_size(m_field_metadata[col] >> 8, 
36
34
                                       m_field_metadata[col] & 0xff);
37
35
    break;
38
 
  case DRIZZLE_TYPE_DOUBLE:
 
36
  case MYSQL_TYPE_DECIMAL:
 
37
  case MYSQL_TYPE_FLOAT:
 
38
  case MYSQL_TYPE_DOUBLE:
39
39
    length= m_field_metadata[col];
40
40
    break;
41
41
  /*
42
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
 
43
    both are mapped to type MYSQL_TYPE_STRING and their real types
44
44
    are encoded in the field metadata.
45
45
  */
46
 
  case DRIZZLE_TYPE_ENUM:
 
46
  case MYSQL_TYPE_SET:
 
47
  case MYSQL_TYPE_ENUM:
 
48
  case MYSQL_TYPE_STRING:
47
49
  {
48
 
    length= m_field_metadata[col] & 0x00ff;
 
50
    uchar type= m_field_metadata[col] >> 8U;
 
51
    if ((type == MYSQL_TYPE_SET) || (type == MYSQL_TYPE_ENUM))
 
52
      length= m_field_metadata[col] & 0x00ff;
 
53
    else
 
54
    {
 
55
      /*
 
56
        We are reading the actual size from the master_data record
 
57
        because this field has the actual lengh stored in the first
 
58
        byte.
 
59
      */
 
60
      length= (uint) *master_data + 1;
 
61
      DBUG_ASSERT(length != 0);
 
62
    }
49
63
    break;
50
64
  }
51
 
  case DRIZZLE_TYPE_TINY:
 
65
  case MYSQL_TYPE_YEAR:
 
66
  case MYSQL_TYPE_TINY:
52
67
    length= 1;
53
68
    break;
54
 
  case DRIZZLE_TYPE_LONG:
 
69
  case MYSQL_TYPE_SHORT:
 
70
    length= 2;
 
71
    break;
 
72
  case MYSQL_TYPE_INT24:
 
73
    length= 3;
 
74
    break;
 
75
  case MYSQL_TYPE_LONG:
55
76
    length= 4;
56
77
    break;
57
 
  case DRIZZLE_TYPE_LONGLONG:
 
78
#ifdef HAVE_LONG_LONG
 
79
  case MYSQL_TYPE_LONGLONG:
58
80
    length= 8;
59
81
    break;
60
 
  case DRIZZLE_TYPE_NULL:
 
82
#endif
 
83
  case MYSQL_TYPE_NULL:
61
84
    length= 0;
62
85
    break;
63
 
  case DRIZZLE_TYPE_NEWDATE:
64
 
    length= 3;
65
 
    break;
66
 
  case DRIZZLE_TYPE_TIME:
67
 
    length= 3;
68
 
    break;
69
 
  case DRIZZLE_TYPE_TIMESTAMP:
 
86
  case MYSQL_TYPE_NEWDATE:
 
87
    length= 3;
 
88
    break;
 
89
  case MYSQL_TYPE_DATE:
 
90
  case MYSQL_TYPE_TIME:
 
91
    length= 3;
 
92
    break;
 
93
  case MYSQL_TYPE_TIMESTAMP:
70
94
    length= 4;
71
95
    break;
72
 
  case DRIZZLE_TYPE_DATETIME:
 
96
  case MYSQL_TYPE_DATETIME:
73
97
    length= 8;
74
98
    break;
75
 
  case DRIZZLE_TYPE_VARCHAR:
 
99
  case MYSQL_TYPE_BIT:
 
100
  {
 
101
    /*
 
102
      Decode the size of the bit field from the master.
 
103
        from_len is the length in bytes from the master
 
104
        from_bit_len is the number of extra bits stored in the master record
 
105
      If from_bit_len is not 0, add 1 to the length to account for accurate
 
106
      number of bytes needed.
 
107
    */
 
108
    uint from_len= (m_field_metadata[col] >> 8U) & 0x00ff;
 
109
    uint from_bit_len= m_field_metadata[col] & 0x00ff;
 
110
    DBUG_ASSERT(from_bit_len <= 7);
 
111
    length= from_len + ((from_bit_len > 0) ? 1 : 0);
 
112
    break;
 
113
  }
 
114
  case MYSQL_TYPE_VARCHAR:
76
115
  {
77
116
    length= m_field_metadata[col] > 255 ? 2 : 1; // c&p of Field_varstring::data_length()
78
 
    assert(uint2korr(master_data) > 0);
79
 
    length+= length == 1 ? (uint32_t) *master_data : uint2korr(master_data);
 
117
    DBUG_ASSERT(uint2korr(master_data) > 0);
 
118
    length+= length == 1 ? (uint32) *master_data : uint2korr(master_data);
80
119
    break;
81
120
  }
82
 
  case DRIZZLE_TYPE_BLOB:
 
121
  case MYSQL_TYPE_TINY_BLOB:
 
122
  case MYSQL_TYPE_MEDIUM_BLOB:
 
123
  case MYSQL_TYPE_LONG_BLOB:
 
124
  case MYSQL_TYPE_BLOB:
 
125
  case MYSQL_TYPE_GEOMETRY:
83
126
  {
84
 
    length= uint4korr(master_data);
 
127
    /*
 
128
      Compute the length of the data. We cannot use get_length() here
 
129
      since it is dependent on the specific table (and also checks the
 
130
      packlength using the internal 'table' pointer) and replication
 
131
      is using a fixed format for storing data in the binlog.
 
132
    */
 
133
    switch (m_field_metadata[col]) {
 
134
    case 1:
 
135
      length= *master_data;
 
136
      break;
 
137
    case 2:
 
138
      length= uint2korr(master_data);
 
139
      break;
 
140
    case 3:
 
141
      length= uint3korr(master_data);
 
142
      break;
 
143
    case 4:
 
144
      length= uint4korr(master_data);
 
145
      break;
 
146
    default:
 
147
      DBUG_ASSERT(0);           // Should not come here
 
148
      break;
 
149
    }
 
150
 
85
151
    length+= m_field_metadata[col];
86
152
    break;
87
153
  }
88
154
  default:
89
 
    length= ~(uint32_t) 0;
 
155
    length= ~(uint32) 0;
90
156
  }
91
157
  return length;
92
158
}
96
162
 
97
163
*/
98
164
int
99
 
table_def::compatible_with(Relay_log_info const *rli_arg, Table *table)
 
165
table_def::compatible_with(Relay_log_info const *rli_arg, TABLE *table)
100
166
  const
101
167
{
102
168
  /*
103
169
    We only check the initial columns for the tables.
104
170
  */
105
 
  uint32_t const cols_to_check= cmin(table->s->fields, size());
 
171
  uint const cols_to_check= min(table->s->fields, size());
106
172
  int error= 0;
107
173
  Relay_log_info const *rli= const_cast<Relay_log_info*>(rli_arg);
108
174
 
109
175
  TABLE_SHARE const *const tsh= table->s;
110
176
 
111
 
  for (uint32_t col= 0 ; col < cols_to_check ; ++col)
 
177
  for (uint col= 0 ; col < cols_to_check ; ++col)
112
178
  {
113
179
    if (table->field[col]->type() != type(col))
114
180
    {
115
 
      assert(col < size() && col < tsh->fields);
116
 
      assert(tsh->db.str && tsh->table_name.str);
 
181
      DBUG_ASSERT(col < size() && col < tsh->fields);
 
182
      DBUG_ASSERT(tsh->db.str && tsh->table_name.str);
117
183
      error= 1;
118
184
      char buf[256];
119
 
      snprintf(buf, sizeof(buf), _("Column %d type mismatch - "
120
 
                "received type %d, %s.%s has type %d"),
121
 
                col, type(col), tsh->db.str, tsh->table_name.str,
122
 
                table->field[col]->type());
 
185
      my_snprintf(buf, sizeof(buf), "Column %d type mismatch - "
 
186
                  "received type %d, %s.%s has type %d",
 
187
                  col, type(col), tsh->db.str, tsh->table_name.str,
 
188
                  table->field[col]->type());
123
189
      rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF,
124
190
                  ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf);
125
191
    }
131
197
    {
132
198
      error= 1;
133
199
      char buf[256];
134
 
      snprintf(buf, sizeof(buf), _("Column %d size mismatch - "
135
 
               "master has size %d, %s.%s on slave has size %d."
136
 
               " Master's column size should be <= the slave's "
137
 
               "column size."), col,
138
 
               table->field[col]->pack_length_from_metadata(
139
 
                                    m_field_metadata[col]),
140
 
               tsh->db.str, tsh->table_name.str, 
141
 
               table->field[col]->row_pack_length());
 
200
      my_snprintf(buf, sizeof(buf), "Column %d size mismatch - "
 
201
                  "master has size %d, %s.%s on slave has size %d."
 
202
                  " Master's column size should be <= the slave's "
 
203
                  "column size.", col,
 
204
                  table->field[col]->pack_length_from_metadata(
 
205
                                       m_field_metadata[col]),
 
206
                  tsh->db.str, tsh->table_name.str, 
 
207
                  table->field[col]->row_pack_length());
142
208
      rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF,
143
209
                  ER(ER_BINLOG_ROW_WRONG_TABLE_DEF), buf);
144
210
    }