[ZBX-5307] PHP runs out of memory when creating complex templates Created: 2012 Jul 11  Updated: 2017 May 30  Resolved: 2012 Aug 02

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: API (A), Frontend (F)
Affects Version/s: 2.1.0
Fix Version/s: 2.0.3rc1, 2.1.0

Type: Incident report Priority: Blocker
Reporter: Pavels Jelisejevs (Inactive) Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: database, dependencies, template, trigger
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: XML File zbx_export_templates(3).xml    

 Description   

I have a template, that has two parent templates with trigger dependencies between the parent templates. When I'm trying to import the templates from zbx_export_templates(3).xml PHP runs out of memory. I suspect this is caused by trigger dependencies.

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 41 bytes) in /opt/lampp/htdocs/zabbix/trunk/frontends/php/include/classes/debug/CProfiler.php on line 232
Call Stack

  1. Time Memory Function Location
    1 0.0006 373020 {main}

    ( ) ../conf.import.php:0
    2 0.1514 8089600 CConfigurationImport->import( ) ../conf.import.php:130
    3 1.0412 21862848 CConfigurationImport->processTriggers( ) ../CConfigurationImport.php:157
    4 1.8153 28655488 CAPIObject->update( ) ../CConfigurationImport.php:970
    5 1.8153 28655676 CAPIObject->__call( ) ../CConfigurationImport.php:970
    6 1.8154 28656092 czbxrpc::call( ) ../CAPIObject.php:35
    7 1.8155 28658128 czbxrpc::callAPI( ) ../class.czbxrpc.php:64
    8 1.8156 28658680 call_user_func ( ) ../class.czbxrpc.php:106
    9 1.8156 28658696 CTrigger->update( ) ../class.czbxrpc.php:106
    10 2.2226 31307052 CTrigger->addDependencies( ) ../CTrigger.php:1308
    11 2.2296 31421104 CTrigger->addDependencies( ) ../CTrigger.php:1478
    12 2.2460 31726992 CTrigger->addDependencies( ) ../CTrigger.php:1478
    13 2.2460 31727152 CTrigger->validateAddDependencies( ) ../CTrigger.php:1445
    14 2.2461 31727700 CTrigger->checkDependencies( ) ../CTrigger.php:1431
    15 18.6377 268279632 DBselect( ) ../CTrigger.php:1847
    16 18.6381 268280984 CProfiler->profileSql( ) ../db.inc.php:485
    17 18.6382 268281216 debug_backtrace ( ) ../CProfiler.php:232

After that the database becomes locked and an attempt to update something in the frontend results in errors like:

Error in query [SELECT nextid FROM ids WHERE nodeid=0 AND table_name='hosts' AND field_name='hostid' FOR UPDATE] [Lock wait timeout exceeded; try restarting transaction]
mysql_fetch_assoc() expects parameter 1 to be resource, boolean given [include/db.inc.php:569]
mysql_free_result() expects parameter 1 to be resource, boolean given [include/db.inc.php:570]
Error in query [DELETE FROM ids WHERE nodeid=0 AND table_name='hosts' AND field_name='hostid'] [Lock wait timeout exceeded; try restarting transaction]
DBEXECUTE_ERROR



 Comments   
Comment by Pavels Jelisejevs (Inactive) [ 2012 Jul 30 ]

In trunk r29197 PHP does not run out of memory, but the import fails with the following errors:

