#901 node_ip time_last can be before time_first

This commit is contained in:
Oliver Gorwits
2023-03-03 15:34:16 +00:00
parent 1d00ebc91e
commit 4bb9b25ae9
3 changed files with 35 additions and 18 deletions

View File

@@ -158,20 +158,27 @@ sub store_nbt {
my ( $hash_ref, $now ) = @_; my ( $hash_ref, $now ) = @_;
$now ||= 'LOCALTIMESTAMP'; $now ||= 'LOCALTIMESTAMP';
schema(vars->{'tenant'})->resultset('NodeNbt')->update_or_create( schema(vars->{'tenant'})->txn_do(sub {
{ mac => $hash_ref->{'mac'}, my $row = schema(vars->{'tenant'})->resultset('NodeNbt')->update_or_new(
ip => $hash_ref->{'ip'}, { mac => $hash_ref->{'mac'},
nbname => $hash_ref->{'nbname'}, ip => $hash_ref->{'ip'},
domain => $hash_ref->{'domain'}, nbname => $hash_ref->{'nbname'},
server => $hash_ref->{'server'}, domain => $hash_ref->{'domain'},
nbuser => $hash_ref->{'nbuser'}, server => $hash_ref->{'server'},
active => \'true', nbuser => $hash_ref->{'nbuser'},
time_last => \$now, active => \'true',
}, time_last => \$now,
{ key => 'primary', },
for => 'update', { key => 'primary',
} for => 'update',
); }
);
if (! $row->in_storage) {
$row->set_column(time_first => \$now);
$row->insert;
}
});
return; return;
} }

View File

@@ -176,13 +176,13 @@ sub store_arp {
debug sprintf 'store_arp - mac %s ip %s', $mac->as_ieee, $ip; debug sprintf 'store_arp - mac %s ip %s', $mac->as_ieee, $ip;
schema(vars->{'tenant'})->txn_do(sub { schema(vars->{'tenant'})->txn_do(sub {
my $current = schema(vars->{'tenant'})->resultset('NodeIp') schema(vars->{'tenant'})->resultset('NodeIp')
->search( ->search(
{ ip => $ip, -bool => 'active'}, { ip => $ip, -bool => 'active'},
{ columns => [qw/mac ip/] })->update({active => \'false'}); { columns => [qw/mac ip/] })->update({active => \'false'});
schema(vars->{'tenant'})->resultset('NodeIp') my $row = schema(vars->{'tenant'})->resultset('NodeIp')
->update_or_create( ->update_or_new(
{ {
mac => $mac->as_ieee, mac => $mac->as_ieee,
ip => $ip, ip => $ip,
@@ -194,6 +194,11 @@ sub store_arp {
key => 'primary', key => 'primary',
for => 'update', for => 'update',
}); });
if (! $row->in_storage) {
$row->set_column(time_first => \$now);
$row->insert;
}
}); });
} }

View File

@@ -249,7 +249,7 @@ sub store_node {
})->update( { active => \'false' } ); })->update( { active => \'false' } );
# new data # new data
$nodes->update_or_create( my $row = $nodes->update_or_new(
{ {
switch => $ip, switch => $ip,
port => $port, port => $port,
@@ -265,6 +265,11 @@ sub store_node {
for => 'update', for => 'update',
} }
); );
if (! $row->in_storage) {
$row->set_column(time_first => \$now);
$row->insert;
}
}); });
} }