[icinga-checkins] icinga.org: icinga-core/support/1.9: Work-around for the dbi_result_next_row() bug.

git at icinga.org git at icinga.org
Sat Jun 22 17:53:42 CEST 2013


Module: icinga-core
Branch: support/1.9
Commit: bcb878e62cd1fa433282f78a7f80d181cef849e2
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=bcb878e62cd1fa433282f78a7f80d181cef849e2

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Mon Apr 29 21:22:15 2013 +0200

Work-around for the dbi_result_next_row() bug.

dbi_result_next_row() is O(n) where n is the number of rows
in the result set.

---

 module/idoutils/src/db.c         |    4 +-
 module/idoutils/src/dbhandlers.c |   57 ++++++++++++++++++++++---------------
 2 files changed, 36 insertions(+), 25 deletions(-)

diff --git a/module/idoutils/src/db.c b/module/idoutils/src/db.c
index 8eb7b8e..cc6b65a 100644
--- a/module/idoutils/src/db.c
+++ b/module/idoutils/src/db.c
@@ -1801,7 +1801,7 @@ int ido2db_db_hello(ido2db_idi *idi) {
 
 	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_hello() get cached object ids\n");
 	/* get cached object ids... */
-	/*ido2db_get_cached_object_ids(idi);*/
+	ido2db_get_cached_object_ids(idi);
 
 	/* get latest times from various tables... */
 	ido2db_db_get_latest_data_time(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_PROGRAMSTATUS], "status_update_time", (unsigned long *) &idi->dbinfo.latest_program_status_time);
@@ -2120,7 +2120,7 @@ int ido2db_thread_db_hello(ido2db_idi *idi) {
 #endif /* Oracle ocilib specific */
 	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_thread_db_hello() get cached object ids\n");
 	/* get cached object ids... */
-	/*ido2db_get_cached_object_ids(idi);*/
+	ido2db_get_cached_object_ids(idi);
 
 	/* get latest times from various tables... */
 	ido2db_db_get_latest_data_time(idi, ido2db_db_tablenames[IDO2DB_DBTABLE_PROGRAMSTATUS], "status_update_time", (unsigned long *) &idi->dbinfo.latest_program_status_time);
diff --git a/module/idoutils/src/dbhandlers.c b/module/idoutils/src/dbhandlers.c
index 71f1d60..72a8f0c 100644
--- a/module/idoutils/src/dbhandlers.c
+++ b/module/idoutils/src/dbhandlers.c
@@ -476,6 +476,7 @@ int ido2db_get_cached_object_ids(ido2db_idi *idi) {
 	char *tmp1 = NULL;
 	char *tmp2 = NULL;
 #ifdef USE_LIBDBI
+	unsigned long offset, stride;
 	char *buf = NULL;
 #endif
 
@@ -486,37 +487,47 @@ int ido2db_get_cached_object_ids(ido2db_idi *idi) {
 
 	/* find all the object definitions we already have */
 #ifdef USE_LIBDBI /* everything else will be libdbi */
-	if (asprintf(&buf, "SELECT object_id, objecttype_id, name1, name2 FROM %s WHERE instance_id=%lu", ido2db_db_tablenames[IDO2DB_DBTABLE_OBJECTS], idi->dbinfo.instance_id) == -1)
-		buf = NULL;
+	offset = 0;
+	stride = 2500;
 
-	if ((result = ido2db_db_query(idi, buf)) == IDO_OK) {
-		while (idi->dbinfo.dbi_result) {
-			if (dbi_result_next_row(idi->dbinfo.dbi_result)) {
-				object_id = dbi_result_get_ulonglong(idi->dbinfo.dbi_result, "object_id");
-				objecttype_id = dbi_result_get_ulonglong(idi->dbinfo.dbi_result, "objecttype_id");
+	for (;;) {
+		if (asprintf(&buf, "SELECT object_id, objecttype_id, name1, name2 FROM %s WHERE instance_id=%lu LIMIT %lu, %lu", ido2db_db_tablenames[IDO2DB_DBTABLE_OBJECTS], idi->dbinfo.instance_id, offset, stride) == -1)
+			buf = NULL;
 
-				/* get string and free it later on */
-				if (asprintf(&tmp1, "%s", dbi_result_get_string_copy(idi->dbinfo.dbi_result, "name1")) == -1)
-					tmp1 = NULL;
-				if (asprintf(&tmp2, "%s", dbi_result_get_string_copy(idi->dbinfo.dbi_result, "name2")) == -1)
-					tmp2 = NULL;
+		if ((result = ido2db_db_query(idi, buf)) == IDO_OK) {
+			if (dbi_result_get_numrows(idi->dbinfo.dbi_result) == 0)
+				break;
 
-				ido2db_add_cached_object_id(idi, objecttype_id, tmp1, tmp2, object_id);
+			while (idi->dbinfo.dbi_result) {
+				if (dbi_result_next_row(idi->dbinfo.dbi_result)) {
+					object_id = dbi_result_get_ulonglong(idi->dbinfo.dbi_result, "object_id");
+					objecttype_id = dbi_result_get_ulonglong(idi->dbinfo.dbi_result, "objecttype_id");
 
-				free(tmp1);
-				free(tmp2);
+					/* get string and free it later on */
+					if (asprintf(&tmp1, "%s", dbi_result_get_string_copy(idi->dbinfo.dbi_result, "name1")) == -1)
+						tmp1 = NULL;
+					if (asprintf(&tmp2, "%s", dbi_result_get_string_copy(idi->dbinfo.dbi_result, "name2")) == -1)
+						tmp2 = NULL;
 
-			} else {
-				dbi_result_free(idi->dbinfo.dbi_result);
-				idi->dbinfo.dbi_result = NULL;
+					ido2db_add_cached_object_id(idi, objecttype_id, tmp1, tmp2, object_id);
+
+					free(tmp1);
+					free(tmp2);
+
+				} else {
+					dbi_result_free(idi->dbinfo.dbi_result);
+					idi->dbinfo.dbi_result = NULL;
+				}
 			}
+		} else {
+			dbi_result_free(idi->dbinfo.dbi_result);
+			idi->dbinfo.dbi_result = NULL;
 		}
-	} else {
-		dbi_result_free(idi->dbinfo.dbi_result);
-		idi->dbinfo.dbi_result = NULL;
-	}
 
-	free(buf);
+		free(buf);
+
+		offset += stride;
+	}
 #endif
 
 #ifdef USE_PGSQL /* pgsql */





More information about the icinga-checkins mailing list