~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/rpl_utility.cc

  • Committer: Monty Taylor
  • Date: 2008-07-22 05:48:51 UTC
  • mto: (202.1.3 toru)
  • mto: This revision was merged to the branch mainline in revision 204.
  • Revision ID: monty@inaugust.com-20080722054851-airxt73370725p7x
Re-enabled optimizations for the normal build, and added back the --with-debug option to turn them off. 

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_DOUBLE:
39
37
    length= m_field_metadata[col];
40
38
    break;
41
39
  /*
42
40
    The cases for SET and ENUM are include for completeness, however
43
 
    both are mapped to type DRIZZLE_TYPE_STRING and their real types
 
41
    both are mapped to type MYSQL_TYPE_STRING and their real types
44
42
    are encoded in the field metadata.
45
43
  */
46
 
  case DRIZZLE_TYPE_ENUM:
 
44
  case MYSQL_TYPE_SET:
 
45
  case MYSQL_TYPE_ENUM:
 
46
  case MYSQL_TYPE_STRING:
47
47
  {
48
 
    length= m_field_metadata[col] & 0x00ff;
 
48
    uchar type= m_field_metadata[col] >> 8U;
 
49
    if ((type == MYSQL_TYPE_SET) || (type == MYSQL_TYPE_ENUM))
 
50
      length= m_field_metadata[col] & 0x00ff;
 
51
    else
 
52
    {
 
53
      /*
 
54
        We are reading the actual size from the master_data record
 
55
        because this field has the actual lengh stored in the first
 
56
        byte.
 
57
      */
 
58
      length= (uint) *master_data + 1;
 
59
      assert(length != 0);
 
60
    }
49
61
    break;
50
62
  }
51
 
  case DRIZZLE_TYPE_TINY:
 
63
  case MYSQL_TYPE_YEAR:
 
64
  case MYSQL_TYPE_TINY:
52
65
    length= 1;
53
66
    break;
54
 
  case DRIZZLE_TYPE_LONG:
 
67
  case MYSQL_TYPE_SHORT:
 
68
    length= 2;
 
69
    break;
 
70
  case MYSQL_TYPE_LONG:
55
71
    length= 4;
56
72
    break;
57
 
  case DRIZZLE_TYPE_LONGLONG:
 
73
  case MYSQL_TYPE_LONGLONG:
58
74
    length= 8;
59
75
    break;
60
 
  case DRIZZLE_TYPE_NULL:
 
76
  case MYSQL_TYPE_NULL:
61
77
    length= 0;
62
78
    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:
 
79
  case MYSQL_TYPE_NEWDATE:
 
80
    length= 3;
 
81
    break;
 
82
  case MYSQL_TYPE_TIME:
 
83
    length= 3;
 
84
    break;
 
85
  case MYSQL_TYPE_TIMESTAMP:
70
86
    length= 4;
71
87
    break;
72
 
  case DRIZZLE_TYPE_DATETIME:
 
88
  case MYSQL_TYPE_DATETIME:
73
89
    length= 8;
74
90
    break;
75
 
  case DRIZZLE_TYPE_VARCHAR:
 
91
  case MYSQL_TYPE_VARCHAR:
76
92
  {
77
93
    length= m_field_metadata[col] > 255 ? 2 : 1; // c&p of Field_varstring::data_length()
78
94
    assert(uint2korr(master_data) > 0);
79
 
    length+= length == 1 ? (uint32_t) *master_data : uint2korr(master_data);
 
95
    length+= length == 1 ? (uint32) *master_data : uint2korr(master_data);
80
96
    break;
81
97
  }
82
 
  case DRIZZLE_TYPE_BLOB:
 
98
  case MYSQL_TYPE_BLOB:
83
99
  {
84
100
    length= uint4korr(master_data);
85
101
    length+= m_field_metadata[col];
86
102
    break;
87
103
  }
88
104
  default:
89
 
    length= ~(uint32_t) 0;
 
105
    length= ~(uint32) 0;
90
106
  }
91
107
  return length;
92
108
}
96
112
 
97
113
*/
98
114
int
99
 
table_def::compatible_with(Relay_log_info const *rli_arg, Table *table)
 
115
table_def::compatible_with(Relay_log_info const *rli_arg, TABLE *table)
100
116
  const
101
117
{
102
118
  /*
103
119
    We only check the initial columns for the tables.
104
120
  */
105
 
  uint32_t const cols_to_check= cmin(table->s->fields, size());
 
121
  uint const cols_to_check= min(table->s->fields, size());
106
122
  int error= 0;
107
123
  Relay_log_info const *rli= const_cast<Relay_log_info*>(rli_arg);
108
124
 
109
125
  TABLE_SHARE const *const tsh= table->s;
110
126
 
111
 
  for (uint32_t col= 0 ; col < cols_to_check ; ++col)
 
127
  for (uint col= 0 ; col < cols_to_check ; ++col)
112
128
  {
113
129
    if (table->field[col]->type() != type(col))
114
130
    {
116
132
      assert(tsh->db.str && tsh->table_name.str);
117
133
      error= 1;
118
134
      char buf[256];
119
 
      snprintf(buf, sizeof(buf), _("Column %d type mismatch - "
120
 
                "received type %d, %s.%s has type %d"),
 
135
      snprintf(buf, sizeof(buf), "Column %d type mismatch - "
 
136
                "received type %d, %s.%s has type %d",
121
137
                col, type(col), tsh->db.str, tsh->table_name.str,
122
138
                table->field[col]->type());
123
139
      rli->report(ERROR_LEVEL, ER_BINLOG_ROW_WRONG_TABLE_DEF,
131
147
    {
132
148
      error= 1;
133
149
      char buf[256];
134
 
      snprintf(buf, sizeof(buf), _("Column %d size mismatch - "
 
150
      snprintf(buf, sizeof(buf), "Column %d size mismatch - "
135
151
               "master has size %d, %s.%s on slave has size %d."
136
152
               " Master's column size should be <= the slave's "
137
 
               "column size."), col,
 
153
               "column size.", col,
138
154
               table->field[col]->pack_length_from_metadata(
139
155
                                    m_field_metadata[col]),
140
156
               tsh->db.str, tsh->table_name.str,