Invalid argument supplied for foreach() [include/classes/import/CConfigurationImport.php:269]
Created: Item "super-super-item1" on "super-template1".
Created: Item "super-super-item1" on "template1".
Created: Trigger "super-super-template-trigger1-1" on "super-template1".
Created: Trigger "super-super-template-trigger1-1" on "template1".
Created: Item "super-super-template-item1" on "super-super-template1-1".
Created: Item "super-super-template-item2" on "super-super-template1-2".
Created: Item "super-template-item1" on "super-template1".
Created: Item "super-super-template-item1" on "super-template1".
Created: Item "super-super-template-item2" on "super-template1".
Created: Item "super-template-item1" on "template1".
Created: Item "super-super-template-item1" on "template1".
Created: Item "super-super-template-item2" on "template1".
Created: Discovery rule "super-super-lld" on "super-super-template1-1".
Created: Discovery rule "super-super-lld" on "super-template1".
Created: Discovery rule "super-super-lld" on "template1".
Invalid argument supplied for foreach() [include/classes/import/CConfigurationImport.php:684]
Created: Item prototype "super-super-lld-item" on "super-super-template1-1".
Created: Item prototype "super-super-lld-item" on "super-template1".
Created: Item prototype "super-super-lld-item" on "template1".
Created: Trigger prototype "super-super-lld-triggeR" on "super-super-template1-1".
Created: Trigger prototype "super-super-lld-triggeRR" on "super-super-template1-1".
Created: Trigger prototype "super-super-lld-triggeR" on "super-template1".
Created: Trigger prototype "super-super-lld-triggeR" on "template1".
Created: Trigger prototype "super-super-lld-triggeRR" on "super-template1".
Created: Trigger prototype "super-super-lld-triggeRR" on "template1".
Created: Trigger "super-super-template-trigger11-1" on "super-super-template1-1".
Created: Trigger "super-super-template-trigger11-2" on "super-super-template1-1".
Created: Trigger "super-super-template-trigger12-1" on "super-super-template1-2".
Created: Trigger "super-super-template-trigger12-2" on "super-super-template1-2".
Created: Trigger "super-template-trigger1" on "super-template1".
Created: Trigger "super-super-template-trigger11-1" on "super-template1".
Created: Trigger "super-super-template-trigger11-1" on "template1".
Created: Trigger "super-super-template-trigger11-2" on "super-template1".
Created: Trigger "super-super-template-trigger11-2" on "template1".
Created: Trigger "super-super-template-trigger12-1" on "super-template1".
Created: Trigger "super-super-template-trigger12-1" on "template1".
Created: Trigger "super-super-template-trigger12-2" on "super-template1".
Created: Trigger "super-super-template-trigger12-2" on "template1".
Created: Trigger "super-template-trigger1" on "template1".
Updated: Trigger "super-super-template-trigger11-2" on "super-super-template1-1".
Updated: Trigger "super-super-template-trigger12-1" on "super-super-template1-2".
Updated: Trigger "super-super-template-trigger12-2" on "super-super-template1-2".
Updated: Trigger "super-super-template-trigger11-2" on "super-template1".
Updated: Trigger "super-super-template-trigger11-2" on "template1".
Incorrect value "" for unsigned int field "triggerid_up".

<pavels> The problem was that a trigger in the import file was dependent on a trigger, that did not exist in my configuration. That caused the final "Incorrect value "" for unsigned int field "triggerid_up"." error. The undefined indexes appeared, because item prototype applications were not being formatted properly. RESOLVED.

Comment by Pavels Jelisejevs (Inactive) [ 2012 Jul 31 ]

The reason for the error is that now it's possible to create a dependency from a templated trigger, to the inherited trigger on a host, resulting in a circular dependency on the host trigger. I've added a validation rule to prevent such errors.

RESOLVED.

Comment by Toms (Inactive) [ 2012 Aug 01 ]

(1) There is possibility to create incorrect dependency:

  • create template with two triggers;
  • create host and link template to it;
  • create dependency within host from first trigger to second;
  • create dependency within template from second trigger to first.

To see that this is wrong, you can try to open one of trigger within host and try saving it without changes.

<pavels> RESOLVED.

<Toms> CLOSED

Comment by Toms (Inactive) [ 2012 Aug 01 ]

(2) To not get an undefined index in foreach loop, there should be if statement prior that loop, not assigning empty array at some point elsewhere.

plus CArrayHelper::convertFieldToArray($prototype, 'applications') in C20ImportFormatter.php line 304 makes unnecessary array_values().

<pavels> The whole point of the import formatter classes is to return imported data in a standard normalized form, so that import can handle it no matter what import format or version has been used. So if some import file does not contain some objects, it has to return an array, not an empty string, a null or whatever.

The array_values() call is needed to reset the keys of the application array to zero based numeric case, from whatever format they may be given in.

<Toms> OK, it's little overhead to get more structured format to not get any errors in future development. CLOSED

Comment by Toms (Inactive) [ 2012 Aug 01 ]

(3) CTrigger.php line 1821 ... $triggerTemplates = API::Template()->get(array( ... those are not trigger template but rather trigger dependency templates.

following 'output' => array('status'), is unnecessery

<pavels> RESOLVED.

<Toms> CLOSED

Comment by Toms (Inactive) [ 2012 Aug 01 ]

(4) CTrigger.php line 1861 ... instead of get_hosts_by_triggerid() there should be a direct SQL function get_templates_by_triggerid() fetching only templates

<pavels> RESOLVED.

<Toms> CLOSED

Comment by Toms (Inactive) [ 2012 Aug 01 ]

(5) CTrigger.php line 1896 ... loop should be executed only if $setWithDep is true ... so it should be inside previous loop

<pavels> RESOLVED.

<Toms> CLOSED

Comment by Toms (Inactive) [ 2012 Aug 01 ]

(6) possible undefined $depTriggerIds in checkDependencyParents()

$parentDepTriggers I have a feeling that this is more like dependency parent trigger, rather than parent dependency trigger

<pavels> RESOLVED.

<Toms> CLOSED

Comment by Toms (Inactive) [ 2012 Aug 02 ]

TESTED

Comment by Pavels Jelisejevs (Inactive) [ 2012 Aug 02 ]

Fixed in 2.0.3rc1 r29382 and 2.1.0 r29382.

CLOSED.

Generated at Fri Apr 26 14:19:19 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.