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

"reserveIds" and "refreshIds" functions still assume not 64-bit IDs range in standalone installation.

XMLWordPrintable

    • Icon: Incident report Incident report
    • Resolution: Fixed
    • Icon: Critical Critical
    • 2.2.3rc1, 2.3.0
    • 2.2.2, 2.3.0
    • Frontend (F)

      Follow up from ZBXNEXT-1500
      I don't see that include/classes/db/DB.php was changed in the rev 32316 commit so we probably forgot about it.

      In the DB.php:186 we have a code:
      $sql = 'SELECT MAX('.$id_name.') AS id'.
      ' FROM '.$table.
      ' WHERE '.$id_name.'>='.self::$minNodeId.
      ' AND '.$id_name.'<='.self::$maxNodeId;
      $row = DBfetch(DBselect($sql));

      This code can generates this debug if we try to create something (an item in our case):

      SQL (0.000169): SELECT nextid FROM ids WHERE nodeid=0 AND table_name='items' AND field_name='itemid' FOR UPDATE
      items.php:468 ? CAPIObject->create() ? CAPIObject->__call() ? czbxrpc::call() ? czbxrpc::callAPI() ? call_user_func() ? CItem->create() ? CItem->createReal() ? DB::insert() ? DB::reserveIds() ? DBselect() in /zab/www-dev/zabbix22node1/include/classes/db/DB.php:135

      SQL (0.00015): DELETE FROM ids WHERE nodeid=0 AND table_name='items' AND field_name='itemid'
      items.php:468 ? CAPIObject->create() ? CAPIObject->__call() ? czbxrpc::call() ? czbxrpc::callAPI() ? call_user_func() ? CItem->create() ? CItem->createReal() ? DB::insert() ? DB::reserveIds() ? DB::refreshIds() ? DBexecute() in /zab/www-dev/zabbix22node1/include/classes/db/DB.php:182

      SQL (0.000139): SELECT MAX(itemid) AS id FROM items WHERE itemid>=0 AND itemid<=99999999999
      items.php:468 ? CAPIObject->create() ? CAPIObject->__call() ? czbxrpc::call() ? czbxrpc::callAPI() ? call_user_func() ? CItem->create() ? CItem->createReal() ? DB::insert() ? DB::reserveIds() ? DB::refreshIds() ? DBselect() in /zab/www-dev/zabbix22node1/include/classes/db/DB.php:190

      SQL (0.000129): INSERT INTO ids (nodeid,table_name,field_name,nextid) VALUES (0,'items','itemid',1)
      items.php:468 ? CAPIObject->create() ? CAPIObject->__call() ? czbxrpc::call() ? czbxrpc::callAPI() ? call_user_func() ? CItem->create() ? CItem->createReal() ? DB::insert() ? DB::reserveIds() ? DB::refreshIds() ? DBexecute() in /zab/www-dev/zabbix22node1/include/classes/db/DB.php:201

      Do you see a "WHERE itemid>=0 AND itemid<=99999999999" part ?
      Is this ok as for, quotation:
      "Zabbix now supports a signed 64-bit range for internal object IDs in a standalone, non-distributed setup. Thus the highest available number of one-type objects is 263 now."
      https://www.zabbix.com/documentation/2.2/manual/introduction/whatsnew220#miscellaneous

      Where this problem is observed:

      Suppose we want to revert (not officially supported) a DM (only one node was and is in DB) to standalone.
      Starting from 2.2 it's possible to do it with simple truncating "nodes" table. (Note: for server also need to comment out NodeID parameter and restart it.)

      In all configuration tables we had IDs in form like 100100000000002.
      Of course these IDs will not pass "WHERE itemid>=0 AND itemid<=99999999999" conditions and frontend will start to create items (and other objects) starting from ID=1 which is bad as in feature we can reach a point when frontend will reach already existing IDs like 100100000000002 and it will be a problem.

      The same debuglog can be generated if we just truncate the "ids" table.
      OR even in case if we have already there required table_name.field_name but its value is more than 99999999999
      because of this line(138):
      if (bccomp($maxNextId, self::$maxNodeId, 0) == 1 || bccomp($maxNextId, self::$minNodeId, 0) == -1) {

      Suggestion: review that part of code and:
      1) remove the "WHERE itemid>=0 AND itemid<=99999999999" limitation for standalone setup.
      2) allow $maxNextId more than 99999999999 for standalone setup.

            Unassigned Unassigned
            zalex_ua Oleksii Zagorskyi
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: