Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
emulab-devel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
143
Issues
143
List
Boards
Labels
Service Desk
Milestones
Merge Requests
6
Merge Requests
6
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
emulab
emulab-devel
Commits
d970b69b
Commit
d970b69b
authored
Jan 21, 2009
by
Leigh B. Stoller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More little tweaks and changes for the upcoming change to how DB
updates are done.
parent
65a84af9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
27 deletions
+71
-27
db/GNUmakefile.in
db/GNUmakefile.in
+2
-1
db/dbupdate.in
db/dbupdate.in
+51
-17
db/emdbi.pm.in
db/emdbi.pm.in
+16
-8
db/libdb.pm.in
db/libdb.pm.in
+2
-1
No files found.
db/GNUmakefile.in
View file @
d970b69b
...
...
@@ -17,7 +17,8 @@ SBIN_SCRIPTS = avail inuse showgraph if2port backup webcontrol node_status \
dbcheck interswitch dbboot grabron stategraph newwanode \
idletimes idlemail setsitevar audit changeuid changepid \
elabinelab_bossinit update_permissions mysqld_watchdog \
dumperrorlog changeleader checkstats changecreator
dumperrorlog changeleader checkstats changecreator \
dbupdate
WEB_SBIN_SCRIPTS= webnodelog webnewwanode webidlemail webchangeuid \
webchangeleader
...
...
db/dbupdate.in
View file @
d970b69b
...
...
@@ -13,11 +13,13 @@ use Getopt::Std;
#
sub
usage
()
{
print
STDERR
"
Usage: dbupdate <dbname> [<version>]
\n
";
print
STDERR
"
Usage: dbupdate
[-s | -f]
<dbname> [<version>]
\n
";
exit
(
-
1
);
}
my
$optlist
=
"
d
";
my
$optlist
=
"
d
sf
";
my
$debug
=
0
;
my
$force
=
0
;
my
$single
=
0
;
my
$dbname
;
my
$version
;
my
$dbnumber
=
0
;
# XXX Core emulab code is very rigid.
...
...
@@ -57,6 +59,15 @@ if (! getopts($optlist, \%options)) {
if
(
defined
(
$options
{"
d
"}))
{
$debug
=
1
;
}
if
(
defined
(
$options
{"
f
"}))
{
$force
=
1
;
}
if
(
defined
(
$options
{"
s
"}))
{
$single
=
1
;
if
(
@ARGV
!=
2
)
{
Fatal
("
Must provide a version argument when using -s option
");
}
}
if
(
@ARGV
<
1
||
@ARGV
>
2
)
{
usage
();
}
...
...
@@ -88,12 +99,23 @@ else {
#
if
(
!
defined
(
$version
))
{
my
$query_result
=
emdbi::
DBQueryFatalN
(
$dbnumber
,
"
select value from version_info
"
.
"
where name='dbrev'
");
Fatal
("
No version info in the DB
")
if
(
!
$query_result
->
numrows
);
(
$version
)
=
$query_result
->
fetchrow_array
();
emdbi::
DBQueryN
(
$dbnumber
,
"
select value from version_info
"
.
"
where name='dbrev'
");
if
(
!
$query_result
)
{
if
(
$dbname
eq
$DEFDBNAME
)
{
$version
=
"
4.0
";
}
else
{
$version
=
"
1.0
";
}
}
elsif
(
!
$query_result
->
numrows
)
{
Fatal
("
No version info in the DB
");
}
else
{
(
$version
)
=
$query_result
->
fetchrow_array
();
}
}
if
(
!
(
$version
=~
/^[\d\.]+$/
))
{
Fatal
("
'
$version
' does not look like a reasonable starting version.
");
...
...
@@ -116,14 +138,23 @@ if (@dots) {
Fatal
("
Cannot chdir to
$dir
");
}
}
my
@files
;
#
# Open up the current directory. We want all numbered files.
#
opendir
(
DIR
,
"
.
")
or
Fatal
("
Could not opendir the current directory
");
my
@files
=
grep
{
/^\d*$/
}
readdir
(
DIR
);
closedir
(
DIR
);
if
(
$single
)
{
Fatal
("
Update file
$start
does not exist
")
if
(
!
-
e
$start
);
# Just the one file.
@files
=
(
$start
);
}
else
{
#
# Open up the current directory. We want all numbered files.
#
opendir
(
DIR
,
"
.
")
or
Fatal
("
Could not opendir the current directory
");
@files
=
grep
{
/^\d*$/
}
readdir
(
DIR
);
closedir
(
DIR
);
}
#
# Sort them since we we want to start at the right file, and proceed
...
...
@@ -136,7 +167,9 @@ closedir(DIR);
#
foreach
my
$file
(
@files
)
{
next
if
(
$file
<=
$start
);
if
(
!
$force
&&
!
$single
&&
$file
<=
$start
);
next
if
(
$single
&&
$file
!=
$start
);
my
$fullpath
=
join
("
/
",
@dots
)
.
"
/
$file
";
my
$revision
=
join
("
.
",
@dots
)
.
"
.
$file
";
...
...
@@ -159,7 +192,8 @@ foreach my $file (@files) {
# Mark that we have done it.
emdbi::
DBQueryFatalN
(
$dbnumber
,
"
update version_info set value='
$revision
'
"
.
"
where name='dbrev'
");
"
where name='dbrev'
")
if
(
!
$single
&&
!
$force
);
}
exit
(
0
);
...
...
db/emdbi.pm.in
View file @
d970b69b
...
...
@@ -433,11 +433,8 @@ sub DBTableExistsN($$)
my($dbnum, $table) = @_;
my $result =
DBQueryN($dbnum, "
show
tables
like
'$table'
");
DBQuery
Fatal
N($dbnum, "
show
tables
like
'$table'
");
if (! $result) {
DBWarn("
DB
Query
failed
");
}
return $result->numrows;
}
sub DBTableExists($) { return DBTableExistsN(0,$_[0]); }
...
...
@@ -447,15 +444,26 @@ sub DBSlotExistsN($$$)
my($dbnum, $table, $slot) = @_;
my $result =
DBQueryN($dbnum, "
show
columns
from
`$
table
`
like
'$slot'
");
DBQuery
Fatal
N($dbnum, "
show
columns
from
`$
table
`
like
'$slot'
");
if (! $result) {
DBWarn("
DB
Query
failed
");
}
return $result->numrows;
}
sub DBSlotExists($$) { return DBSlotExistsN(0,$_[0],$_[1]); }
sub DBSlotTypeN($$$)
{
my($dbnum, $table, $slot) = @_;
my $result =
DBQueryFatalN($dbnum, "
show
columns
from
`$
table
`
like
'$slot'
");
return undef
if (! $result->numrows);
my $row = $result->fetchrow_hashref();
return $row->{'Type'};
}
sub DBSlotType($$) { return DBSlotTypeN(0,$_[0],$_[1]); }
END {
# Call it here otherwise may get:
# (in cleanup) Can't call method "
FETCH
" on an undefined value at
...
...
db/libdb.pm.in
View file @
d970b69b
...
...
@@ -163,7 +163,7 @@ use vars qw(@ISA @EXPORT);
DBQuery DBQueryFatal DBQueryWarn DBWarn DBFatal DBErr
NewTBDBHandle DBQueryN DBQueryFatalN DBQueryWarnN DBErrN
DBQuerySingleFatal DBQuerySingleFatalN
DBTableExists DBSlotExists
DBTableExists DBSlotExists
DBSlotType
DBQuoteSpecial ExpState
ExpNodes ExpNodeVnames ExpNodesOldReserved
DBDateTime DefaultImageID
...
...
@@ -304,6 +304,7 @@ sub DBErrN($) { return emdbi::DBErrN($_[0]); }
sub DBErr() { return emdbi::DBErr(); }
sub DBTableExists($) { return emdbi::DBTableExists($_[0]); }
sub DBSlotExists($$) { return emdbi::DBSlotExists($_[0], $_[1]); }
sub DBSlotType($$) { return emdbi::DBSlotType($_[0], $_[1]); }
# These are handled differently cause of tblog stuff.
sub DBWarn($;$) { DBError(\&tbwarn, $_[0], $_[1]); }
sub DBFatal($;$) { DBError(\&tbdie, $_[0], $_[1]); }
...
...
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