[ZBX-10576] Restructure unixODBC related code Created: 2016 Mar 24  Updated: 2018 Nov 15  Resolved: 2017 Oct 18

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Installation (I), Proxy (P), Server (S)
Affects Version/s: 3.0.2rc1, 3.2.0alpha1
Fix Version/s: 4.0.0alpha1, 4.0 (plan)

Type: Problem report Priority: Trivial
Reporter: Glebs Ivanovskis (Inactive) Assignee: Glebs Ivanovskis (Inactive)
Resolution: Fixed Votes: 4
Labels: codequality, libraries, unixodbc
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Causes
causes ZBX-15171 Zabbix Server Crash Closed
Epic Link: DEV-591
Team: Team A
Sprint: Sprint 15, Sprint 16, Sprint 17, Sprint 18, Sprint 19
Story Points: 3

 Description   

Zabbix interface for unixODBC library has following flaws:

  • There are two places where unixODBC headers are (indirectly) included:
    • src/libs/zbxdbhigh/odbc.c
    • src/zabbix_server/poller/checks_db.c
  • File odbc.c is compiled as a part of libzbxdbhigh.a but has its own header include/zbxodbc.h
  • ODBC handle structure serves both as handle and result structure

We should either

  • make a standalone unixODBC lib with it's own include/zbxodbc.h, src/libs/zbxodbc, libzbxodbc.a and hide all unixODBC details there
  • or move all related stuff from src/libs/zbxdbhigh/odbc.c to src/zabbix_server/poller/checks_db.c and remove include/zbxodbc.h because it is not used anywhere else (we do similarly with netSNMP, OpenIPMI and libSSH2)


 Comments   
Comment by Glebs Ivanovskis (Inactive) [ 2016 Apr 08 ]

Also, unixODBC function names conflict with IBM DB2 function names which makes it impossible to run Zabbix on IBM DB2 and use ODBC checks simultaneously. Credits to constantin.oshmyan for discovering this issue.

Comment by elham jahani [ 2016 Dec 20 ]

also in compile zabbix 3.2 I have a problem with unixODBC
when configure zabbix with "--with-unixodbc" , see the many line of error in "make" step
and Inevitably delete this option

Comment by Aleksandrs Saveljevs [ 2016 Dec 20 ]

The above problem originally discussed at http://stackoverflow.com/questions/41236437/error-during-zabbix-3-2-compile .

Comment by Glebs Ivanovskis (Inactive) [ 2017 Sep 08 ]

Progress so far:

  • moved all code dependent on UnixODBC headers to src/zabbix_server/odbc
  • simplified src/zabbix_server/poller/checks_db.c
  • detached ODBC connection and query structures, now it's possible to have several queries per connection handle, maybe will be useful someday
  • cleaned up our ODBC lib API according to best practices used in Zabbix
  • refactored (partially) internals of the lib to correspond new API
  • invalid UTF-8 characters were only replaced in db.odbc.select, done the same for db.odbc.discovery

Currently I'm quite happy with src/zabbix_server/poller/checks_db.c and src/zabbix_server/odbc/odbc.h but internals of src/zabbix_server/odbc/odbc.c still need some love.

Left to do:

  • do something with CALLODBC, it's an unreadable monster
  • complete transition to dynamic error buffers and improve error messages
  • investigate how timeouts work for UnixODBC

glebs.ivanovskis Update:

  • CALLODBC removed
  • error buffers are now dynamic (except native ODBC errors which are still limited to 128 characters, see (1))
  • yes, slow ODBC queries (e.g. select sleep(10);) can stall Zabbix, see (3)

Available for review and testing in development branch svn://svn.zabbix.com/branches/dev/ZBX-10576

P.S. UnixODBC call semantics have not changed, at least I had no intention to do that. Therefore such occasion can be considered a bug.

Comment by Andrea Biscuola (Inactive) [ 2017 Oct 03 ]

Out of the previous minor comment, I like the restructuring done. It make definitely the odbc code more navigable and understandable. I also don't see functional changes here.

Comment by Andrea Biscuola (Inactive) [ 2017 Oct 05 ]

Successfully tested.

Comment by Glebs Ivanovskis (Inactive) [ 2017 Oct 05 ]

Available in pre-4.0.0alpha1 (trunk) r73216, few compiler warnings fixed in r73225, proxy-only compilation fixed in r73306.

Comment by Andris Zeila [ 2017 Oct 06 ]

(7) Error when trying to build only proxy:

make[3]: *** No rule to make target '../../src/zabbix_server/odbc/libzbxodbc.a', needed by 'zabbix_proxy'.  Stop.

glebs.ivanovskis RESOLVED in r73306.

abs CLOSED

Generated at Thu Mar 28 14:43:27 EET 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.