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
4f82c413
Commit
4f82c413
authored
May 08, 2017
by
Gary Wong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace 20 lines of buggy Perl with a single (less buggy?) SQL query.
parent
937c6efa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
23 deletions
+13
-23
db/Reservation.pm.in
db/Reservation.pm.in
+13
-23
No files found.
db/Reservation.pm.in
View file @
4f82c413
...
...
@@ -965,32 +965,22 @@ sub CurrentReservations($$) {
# reject illegal PIDs
return undef unless /^[-\w]+$/;
}
my $query_result = DBQueryFatal( "SELECT DISTINCT(type) FROM " .
"future_reservations WHERE pid IN ('
" .
join( "
','
", @$projlist ) . "
')" );
while( my($type) = $query_result->fetchrow_array() ) {
my $reservations = LookupAll( $class, $type );
my @forecast = ();
IsFeasible( $class, $reservations, undef, undef, undef, undef,
\@forecast );
my $query_result = DBQueryFatal(
"SELECT q.*, COUNT(*) AS used FROM (" .
"SELECT pid, type, SUM( nodes ) AS reserved FROM " .
"future_reservations WHERE start <= NOW() AND end > NOW() " .
"GROUP BY pid, type) AS q ".
"LEFT OUTER JOIN reserved AS r ON q.pid=r.pid " .
"INNER JOIN nodes AS n ON r.node_id=n.node_id WHERE " .
"n.type=q.type GROUP BY q.pid, q.type" );
foreach my $f ( @forecast ) {
foreach my $pid ( keys ( %{$f->{'
reserved
'}} ) ) {
if( grep( $_ eq $pid, @$projlist ) ) {
last if( $f->{'
t
'} > time );
push( @answer, { '
pid
' => $pid, '
nodetype
' => $type,
'
reserved
' => $f->{'
reserved
'}->{$pid},
'
used
' => $f->{'
used
'}->{$pid} } );
}
}
}
while( my($pid, $type, $reserved, $used) =
$query_result->fetchrow_array() ) {
push( @answer, { '
pid
' => $pid, '
nodetype
' => $type,
'
reserved
' => $reserved, '
used
' => $used } );
}
return @answer;
}
...
...
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