Commit 53c3748f authored by Leigh B Stoller's avatar Leigh B Stoller

Fix shared node interface bandwidth accounting bug. My multiple table

update/join was not doing what I expected, and it looks like I cannot
actually do what I was intended cause mixing multiple table update and
left join does not work like I expect (read: I cannot make any sense
of the mysql manual). So, recast as a multiple table update without
the join, over individual rows in the vinterfaces table.
parent 922fd527
......@@ -1690,20 +1690,33 @@ sub ReleaseSharedBandwidth($)
#
# A negative BW is not reserved yet.
#
if (!DBQueryWarn("update interface_state,vinterfaces set ".
" remaining_bandwidth=remaining_bandwidth+bandwidth ".
"where interface_state.node_id=vinterfaces.node_id and ".
" interface_state.iface=vinterfaces.iface and ".
" vinterfaces.vnode_id='$node_id' and ".
" vinterfaces.iface is not null and ".
" vinterfaces.bandwidth>0")) {
DBQueryWarn("unlock tables");
return -1;
}
if (!DBQueryWarn("update vinterfaces set bandwidth=0 ".
"where vinterfaces.vnode_id='$node_id'")) {
DBQueryWarn("unlock tables");
return -1;
my $query_result =
DBQueryWarn("select iface,unit from vinterfaces ".
"where vnode_id='$node_id' and ".
" iface is not null and ".
" bandwidth>0");
return -1
if (!$query_result);
return 0
if (!$query_result->numrows);
#
# For each vinterface indicating reserved bandwidth, atomically
# update interface_state adding back the bandwidth, and decrementing
# vinterface to indicate the bandwidth has been released.
#
while (my ($iface,$unit) = $query_result->fetchrow_array()) {
if (!DBQueryWarn("update interface_state,vinterfaces set ".
" remaining_bandwidth=remaining_bandwidth+bandwidth, ".
" bandwidth=0-bandwidth ".
"where interface_state.node_id=vinterfaces.node_id and ".
" interface_state.iface=vinterfaces.iface and ".
" vinterfaces.vnode_id='$node_id' and ".
" vinterfaces.iface='$iface' and ".
" vinterfaces.unit='$unit'")) {
DBQueryWarn("unlock tables");
return -1;
}
}
DBQueryWarn("unlock tables");
return 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment