Skip to content

Commit 84fcbca

Browse files
author
garnier-quentin
committed
+ Enchance centreond-acl (bulk request)
1 parent 2a2d7d6 commit 84fcbca

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

bin/centreond/centreond.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ resync_random_windows=7200
7474
; set to 1 to disable - if you want to do it by a cron
7575
resync_auto_disable=0
7676
sql_fetch=10000
77+
sql_bulk=2000
7778

7879
[centreondcron]
7980
module=modules::centreondcron::hooks

bin/centreond/modules/centreondacl/class.pm

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -279,22 +279,54 @@ sub insert_result {
279279
return 1;
280280
}
281281
}
282+
if (!defined($options{hs_sth})) {
283+
$self->{db_centreon}->commit();
284+
return 0;
285+
}
282286

283287
# In Oracle 11: IGNORE_ROW_ON_DUPKEY_INDEX
284288
# MS SQL: IGNORE_DUP_KEY
285289
# Postgres: ???
286-
($status, $sth) = $self->{db_centreon}->query('INSERT IGNORE INTO cfg_acl_resources_cache VALUES (' . $self->{organization_id} . ', ' . $options{acl_resource_id} . ', ?, ?)', prepare_only => 1);
290+
my $prepare_str = '(' . $self->{organization_id} . ', ' . $options{acl_resource_id} . ', ?, ?)';
291+
for (my $i = 1; $i < $self->{config}{sql_bulk}; $i++) {
292+
$prepare_str .= ', (' . $self->{organization_id} . ', ' . $options{acl_resource_id} . ', ?, ?)';
293+
}
294+
($status, $sth) = $self->{db_centreon}->query('INSERT IGNORE INTO cfg_acl_resources_cache VALUES ' . $prepare_str, prepare_only => 1);
287295
my $rows = [];
288296
my %host_insert = ();
289297
my $i = 0;
298+
my @array_binds = ();
290299
while (my $row = ( shift(@$rows) || # get row from cache, or reload cache:
291300
shift(@{$rows = $options{hs_sth}->fetchall_arrayref(undef, $self->{config}{sql_fetch})||[]})) ) {
292-
$i++;
301+
293302
if (!defined($host_insert{$$row[0]})) {
294303
$host_insert{$$row[0]} = 1;
295-
return 1 if ($self->insert_execute(sth => $sth, bind => [1, $$row[0]]));
304+
push @array_binds, 1, $$row[0];
305+
$i++;
306+
if ($i == $self->{config}{sql_bulk}) {
307+
return 1 if ($self->insert_execute(sth => $sth, bind => \@array_binds));
308+
$i = 0;
309+
@array_binds = ();
310+
}
296311
}
297-
return 1 if ($self->insert_execute(sth => $sth, bind => [2, $$row[1]]));
312+
313+
push @array_binds, 2, $$row[1];
314+
$i++;
315+
if ($i == $self->{config}{sql_bulk}) {
316+
return 1 if ($self->insert_execute(sth => $sth, bind => \@array_binds));
317+
$i = 0;
318+
@array_binds = ();
319+
}
320+
}
321+
322+
if (scalar(@array_binds) > 0) {
323+
my $query = 'INSERT IGNORE INTO cfg_acl_resources_cache VALUES (' . $self->{organization_id} . ', ' . $options{acl_resource_id} . ', ?, ?)';
324+
my $num = scalar(@array_binds) / 2;
325+
for (my $i = 1; $i < $num; $i++) {
326+
$query .= ', (' . $self->{organization_id} . ', ' . $options{acl_resource_id} . ', ?, ?)';
327+
}
328+
($status, $sth) = $self->{db_centreon}->query($query, prepare_only => 1);
329+
return 1 if ($self->insert_execute(sth => $sth, bind => \@array_binds));
298330
}
299331

300332
$self->{db_centreon}->commit();
@@ -318,11 +350,6 @@ sub action_aclresync {
318350
return 1;
319351
}
320352

321-
if ($status == 2) {
322-
$self->{logger}->writeLogDebug("centreondacl: organization $self->{organization_id} acl resource $acl_resource_id : finished resync (emtpy resource)");
323-
next;
324-
}
325-
326353
$status = $self->insert_result(acl_resource_id => $acl_resource_id, hs_sth => $sth, first_request => "DELETE FROM cfg_acl_resources_cache WHERE organization_id = '" . $self->{organization_id} . "' AND acl_resource_id = " . $acl_resource_id);
327354
$self->{logger}->writeLogDebug("centreondacl: organization $self->{organization_id} acl resource $acl_resource_id : finished resync (status: $status)");
328355
if ($status == 1) {
@@ -400,15 +427,15 @@ sub run {
400427
while (1) {
401428
# we try to do all we can
402429
my $rev = zmq_poll($self->{poll}, 5000);
403-
if ($rev == 0 && $self->{stop} == 1) {
430+
if (defined($rev) && $rev == 0 && $self->{stop} == 1) {
404431
$self->{logger}->writeLogInfo("centreond-acl $$ has quit");
405432
zmq_close($socket);
406433
exit(0);
407434
}
408435

409436
# Check if we need to quit
410437
if ($on_demand == 1) {
411-
if ($rev == 0) {
438+
if (defined($rev) && $rev == 0) {
412439
if (time() - $on_demand_time > $self->{config}{on_demand_time}) {
413440
$self->{logger}->writeLogInfo("centreond-acl $$ has quit");
414441
zmq_close($socket);

0 commit comments

Comments
 (0)