~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/src/kernel/blocks/dbdih/printSysfile.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

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