[ZBX-7829] "reserveIds" and "refreshIds" functions still assume not 64-bit IDs range in standalone installation. Created: 2014 Feb 18  Updated: 2017 May 30  Resolved: 2014 Feb 25

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Frontend (F)
Affects Version/s: 2.2.2, 2.3.0
Fix Version/s: 2.2.3rc1, 2.3.0

Type: Incident report Priority: Critical
Reporter: Oleksii Zagorskyi Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: dm, ids
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate

 Description   

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.



 Comments   
Comment by Alexander Vladishev [ 2014 Feb 20 ]

Related issue: ZBXNEXT-1500

zalex_ua I mentioned that on top of issue description from very beginning

Comment by Alexander Vladishev [ 2014 Feb 22 ]

Fixed in the development branch svn://svn.zabbix.com/branches/dev/ZBX-7829

Comment by Pavels Jelisejevs (Inactive) [ 2014 Feb 24 ]

(1) The following functions can also be removed:

  • in_node
  • create_id_by_nodeid
  • remove_nodes_from_id (it seems that the if statements can be replaced with just "> 0" comparisons).

sasha RESOLVED in r42956.

jelisejev CLOSED.

Comment by Pavels Jelisejevs (Inactive) [ 2014 Feb 25 ]

TESTED.

Comment by Alexander Vladishev [ 2014 Feb 25 ]

Fixed in pre-2.2.3 r42980 and pre-2.3.0 (trunk) r42981

Generated at Thu Mar 28 15:16:23 EET 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.