MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
printSysfile.cpp
1 /*
2  Copyright (c) 2005, 2010, 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 
19 #include <ndb_global.h>
20 
21 #include <NdbMain.h>
22 #include <NdbOut.hpp>
23 #include "Sysfile.hpp"
24 
25 static int g_all = 0;
26 
27 void
28 usage(const char * prg){
29  ndbout << "Usage " << prg
30  << " P[0-1].sysfile" << endl;
31 }
32 
33 struct NSString {
34  Sysfile::ActiveStatus NodeStatus;
35  const char * desc;
36 };
37 
38 static const
39 NSString NodeStatusStrings[] = {
40  { Sysfile::NS_Active, "Active " },
41  { Sysfile::NS_ActiveMissed_1, "Active missed 1" },
42  { Sysfile::NS_ActiveMissed_2, "Active missed 2" },
43  { Sysfile::NS_ActiveMissed_3, "Active missed 3" },
44  { Sysfile::NS_NotActive_NotTakenOver, "Not active " },
45  { Sysfile::NS_TakeOver, "Take over " },
46  { Sysfile::NS_NotActive_TakenOver, "Taken over " },
47  { Sysfile::NS_NotDefined, "Not defined " }
48  ,{ Sysfile::NS_Configured, "Configured " }
49 };
50 
51 const
52 char * getNSString(Uint32 ns){
53  for(Uint32 i = 0; i<(sizeof(NodeStatusStrings)/sizeof(NSString)); i++)
54  if((Uint32)NodeStatusStrings[i].NodeStatus == ns)
55  return NodeStatusStrings[i].desc;
56  return "<Unknown state>";
57 }
58 
59 void
60 fill(const char * buf, int mod){
61  int len = strlen(buf)+1;
62  ndbout << buf << " ";
63  while((len % mod) != 0){
64  ndbout << " ";
65  len++;
66  }
67 }
68 
69 void
70 print(const char * filename, const Sysfile * sysfile){
71  char buf[255];
72  ndbout << "----- Sysfile: " << filename
73  << " seq: " << hex << sysfile->m_restart_seq
74  << " -----" << endl;
75  ndbout << "Initial start ongoing: "
76  << Sysfile::getInitialStartOngoing(sysfile->systemRestartBits)
77  << ", ";
78 
79  ndbout << "Restart Ongoing: "
80  << Sysfile::getRestartOngoing(sysfile->systemRestartBits)
81  << ", ";
82 
83  ndbout << "LCP Ongoing: "
84  << Sysfile::getLCPOngoing(sysfile->systemRestartBits)
85  << endl;
86 
87 
88  ndbout << "-- Global Checkpoint Identities: --" << endl;
89  sprintf(buf, "keepGCI = %u", sysfile->keepGCI);
90  fill(buf, 40);
91  ndbout << " -- Tail of REDO log" << endl;
92 
93  sprintf(buf, "oldestRestorableGCI = %u", sysfile->oldestRestorableGCI);
94  fill(buf, 40);
95  ndbout << " -- " << endl;
96 
97  sprintf(buf, "newestRestorableGCI = %u", sysfile->newestRestorableGCI);
98  fill(buf, 40);
99  ndbout << " -- " << endl;
100 
101  sprintf(buf, "latestLCP = %u", sysfile->latestLCP_ID);
102  fill(buf, 40);
103  ndbout << " -- " << endl;
104 
105  ndbout << "-- Node status: --" << endl;
106  for(int i = 1; i < MAX_NDB_NODES; i++){
107  if(g_all || Sysfile::getNodeStatus(i, sysfile->nodeStatus) !=Sysfile::NS_NotDefined){
108  sprintf(buf,
109  "Node %.2d -- %s GCP: %d, NodeGroup: %d, TakeOverNode: %d, "
110  "LCP Ongoing: %s",
111  i,
112  getNSString(Sysfile::getNodeStatus(i,sysfile->nodeStatus)),
113  sysfile->lastCompletedGCI[i],
114  Sysfile::getNodeGroup(i, sysfile->nodeGroups),
115  Sysfile::getTakeOverNode(i, sysfile->takeOver),
116  BitmaskImpl::get(NdbNodeBitmask::Size,
117  sysfile->lcpActive, i) != 0 ? "yes" : "no");
118  ndbout << buf << endl;
119  }
120  }
121 }
122 
123 NDB_COMMAND(printSysfile,
124  "printSysfile", "printSysfile", "Prints a sysfile", 16384){
125  ndb_init();
126  if(argc < 2){
127  usage(argv[0]);
128  return 0;
129  }
130 
131  for(int i = 1; i<argc; i++){
132  const char * filename = argv[i];
133 
134  if (strcmp(filename, "--all") == 0)
135  {
136  g_all = 1;
137  continue;
138  }
139 
140  struct stat sbuf;
141 
142  if(stat(filename, &sbuf) != 0)
143  {
144  ndbout << "Could not find file: \"" << filename << "\"" << endl;
145  continue;
146  }
147  const Uint32 bytes = sbuf.st_size;
148 
149  Uint32 * buf = new Uint32[bytes/4+1];
150 
151  FILE * f = fopen(filename, "rb");
152  if(f == 0){
153  ndbout << "Failed to open file" << endl;
154  delete [] buf;
155  continue;
156  }
157  Uint32 sz = (Uint32)fread(buf, 1, bytes, f);
158  fclose(f);
159  if(sz != bytes){
160  ndbout << "Failure while reading file" << endl;
161  delete [] buf;
162  continue;
163  }
164 
165  print(filename, (Sysfile *)&buf[0]);
166  delete [] buf;
167  continue;
168  }
169  return 0;
170 }