Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
1f092293
Commit
1f092293
authored
Sep 28, 2005
by
pekka@mysql.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ndb - printSchemaFile: more checks and options
parent
a11dcd74
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
117 additions
and
51 deletions
+117
-51
ndb/src/kernel/blocks/dbdict/printSchemaFile.cpp
ndb/src/kernel/blocks/dbdict/printSchemaFile.cpp
+117
-51
No files found.
ndb/src/kernel/blocks/dbdict/printSchemaFile.cpp
View file @
1f092293
#if 0
make -f Makefile -f - printSchemaFile <<'_eof_'
printSchemaFile: printSchemaFile.cpp SchemaFile.hpp
$(CXXCOMPILE) -o $@ $@.cpp -L../../../common/util/.libs -lgeneral
ifneq ($(MYSQL_HOME),)
ln -sf `pwd`/$@ $(MYSQL_HOME)/bin/$@
endif
_eof_
exit $?
#endif
/* Copyright (C) 2003 MySQL AB
/* Copyright (C) 2003 MySQL AB
This program is free software; you can redistribute it and/or modify
This program is free software; you can redistribute it and/or modify
...
@@ -36,14 +25,19 @@ exit $?
...
@@ -36,14 +25,19 @@ exit $?
static
const
char
*
progname
=
0
;
static
const
char
*
progname
=
0
;
static
bool
allflag
=
false
;
static
bool
allflag
=
false
;
static
bool
checkonly
=
false
;
static
bool
checkonly
=
false
;
static
int
xitcode
=
0
;
static
bool
equalcontents
=
false
;
static
bool
okquiet
=
false
;
static
void
static
void
usage
()
usage
()
{
{
ndbout
<<
"Usage "
<<
progname
ndbout
<<
" [-ac]"
<<
"Usage: "
<<
progname
<<
" [-aceq]"
<<
" file ..."
<<
endl
<<
" P0.SchemaLog"
<<
endl
;
<<
"-a print also unused slots"
<<
endl
<<
"-c check only (return status 1 on error)"
<<
endl
<<
"-e check also that the files have identical contents"
<<
endl
<<
"-q no output if file is ok"
<<
endl
<<
"Example: "
<<
progname
<<
" -ceq ndb_*_fs/D[12]/DBDICT/P0.SchemaLog"
<<
endl
;
}
}
static
void
static
void
...
@@ -57,52 +51,78 @@ fill(const char * buf, int mod)
...
@@ -57,52 +51,78 @@ fill(const char * buf, int mod)
}
}
}
}
static
void
static
const
char
*
version
(
Uint32
v
)
{
static
char
buf
[
40
];
sprintf
(
buf
,
"%d.%d.%d"
,
v
>>
16
,
(
v
>>
8
)
&
0xFF
,
v
&
0xFF
);
return
buf
;
}
static
int
print_head
(
const
char
*
filename
,
const
SchemaFile
*
sf
)
print_head
(
const
char
*
filename
,
const
SchemaFile
*
sf
)
{
{
int
retcode
=
0
;
if
(
!
checkonly
)
{
if
(
!
checkonly
)
{
ndbout
<<
"----- Schemafile: "
<<
filename
<<
" -----"
<<
endl
;
ndbout
<<
"----- Schemafile: "
<<
filename
<<
" -----"
<<
endl
;
ndbout_c
(
"Magic: %.*s ByteOrder: %.8x NdbVersion: %
d.%d.%d
FileSize: %d"
,
ndbout_c
(
"Magic: %.*s ByteOrder: %.8x NdbVersion: %
s
FileSize: %d"
,
sizeof
(
sf
->
Magic
),
sizeof
(
sf
->
Magic
),
sf
->
Magic
,
sf
->
Magic
,
sf
->
ByteOrder
,
sf
->
ByteOrder
,
sf
->
NdbVersion
>>
16
,
version
(
sf
->
NdbVersion
),
(
sf
->
NdbVersion
>>
8
)
&
0xFF
,
sf
->
NdbVersion
&
0xFF
,
sf
->
FileSize
);
sf
->
FileSize
);
}
}
if
(
memcmp
(
sf
->
Magic
,
"NDBSCHMA"
,
sizeof
(
sf
->
Magic
)
!=
0
))
{
ndbout
<<
filename
<<
": invalid header magic"
<<
endl
;
retcode
=
1
;
}
if
((
sf
->
NdbVersion
>>
16
)
<
4
||
(
sf
->
NdbVersion
>>
16
)
>
9
)
{
ndbout
<<
filename
<<
": impossible version "
<<
hex
<<
sf
->
NdbVersion
<<
endl
;
retcode
=
1
;
}
return
retcode
;
}
}
static
void
static
int
print_old
(
const
char
*
filename
,
const
SchemaFile
*
sf
)
print_old
(
const
char
*
filename
,
const
SchemaFile
*
sf
,
Uint32
sz
)
{
{
print_head
(
filename
,
sf
);
int
retcode
=
0
;
if
(
print_head
(
filename
,
sf
)
!=
0
)
retcode
=
1
;
for
(
Uint32
i
=
0
;
i
<
sf
->
NoOfTableEntries
;
i
++
)
{
for
(
Uint32
i
=
0
;
i
<
sf
->
NoOfTableEntries
;
i
++
)
{
SchemaFile
::
TableEntry_old
te
=
sf
->
TableEntries_old
[
i
];
SchemaFile
::
TableEntry_old
te
=
sf
->
TableEntries_old
[
i
];
if
(
allflag
||
if
(
allflag
||
(
te
.
m_tableState
!=
SchemaFile
::
INIT
&&
(
te
.
m_tableState
!=
SchemaFile
::
INIT
&&
te
.
m_tableState
!=
SchemaFile
::
DROP_TABLE_COMMITTED
))
{
te
.
m_tableState
!=
SchemaFile
::
DROP_TABLE_COMMITTED
))
{
ndbout
<<
"Table "
<<
i
<<
":"
if
(
!
checkonly
)
<<
" State = "
<<
te
.
m_tableState
ndbout
<<
"Table "
<<
i
<<
":"
<<
" version = "
<<
te
.
m_tableVersion
<<
" State = "
<<
te
.
m_tableState
<<
" type = "
<<
te
.
m_tableType
<<
" version = "
<<
te
.
m_tableVersion
<<
" noOfPages = "
<<
te
.
m_noOfPages
<<
" type = "
<<
te
.
m_tableType
<<
" gcp: "
<<
te
.
m_gcp
<<
endl
;
<<
" noOfPages = "
<<
te
.
m_noOfPages
<<
" gcp: "
<<
te
.
m_gcp
<<
endl
;
}
}
}
}
return
retcode
;
}
}
static
void
static
int
print
(
const
char
*
filename
,
const
SchemaFile
*
xsf
,
Uint32
sz
)
print
(
const
char
*
filename
,
const
SchemaFile
*
xsf
,
Uint32
sz
)
{
{
int
retcode
=
0
;
int
retcode
=
0
;
print_head
(
filename
,
xsf
);
if
(
print_head
(
filename
,
xsf
)
!=
0
)
retcode
=
1
;
assert
(
sizeof
(
SchemaFile
)
==
NDB_SF_PAGE_SIZE
);
assert
(
sizeof
(
SchemaFile
)
==
NDB_SF_PAGE_SIZE
);
if
(
xsf
->
FileSize
!=
sz
||
xsf
->
FileSize
%
NDB_SF_PAGE_SIZE
!=
0
)
{
if
(
xsf
->
FileSize
!=
sz
||
xsf
->
FileSize
%
NDB_SF_PAGE_SIZE
!=
0
)
{
ndbout
<<
"*****
invalid FileSize "
<<
xsf
->
FileSize
<<
endl
;
ndbout
<<
filename
<<
":
invalid FileSize "
<<
xsf
->
FileSize
<<
endl
;
retcode
=
1
;
retcode
=
1
;
}
}
Uint32
noOfPages
=
xsf
->
FileSize
/
NDB_SF_PAGE_SIZE
;
Uint32
noOfPages
=
xsf
->
FileSize
/
NDB_SF_PAGE_SIZE
;
...
@@ -111,19 +131,23 @@ print(const char * filename, const SchemaFile * xsf, Uint32 sz)
...
@@ -111,19 +131,23 @@ print(const char * filename, const SchemaFile * xsf, Uint32 sz)
ndbout
<<
"----- Page: "
<<
n
<<
" ("
<<
noOfPages
<<
") -----"
<<
endl
;
ndbout
<<
"----- Page: "
<<
n
<<
" ("
<<
noOfPages
<<
") -----"
<<
endl
;
}
}
const
SchemaFile
*
sf
=
&
xsf
[
n
];
const
SchemaFile
*
sf
=
&
xsf
[
n
];
if
(
memcmp
(
sf
->
Magic
,
xsf
->
Magic
,
sizeof
(
sf
->
Magic
))
!=
0
)
{
ndbout
<<
filename
<<
": page "
<<
n
<<
" invalid magic"
<<
endl
;
retcode
=
1
;
}
if
(
sf
->
FileSize
!=
xsf
->
FileSize
)
{
if
(
sf
->
FileSize
!=
xsf
->
FileSize
)
{
ndbout
<<
"*****
page "
<<
n
<<
" FileSize changed to "
<<
sf
->
FileSize
<<
"!="
<<
xsf
->
FileSize
<<
endl
;
ndbout
<<
filename
<<
":
page "
<<
n
<<
" FileSize changed to "
<<
sf
->
FileSize
<<
"!="
<<
xsf
->
FileSize
<<
endl
;
retcode
=
1
;
retcode
=
1
;
}
}
Uint32
cs
=
0
;
Uint32
cs
=
0
;
for
(
Uint32
j
=
0
;
j
<
NDB_SF_PAGE_SIZE_IN_WORDS
;
j
++
)
for
(
Uint32
j
=
0
;
j
<
NDB_SF_PAGE_SIZE_IN_WORDS
;
j
++
)
cs
^=
((
const
Uint32
*
)
sf
)[
j
];
cs
^=
((
const
Uint32
*
)
sf
)[
j
];
if
(
cs
!=
0
)
{
if
(
cs
!=
0
)
{
ndbout
<<
"*****
page "
<<
n
<<
" invalid CheckSum"
<<
endl
;
ndbout
<<
filename
<<
":
page "
<<
n
<<
" invalid CheckSum"
<<
endl
;
retcode
=
1
;
retcode
=
1
;
}
}
if
(
sf
->
NoOfTableEntries
!=
NDB_SF_PAGE_ENTRIES
)
{
if
(
sf
->
NoOfTableEntries
!=
NDB_SF_PAGE_ENTRIES
)
{
ndbout
<<
"*****
page "
<<
n
<<
" invalid NoOfTableEntries "
<<
sf
->
NoOfTableEntries
<<
endl
;
ndbout
<<
filename
<<
":
page "
<<
n
<<
" invalid NoOfTableEntries "
<<
sf
->
NoOfTableEntries
<<
endl
;
retcode
=
1
;
retcode
=
1
;
}
}
for
(
Uint32
i
=
0
;
i
<
NDB_SF_PAGE_ENTRIES
;
i
++
)
{
for
(
Uint32
i
=
0
;
i
<
NDB_SF_PAGE_ENTRIES
;
i
++
)
{
...
@@ -141,31 +165,41 @@ print(const char * filename, const SchemaFile * xsf, Uint32 sz)
...
@@ -141,31 +165,41 @@ print(const char * filename, const SchemaFile * xsf, Uint32 sz)
<<
" gcp: "
<<
te
.
m_gcp
<<
endl
;
<<
" gcp: "
<<
te
.
m_gcp
<<
endl
;
}
}
if
(
te
.
m_unused
[
0
]
!=
0
||
te
.
m_unused
[
1
]
!=
0
||
te
.
m_unused
[
2
]
!=
0
)
{
if
(
te
.
m_unused
[
0
]
!=
0
||
te
.
m_unused
[
1
]
!=
0
||
te
.
m_unused
[
2
]
!=
0
)
{
ndbout
<<
"*****
entry "
<<
j
<<
" garbage in m_unused[3]"
<<
endl
;
ndbout
<<
filename
<<
":
entry "
<<
j
<<
" garbage in m_unused[3]"
<<
endl
;
retcode
=
1
;
retcode
=
1
;
}
}
}
}
}
}
if
(
retcode
!=
0
)
return
retcode
;
xitcode
=
1
;
else
if
(
checkonly
)
ndbout
<<
"ok: "
<<
filename
<<
endl
;
}
}
NDB_COMMAND
(
printSchemafile
,
NDB_COMMAND
(
printSchemafile
,
"printSchemafile"
,
"printSchemafile"
,
"Prints a schemafile"
,
16384
)
"printSchemafile"
,
"printSchemafile"
,
"Prints a schemafile"
,
16384
)
{
{
progname
=
argv
[
0
];
progname
=
argv
[
0
];
int
exitcode
=
0
;
while
(
argv
[
1
][
0
]
==
'-'
)
{
while
(
arg
c
>
1
&&
arg
v
[
1
][
0
]
==
'-'
)
{
if
(
strchr
(
argv
[
1
],
'a'
)
!=
0
)
if
(
strchr
(
argv
[
1
],
'a'
)
!=
0
)
allflag
=
true
;
allflag
=
true
;
if
(
strchr
(
argv
[
1
],
'c'
)
!=
0
)
if
(
strchr
(
argv
[
1
],
'c'
)
!=
0
)
checkonly
=
true
;
checkonly
=
true
;
if
(
strchr
(
argv
[
1
],
'e'
)
!=
0
)
equalcontents
=
true
;
if
(
strchr
(
argv
[
1
],
'q'
)
!=
0
)
okquiet
=
true
;
if
(
strchr
(
argv
[
1
],
'h'
)
!=
0
||
strchr
(
argv
[
1
],
'?'
)
!=
0
)
{
usage
();
return
0
;
}
argc
--
,
argv
++
;
argc
--
,
argv
++
;
}
}
const
char
*
prevfilename
=
0
;
Uint32
*
prevbuf
=
0
;
Uint32
prevbytes
=
0
;
while
(
argc
>
1
)
{
while
(
argc
>
1
)
{
const
char
*
filename
=
argv
[
1
];
const
char
*
filename
=
argv
[
1
];
argc
--
,
argv
++
;
argc
--
,
argv
++
;
...
@@ -173,8 +207,9 @@ NDB_COMMAND(printSchemafile,
...
@@ -173,8 +207,9 @@ NDB_COMMAND(printSchemafile,
struct
stat
sbuf
;
struct
stat
sbuf
;
const
int
res
=
stat
(
filename
,
&
sbuf
);
const
int
res
=
stat
(
filename
,
&
sbuf
);
if
(
res
!=
0
)
{
if
(
res
!=
0
)
{
ndbout
<<
"Could not find file:
\"
"
<<
filename
<<
"
\"
"
<<
endl
;
ndbout
<<
filename
<<
": not found errno="
<<
errno
<<
endl
;
return
1
;
exitcode
=
1
;
continue
;
}
}
const
Uint32
bytes
=
sbuf
.
st_size
;
const
Uint32
bytes
=
sbuf
.
st_size
;
...
@@ -182,25 +217,56 @@ NDB_COMMAND(printSchemafile,
...
@@ -182,25 +217,56 @@ NDB_COMMAND(printSchemafile,
FILE
*
f
=
fopen
(
filename
,
"rb"
);
FILE
*
f
=
fopen
(
filename
,
"rb"
);
if
(
f
==
0
)
{
if
(
f
==
0
)
{
ndbout
<<
"Failed to open file"
<<
endl
;
ndbout
<<
filename
<<
": open failed errno="
<<
errno
<<
endl
;
delete
[]
buf
;
delete
[]
buf
;
return
1
;
exitcode
=
1
;
continue
;
}
}
Uint32
sz
=
fread
(
buf
,
1
,
bytes
,
f
);
Uint32
sz
=
fread
(
buf
,
1
,
bytes
,
f
);
fclose
(
f
);
fclose
(
f
);
if
(
sz
!=
bytes
)
{
if
(
sz
!=
bytes
)
{
ndbout
<<
"Failure while reading file"
<<
endl
;
ndbout
<<
filename
<<
": read failed errno="
<<
errno
<<
endl
;
delete
[]
buf
;
exitcode
=
1
;
continue
;
}
if
(
sz
<
32
)
{
ndbout
<<
filename
<<
": too short (no header)"
<<
endl
;
delete
[]
buf
;
delete
[]
buf
;
return
1
;
exitcode
=
1
;
continue
;
}
}
SchemaFile
*
sf
=
(
SchemaFile
*
)
&
buf
[
0
];
SchemaFile
*
sf
=
(
SchemaFile
*
)
&
buf
[
0
];
int
ret
;
if
(
sf
->
NdbVersion
<
NDB_SF_VERSION_5_0_6
)
if
(
sf
->
NdbVersion
<
NDB_SF_VERSION_5_0_6
)
print_old
(
filename
,
sf
);
ret
=
print_old
(
filename
,
sf
,
sz
);
else
else
print
(
filename
,
sf
,
sz
);
ret
=
print
(
filename
,
sf
,
sz
);
delete
[]
buf
;
if
(
ret
!=
0
)
{
ndbout
<<
filename
<<
": check failed"
<<
" version="
<<
version
(
sf
->
NdbVersion
)
<<
endl
;
exitcode
=
1
;
}
else
if
(
!
okquiet
)
{
ndbout
<<
filename
<<
": ok"
<<
" version="
<<
version
(
sf
->
NdbVersion
)
<<
endl
;
}
if
(
equalcontents
&&
prevfilename
!=
0
)
{
if
(
prevbytes
!=
bytes
||
memcmp
(
prevbuf
,
buf
,
bytes
)
!=
0
)
{
ndbout
<<
filename
<<
": differs from "
<<
prevfilename
<<
endl
;
exitcode
=
1
;
}
}
prevfilename
=
filename
;
delete
[]
prevbuf
;
prevbuf
=
buf
;
prevbytes
=
bytes
;
}
}
return
xitcode
;
delete
[]
prevbuf
;
return
exitcode
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment