Commit 84ea58dc authored by Mike Hibler's avatar Mike Hibler
Browse files

(Hopefully) temporary hack to detect null chars in node_ids in the nodes table.

This is completely reactive and based on no reasoning. A common case of the
somebodys-been-messin-with-my-memory bug, is that we start seeing node_ids
with null chars at the end. Here we will send a stack trace to testbed-ops
if this happens (and we strip off the null). I am hoping to narrow down
where this happens.
parent e635ecee
......@@ -32,7 +32,7 @@ use Data::Dumper;
use overload ('""' => 'Stringify');
use vars qw($NODEROLE_TESTNODE $MFS_INITIAL $STATE_INITIAL
%nodes @cleantables);
%nodes @cleantables %carped);
# Exported defs
$NODEROLE_TESTNODE = 'testnode';
......@@ -43,6 +43,35 @@ $NODEROLE_TESTNODE = 'testnode';
# Cache of instances to avoid regenerating them.
%nodes = ();
# Sorry, one carp per customer...
%carped = ();
#
# XXX debugging
# Find out where nulls at end of strings are coming from
#
sub checknodeid($$)
{
my ($nid,$msg) = @_;
if ($nid =~ /^(.*)\x0/) {
$nid = $1;
if (!exists($carped{$nid}) && open(MAIL, "| /usr/sbin/sendmail -t")) {
$carped{$nid} = 1;
require Carp;
my $TBOPS = "@TBOPSEMAIL@";
print MAIL "To: $TBOPS\n";
print MAIL "Subject: NUL in node_id '$nid'\n";
print MAIL "$msg\n";
print MAIL "\n";
print MAIL Carp::longmess();
print MAIL "\n";
close(MAIL);
}
}
return $nid;
}
# Little helper and debug function.
sub mysystem($)
{
......@@ -53,7 +82,7 @@ sub mysystem($)
return system($command);
}
# To avoid writting out all the methods.
# To avoid writing out all the methods.
AUTOLOAD {
# print STDERR "$AUTOLOAD $_[0]\n";
......@@ -118,9 +147,18 @@ sub Lookup($$)
return undef;
}
# XXX debug
$nodeid = checknodeid($nodeid, "Argument");
# Look in cache first
return $nodes{$nodeid}
if (exists($nodes{$nodeid}));
if (exists($nodes{$nodeid})) {
# XXX debug
my $row = $nodes{$nodeid}->{"DBROW"};
$row->{'node_id'} = checknodeid($row->{'node_id'}, "Cache");
return $nodes{$nodeid};
}
my $query_result =
DBQueryWarn("select * from nodes as n ".
......@@ -139,6 +177,10 @@ sub Lookup($$)
$self->{"HASH"} = {};
bless($self, $class);
# XXX debug
my $row = $self->{"DBROW"};
$nodeid = checknodeid($row->{'node_id'}, "From DB");
# Add to cache.
$nodes{$nodeid} = $self;
return $self;
......@@ -157,6 +199,12 @@ sub DESTROY {
$self->{"WAROW"} = undef;
}
sub node_id($)
{
my $self = shift;
return checknodeid($self->{"DBROW"}->{'node_id'}, "node_id method");
}
#
# Stringify for output.
#
......@@ -220,7 +268,7 @@ sub BulkLookup($$$)
if (!defined($query_result));
while (my $row = $query_result->fetchrow_hashref()) {
my $nodeid = $row->{'node_id'};
my $nodeid = checknodeid($row->{'node_id'}, "BulkLookup method I");
my $node;
if (exists($nodes{$nodeid})) {
......@@ -252,7 +300,7 @@ sub BulkLookup($$$)
if (!defined($query_result));
while (my $row = $query_result->fetchrow_hashref()) {
my $nodeid = $row->{'node_id'};
my $nodeid = checknodeid($row->{'node_id'}, "BulkLookup method II");
my $node = $nodelist{$nodeid};
return -1
......@@ -269,7 +317,7 @@ sub BulkLookup($$$)
if (!defined($query_result));
while (my $row = $query_result->fetchrow_hashref()) {
my $nodeid = $row->{'node_id'};
my $nodeid = checknodeid($row->{'node_id'}, "BulkLookup method III");
my $key = $row->{'attrkey'};
my $node = $nodelist{$nodeid};
......@@ -539,6 +587,11 @@ sub Refresh($)
if (!$query_result || !$query_result->numrows);
$self->{"DBROW"} = $query_result->fetchrow_hashref();
# XXX debug
my $row = $nodes{$nodeid}->{"DBROW"};
$row->{'node_id'} = checknodeid($row->{'node_id'}, "Refresh");
# Force reload
$self->{"RSRV"} = undef;
$self->{"TYPEINFO"} = undef;
......
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