MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
consumer_restore.hpp
1 /*
2  Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #ifndef CONSUMER_RESTORE_HPP
19 #define CONSUMER_RESTORE_HPP
20 
21 #include "consumer.hpp"
22 
23 bool map_nodegroups(Uint32 *ng_array, Uint32 no_parts);
24 
26  class BackupRestore *restore;
27  class TupleS tup;
28  class NdbTransaction *connection;
29  int retries;
30  int error_code;
31  Uint32 fragId;
32  Uint32 n_bytes;
33  restore_callback_t *next;
34 };
35 
37 Uint32 n_old;
38 Uint32 n_new;
39 char new_row[1];
40 };
41 
42 enum AttrConvType { ACT_UNSUPPORTED = 0, ACT_PRESERVING = 1, ACT_LOSSY =-1 };
43 typedef AttrConvType (*AttrCheckCompatFunc)(const NDBCOL &old_col,
44  const NDBCOL &new_col);
45 
47  NDBCOL::Type old_type;
48  NDBCOL::Type new_type;
49  AttrCheckCompatFunc attr_check_compatability;
50  AttrConvertFunc attr_convert;
51 };
52 
54 {
55 public:
56  BackupRestore(const char* ndb_connectstring,
57  int ndb_nodeid,
58  NODE_GROUP_MAP *ng_map,
59  uint ng_map_len,
60  Uint32 parallelism=1) :
61  m_ndb(NULL),
62  m_cluster_connection(NULL),
63  m_ndb_connectstring(ndb_connectstring),
64  m_ndb_nodeid(ndb_nodeid)
65  {
66  m_nodegroup_map = ng_map;
67  m_nodegroup_map_len = ng_map_len;
68  m_n_tablespace = 0;
69  m_n_logfilegroup = 0;
70  m_n_datafile = 0;
71  m_n_undofile = 0;
72  m_n_tables = 0;
73  m_logBytes = m_dataBytes = 0;
74  m_logCount = m_dataCount = 0;
75  m_restore = false;
76  m_restore_meta = false;
77  m_no_restore_disk = false;
78  m_restore_epoch = false;
79  m_parallelism = parallelism;
80  m_callback = 0;
81  m_free_callback = 0;
82  m_temp_error = false;
83  m_no_upgrade = false;
84  m_tableChangesMask = 0;
85  m_preserve_trailing_spaces = false;
86  m_transactions = 0;
87  m_cache.m_old_table = 0;
88  m_disable_indexes = false;
89  m_rebuild_indexes = false;
90  }
91 
92  virtual ~BackupRestore();
93  virtual bool init(Uint32 tableChangesMask);
94  virtual void release();
95  virtual bool object(Uint32 type, const void* ptr);
96  virtual bool table(const TableS &);
97  virtual bool endOfTables();
98  virtual void tuple(const TupleS &, Uint32 fragId);
99  virtual void tuple_free();
100  virtual void tuple_a(restore_callback_t *cb);
101  virtual void tuple_SYSTAB_0(restore_callback_t *cb, const TableS &);
102  virtual int restoreAutoIncrement(restore_callback_t *cb,
103  Uint32 tableId, Uint64 value);
104  virtual void cback(int result, restore_callback_t *cb);
105  virtual bool errorHandler(restore_callback_t *cb);
106  virtual void exitHandler();
107  virtual void endOfTuples();
108  virtual void logEntry(const LogEntry &);
109  virtual void endOfLogEntrys();
110  virtual bool finalize_table(const TableS &);
111  virtual bool rebuild_indexes(const TableS&);
112  virtual bool has_temp_error();
113  virtual bool createSystable(const TableS & table);
114  virtual bool table_compatible_check(const TableS & tableS);
115  virtual bool column_compatible_check(const char* tableName,
116  const NDBCOL* backupCol,
117  const NDBCOL* dbCol);
118  virtual bool update_apply_status(const RestoreMetaData &metaData);
119  virtual bool report_started(unsigned node_id, unsigned backup_id);
120  virtual bool report_meta_data(unsigned node_id, unsigned backup_id);
121  virtual bool report_data(unsigned node_id, unsigned backup_id);
122  virtual bool report_log(unsigned node_id, unsigned backup_id);
123  virtual bool report_completed(unsigned node_id, unsigned backup_id);
124  void connectToMysql();
125  bool map_in_frm(char *new_data, const char *data,
126  uint data_len, uint *new_data_len);
127  bool search_replace(char *search_str, char **new_data,
128  const char **data, const char *end_data,
129  uint *new_data_len);
130  bool map_nodegroups(Uint32 *ng_array, Uint32 no_parts);
131  Uint32 map_ng(Uint32 ng);
132  bool translate_frm(NdbDictionary::Table *table);
133 
134  static AttrConvType check_compat_sizes(const NDBCOL &old_col,
135  const NDBCOL &new_col);
136  static AttrConvType check_compat_promotion(const NDBCOL &old_col,
137  const NDBCOL &new_col);
138  static AttrConvType check_compat_lossy(const NDBCOL &old_col,
139  const NDBCOL &new_col);
140 
141  // bitset conversion handler
142  static void*
143  convert_bitset(const void * source, void * target, bool &truncated);
144 
145  // char/binary array conversion handler
146  template< typename S, typename T >
147  static void *
148  convert_array(const void * source, void * target, bool & truncated);
149 
150  // integral type conversion handler
151  // (follows MySQL replication semantics truncating to nearest legal value)
152  template< typename T, typename S >
153  static void *
154  convert_integral(const void * source, void * target, bool & truncated);
155 
156  // returns the handler function checking type conversion compatibility
157  AttrCheckCompatFunc
158  get_attr_check_compatability(const NDBCOL::Type &old_type,
159  const NDBCOL::Type &new_type);
160 
161  // returns the handler function converting a value
162  AttrConvertFunc
163  get_convert_func(const NDBCOL::Type &old_type,
164  const NDBCOL::Type &new_type);
165 
166  Ndb * m_ndb;
167  Ndb_cluster_connection * m_cluster_connection;
168  const char* m_ndb_connectstring;
169  int m_ndb_nodeid;
170  bool m_restore;
171  bool m_restore_meta;
172  bool m_no_restore_disk;
173  bool m_restore_epoch;
174  bool m_no_upgrade; // for upgrade ArrayType from 5.0 backup file.
175  bool m_disable_indexes;
176  bool m_rebuild_indexes;
177  Uint32 m_tableChangesMask;
178  static bool m_preserve_trailing_spaces;
179 
180  Uint32 m_n_tablespace;
181  Uint32 m_n_logfilegroup;
182  Uint32 m_n_datafile;
183  Uint32 m_n_undofile;
184  Uint32 m_n_tables;
185 
186  Uint64 m_logBytes;
187  Uint64 m_dataBytes;
188 
189  Uint32 m_logCount;
190  Uint32 m_dataCount;
191 
192  Uint32 m_parallelism;
193  volatile Uint32 m_transactions;
194 
195  restore_callback_t *m_callback;
196  restore_callback_t *m_free_callback;
197  bool m_temp_error;
198 
205  struct {
206  const NdbDictionary::Table* m_old_table;
207  const NdbDictionary::Table* m_new_table;
208  } m_cache;
209  const NdbDictionary::Table* get_table(const NdbDictionary::Table* );
210 
212  Vector<Vector<NdbDictionary::Index *> > m_index_per_table; //
213  Vector<NdbDictionary::Tablespace*> m_tablespaces; // Index by id
214  Vector<NdbDictionary::LogfileGroup*> m_logfilegroups;// Index by id
216 
217  static const PromotionRules m_allowed_promotion_attrs[];
218 };
219 
220 #endif