fixes for race conditions and dupes in job queue
we had situations where the manager would start workers on the same job, either because of race conditions or because at the time of queueing it wasn't known that the jobs were targeting the same device (due to device aliases). this commit removes duplicate jobs, reduces the need for locking on the job queue, and makes use of lldpRemChassisId to try to deduplicate jobs before they are started. in effect we have several goes to prevent duplicate jobs: 1. at neighbor discovery time we try to skip queueing same lldpRemChassisId 2. at job selection we 'error out' jobs with same profile as job selected 3. at job selection we check for running job with same profile as selected 4. the job manager process also checks for duplicate job profiles 5. at job lock we abort if the job was 'errored out' all together this seems to work well. a test on a large university network of 303 devices (four core routers and the rest edge routers, runing VRF with many duplicate identities), ~1200 subnets, ~50k hosts, resulted in no DB deadlock or contention and a complete discover+arpnip+macsuck (909 jobs) in ~3 minutes (with ~150 duplicate jobs identified and skipped).
This commit is contained in:
@@ -72,6 +72,10 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
|
||||
$device->renumber($new_ip)
|
||||
or die "cannot renumber to: $new_ip"; # rollback
|
||||
|
||||
# is not done in renumber but required otherwise confusing at job end!
|
||||
schema('netdisco')->resultset('Admin')
|
||||
->find({job => $job->id})->update({device => $new_ip});
|
||||
|
||||
return Status->noop(sprintf ' [%s] device - changed IP to %s (%s)',
|
||||
$old_ip, $device->ip, ($device->dns || ''));
|
||||
});
|
||||
|
||||
@@ -39,11 +39,13 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
|
||||
or return Status->defer("discover failed: could not SNMP connect to $device");
|
||||
|
||||
my @to_discover = store_neighbors($device);
|
||||
my %seen_id = ();
|
||||
|
||||
# only enqueue if device is not already discovered,
|
||||
# discover_* config permits the discovery
|
||||
foreach my $neighbor (@to_discover) {
|
||||
my ($ip, $remote_type) = @$neighbor;
|
||||
my ($ip, $remote_type, $remote_id) = @$neighbor;
|
||||
next if $remote_id and $seen_id{ $remote_id }++;
|
||||
|
||||
my $device = get_device($ip);
|
||||
next if $device->in_storage;
|
||||
@@ -55,10 +57,14 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
|
||||
next;
|
||||
}
|
||||
|
||||
# risk of things going wrong...?
|
||||
# https://quickview.cloudapps.cisco.com/quickview/bug/CSCur12254
|
||||
|
||||
jq_insert({
|
||||
device => $ip,
|
||||
action => 'discover',
|
||||
subaction => 'with-nodes',
|
||||
($remote_id ? (device_key => $remote_id) : ()),
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -171,7 +177,7 @@ sub store_neighbors {
|
||||
# useable remote IP...
|
||||
|
||||
if ($remote_ip eq '0.0.0.0' or
|
||||
check_acl_no($remote_ip, 'group:__LOCAL_ADDRESSES__')) {
|
||||
check_acl_no($remote_ip, 'group:__LOCAL_ADDRESSES__')) {
|
||||
|
||||
if ($remote_id) {
|
||||
my $devices = schema('netdisco')->resultset('Device');
|
||||
@@ -228,7 +234,7 @@ sub store_neighbors {
|
||||
debug sprintf
|
||||
' [%s] neigh - adding neighbor %s, type [%s], on %s to discovery queue',
|
||||
$device->ip, $remote_ip, ($remote_type || ''), $port;
|
||||
push @to_discover, [$remote_ip, $remote_type];
|
||||
push @to_discover, [$remote_ip, $remote_type, $remote_id];
|
||||
|
||||
$remote_port = $c_port->{$entry};
|
||||
if (defined $remote_port) {
|
||||
|
||||
Reference in New Issue
Block a user