~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/replication/utility.cc

  • Committer: Brian Aker
  • Date: 2010-12-08 22:35:56 UTC
  • mfrom: (1819.9.158 update-innobase)
  • Revision ID: brian@tangent.org-20101208223556-37mi4omqg7lkjzf3
Merge in Stewart's changes, 1.3 changes.

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