MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
restore.hpp
1 /*
2  Copyright (C) 2005-2008 MySQL AB, 2010 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef Restore_H
20 #define Restore_H
21 
22 #include <SimulatedBlock.hpp>
23 
24 #include <SLList.hpp>
25 #include <DLList.hpp>
26 #include <KeyTable.hpp>
27 #include <DLHashTable.hpp>
28 #include <DataBuffer.hpp>
29 #include <NodeBitmask.hpp>
30 #include <backup/BackupFormat.hpp>
31 
32 class Restore : public SimulatedBlock
33 {
34  friend class RestoreProxy;
35 
36 public:
37  Restore(Block_context& ctx, Uint32 instanceNumber = 0);
38  virtual ~Restore();
39  BLOCK_DEFINES(Restore);
40 
41 protected:
42 
43  void execSTTOR(Signal* signal);
44  void sendSTTORRY(Signal*);
45  void execREAD_CONFIG_REQ(Signal*);
46  void execDUMP_STATE_ORD(Signal* signal);
47  void execCONTINUEB(Signal* signal);
48  void execRESTORE_LCP_REQ(Signal* signal);
49 
50  void execFSOPENREF(Signal*);
51  void execFSOPENCONF(Signal*);
52  void execFSREADREF(Signal*);
53  void execFSREADCONF(Signal*);
54  void execFSCLOSEREF(Signal*);
55  void execFSCLOSECONF(Signal*);
56 
57  void execLQHKEYREF(Signal*);
58  void execLQHKEYCONF(Signal*);
59 
60  typedef DataBuffer<15> List;
61 
62 public:
63  struct Column
64  {
65  Uint16 m_id;
66  Uint16 m_size;
67  Uint16 m_unused;
68  Uint16 m_flags;
69 
70  enum Flags
71  {
72  COL_KEY = 0x1,
73  COL_VAR = 0x2,
74  COL_DISK = 0x4,
75  COL_NULL = 0x8
76  };
77  };
78 private:
79 
80  struct File; // CC
81  friend struct File;
82 
83  struct File
84  {
85  File() {}
86  Uint32 m_sender_ref;
87  Uint32 m_sender_data;
88 
89  Uint32 m_fd; // File pointer
90  Uint32 m_file_type; // File type
91  Uint32 m_status;
92  Uint32 m_lcp_version;
93 
94  enum StatusFlags
95  {
96  FILE_EOF = 1,
97  FILE_THREAD_RUNNING = 2,
98  RESTORE_THREAD_RUNNING = 4,
99  FIRST_READ = 8,
100  READING_RECORDS = 16
101  };
102 
103  Uint32 m_table_id;
104  Uint32 m_table_version;
105  Uint32 m_fragment_id;
106  List::Head m_columns;
107 
108  Uint32 m_current_page_ptr_i;
109  Uint32 m_current_page_pos;
110  Uint32 m_bytes_left; // Bytes read from FS
111  Uint32 m_current_file_page; // Where in file
112  Uint32 m_outstanding_reads; //
113  Uint32 m_outstanding_operations;
114  Uint64 m_rows_restored;
115 
116  Uint32 m_current_page_index; // Where in page list are we
117  List::Head m_pages;
118 
119  Uint32 nextHash;
120  Uint32 prevHash;
121  Uint32 nextList;
122  Uint32 prevList;
123  Uint32 nextPool;
124  Uint32 m_lcp_no;
125 
126  bool is_lcp() const { return m_file_type == BackupFormat::LCP_FILE;}
127  };
128  typedef Ptr<File> FilePtr;
129 
130  Uint32 init_file(const struct RestoreLcpReq*, FilePtr);
131  void release_file(FilePtr);
132 
133  void open_file(Signal*, FilePtr);
134  void read_file(Signal*, FilePtr);
135  void restore_next(Signal*, FilePtr);
136  void parse_file_header(Signal*, FilePtr, const Uint32*, Uint32 len);
137  void parse_table_list(Signal*, FilePtr, const Uint32*, Uint32 len);
138  void parse_table_description(Signal*, FilePtr, const Uint32*, Uint32 len);
139  void parse_fragment_header(Signal*, FilePtr, const Uint32*, Uint32 len);
140  void parse_record(Signal*, FilePtr, const Uint32*, Uint32 len);
141  void parse_fragment_footer(Signal*, FilePtr, const Uint32*, Uint32 len);
142  void parse_gcp_entry(Signal*, FilePtr, const Uint32*, Uint32 len);
143  void close_file(Signal*, FilePtr);
144 
145  void reorder_key(const struct KeyDescriptor*, Uint32* data, Uint32 len);
146  Uint32 calulate_hash(Uint32 tableId, const Uint32 *src);
147 
148  void parse_error(Signal*, FilePtr, Uint32 line, Uint32 extra);
149  int check_file_version(Signal*, Uint32 file_version);
150  void restore_lcp_conf(Signal* signal, FilePtr);
151  void crash_during_restore(FilePtr, Uint32 line, Uint32 errCode);
152 public:
153 
154 private:
155  class Dblqh* c_lqh;
156  class Dbtup* c_tup;
157  DLList<File> m_file_list;
158  KeyTable<File> m_file_hash;
159  ArrayPool<File> m_file_pool;
160 
161  List::DataBufferPool m_databuffer_pool;
162 };
163 
164 NdbOut& operator << (NdbOut&, const Restore::Column&);
165 
166 #endif