MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SchemaFile.hpp
1 /*
2  Copyright (C) 2003, 2005-2008 MySQL AB
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 DBDICT_SCHEMA_FILE_HPP
20 #define DBDICT_SCHEMA_FILE_HPP
21 
22 #include <ndb_types.h>
23 #include <ndb_version.h>
24 #include <string.h>
25 
26 #define NDB_SF_MAGIC "NDBSCHMA"
27 
28 // page size 4k
29 #define NDB_SF_PAGE_SIZE_IN_WORDS_LOG2 10
30 #define NDB_SF_PAGE_SIZE_IN_WORDS (1 << NDB_SF_PAGE_SIZE_IN_WORDS_LOG2)
31 #define NDB_SF_PAGE_SIZE (NDB_SF_PAGE_SIZE_IN_WORDS << 2)
32 
33 // 4k = (1 + 127) * 32
34 #define NDB_SF_PAGE_ENTRIES 127
35 
36 // 160 pages = 20320 objects
37 #define NDB_SF_MAX_PAGES 160
38 
39 // versions where format changed
40 #define NDB_SF_VERSION_5_0_6 MAKE_VERSION(5, 0, 6)
41 
42 // One page in schema file.
43 struct SchemaFile {
44  // header size 32 bytes
45  char Magic[8];
46  Uint32 ByteOrder;
47  Uint32 NdbVersion;
48  Uint32 FileSize; // In bytes
49  Uint32 PageNumber;
50  Uint32 CheckSum; // Of this page
51  Uint32 NoOfTableEntries; // On this page (NDB_SF_PAGE_ENTRIES)
52 
53  struct Old
54  {
55  enum TableState {
56  INIT = 0,
57  ADD_STARTED = 1,
58  TABLE_ADD_COMMITTED = 2,
59  DROP_TABLE_STARTED = 3,
60  DROP_TABLE_COMMITTED = 4,
61  ALTER_TABLE_COMMITTED = 5,
62  TEMPORARY_TABLE_COMMITTED = 6
63  };
64  };
65 
66  enum EntryState
67  {
68  SF_UNUSED = 0 // A free object entry
69 
73  ,SF_CREATE = 1 // An object being created
74  ,SF_ALTER = 7 // An object being altered
75  ,SF_DROP = 3 // An object being dropped
76  ,SF_IN_USE = 2 // An object wo/ ongoing transactions
77 
81  ,SF_STARTED = 10 // A started transaction
82  ,SF_PREPARE = 11 // Prepare has started (and maybe finished)
83  ,SF_COMMIT = 12 // Commit has started (and maybe finished)
84  ,SF_COMPLETE = 13 // Complete has started (and maybe finished)
85  ,SF_ABORT = 14 // Abort (prepare) has started (and maybe finished)
86  };
87 
88  // entry size 32 bytes
89  struct TableEntry {
90  Uint32 m_tableState;
91  Uint32 m_tableVersion;
92  Uint32 m_tableType;
93  Uint32 m_info_words;
94  Uint32 m_gcp;
95  Uint32 m_transId;
96  Uint32 m_unused[2];
97 
98  // cannot use ctor due to union
99  void init() {
100  m_tableState = 0;
101  m_tableVersion = 0;
102  m_tableType = 0;
103  m_info_words = 0;
104  m_gcp = 0;
105  m_transId = 0;
106  m_unused[0] = 0;
107  m_unused[1] = 0;
108  }
109 
110  bool operator==(const TableEntry& o) const {
111  return memcmp(this, &o, sizeof(* this))== 0;
112  }
113  };
114 
115  // pre-5.0.6
116  struct TableEntry_old {
117  Uint32 m_tableState;
118  Uint32 m_tableVersion;
119  Uint32 m_tableType;
120  Uint32 m_noOfPages;
121  Uint32 m_gcp;
122  };
123 
124  union {
125  TableEntry TableEntries[NDB_SF_PAGE_ENTRIES];
126  TableEntry_old TableEntries_old[1];
127  };
128 };
129 
130 #endif