Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-3920

trigger addDependencies() creates duplicates

XMLWordPrintable

    • Icon: Incident report Incident report
    • Resolution: Fixed
    • Icon: Minor Minor
    • 2.0.4rc1, 2.1.0
    • 1.8.4
    • API (A)
    • MySQL RDBMS using InnoDB engine for tables

      The API method trigger.addDependencies does not check whether dependencies exist prior to adding them, and there is no unique constraint across trigger_depends.triggerid_up and trigger_depends.triggerid_down to prevent the addition.

      We had poorly written code that was unconditionally adding a dependency over and over, e.g.

      1. request:
        {
        "jsonrpc":"2.0",
        "method":"trigger.addDependencies",
        "params":[
        { "triggerid": "100100000065000", "dependsOnTriggerid": "100100000064000" }

        ,
        ],
        "auth":"038e1d7b1735c6a5436ee9eae095879e",
        "id":2
        }

      The problem is, when we checked what this was doing, through the API, it looked like trigger.addDependencies was being very clever, and doing nothing if the dependency already existed:

      1. request:
        {
        "jsonrpc":"2.0",
        "method":"trigger.get",
        "params":{
        "filter": { "description": ["Sample trigger 1"], }

        ,
        "include_dependencies": "refer"
        },
        "auth":"6f38cddc44cfbb6c1bd186f9a220b5a0",
        "id":2
        }

      No matter how many times we added the same dependency with trigger.addDependencies, trigger.get would show us the dependency only once.

      However, each call to trigger.addDependencies added another row to the trigger_depends table. By the time we noticed what was happening, we had over half a million rows in the trigger_depends table, the increasing every half an hour when our script was run from cron.

      We have subsequently modified our code to "include_dependencies" in the trigger.get request, and only trigger.addDependencies if the dependencies we want are missing. This reduces the likelihood of duplicate rows in trigger_depends table considerably.

      Possible solutions that occur to me include:

      1) Make trigger.addDependencies() fail when it receives a request to add an already existing dependency.
      2) Throw a unique constraint across trigger_depends.triggerid_up and trigger_depends.triggerid_down and just let the mysql exception explode upward.
      3) Make trigger.addDependencies() silently ignore a request to add an already existing dependency. Perhaps log a warning.

            Unassigned Unassigned
            sheldonh Sheldon Hearn
            Votes:
            2 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: