[icinga-checkins] icinga.org: icinga-core/dev/cgis: Use transactions for SQL queries ( just for MySQL for now).

git at icinga.org git at icinga.org
Mon Jan 21 22:19:02 CET 2013


Module: icinga-core
Branch: dev/cgis
Commit: 5fe4b9bcedd8edacc75c28decd2522749c8bfc86
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=5fe4b9bcedd8edacc75c28decd2522749c8bfc86

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Fri Nov 23 12:44:24 2012 +0100

Use transactions for SQL queries (just for MySQL for now).

This experimental patch significantly increases IDO2DB's performance.
More testing is required to determine whether transactions are safe
for general use.

---

 module/idoutils/include/db.h |    3 +++
 module/idoutils/src/db.c     |   16 ++++++++++++++++
 module/idoutils/src/ido2db.c |    8 +++++++-
 3 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/module/idoutils/include/db.h b/module/idoutils/include/db.h
index 1b58d1c..73d3288 100644
--- a/module/idoutils/include/db.h
+++ b/module/idoutils/include/db.h
@@ -162,6 +162,9 @@ int ido2db_db_get_latest_data_time(ido2db_idi *,char *,char *,unsigned long *);
 int ido2db_db_perform_maintenance(ido2db_idi *);
 int ido2db_db_trim_data_table(ido2db_idi *,char *,char *,unsigned long);
 
+int ido2db_db_tx_begin(ido2db_idi *idi);
+int ido2db_db_tx_commit(ido2db_idi *idi);
+
 #ifdef USE_ORACLE /* Oracle ocilib specific */
 #define OCI_VARCHAR_SIZE 4096 /* max allowed string size for varchar2 (+1) */
 #define OCI_STR_SIZE 256 /* default small string buffer size */
diff --git a/module/idoutils/src/db.c b/module/idoutils/src/db.c
index 5010d6f..d8bb55e 100644
--- a/module/idoutils/src/db.c
+++ b/module/idoutils/src/db.c
@@ -2904,6 +2904,22 @@ int ido2db_db_perform_maintenance(ido2db_idi *idi) {
 	return IDO_OK;
 }
 
+int ido2db_db_tx_begin(ido2db_idi *idi) {
+#ifdef USE_LIBDBI
+	return ido2db_db_query(idi, "BEGIN");
+#else /* USE_LIBDBI */
+	return IDO_OK;
+#endif /* USE_LIBDBI */
+}
+
+int ido2db_db_tx_commit(ido2db_idi *idi) {
+#ifdef USE_LIBDBI
+	return ido2db_db_query(idi, "COMMIT");
+#else /* USE_LIBDBI */
+	return IDO_OK;
+#endif /* USE_LIBDBI */
+}
+
 /************************************/
 /* check database driver (libdbi)   */
 /************************************/
diff --git a/module/idoutils/src/ido2db.c b/module/idoutils/src/ido2db.c
index ea94dd6..076b620 100644
--- a/module/idoutils/src/ido2db.c
+++ b/module/idoutils/src/ido2db.c
@@ -1208,7 +1208,7 @@ int ido2db_wait_for_connections(void) {
 int ido2db_handle_client_connection(int sd) {
 	int dbuf_chunk = 2048;
 	ido2db_idi idi;
-	char buf[512];
+	char buf[16 * 1024];
 	int result = 0;
 	int error = IDO_FALSE;
 
@@ -1391,8 +1391,14 @@ int ido2db_handle_client_connection(int sd) {
 		/* 2011-02-23 MF: only do that in a worker thread */
 		/* 2011-05-02 MF: redo it the old way */
 
+		result = ido2db_db_tx_begin(&idi);
 		ido2db_check_for_client_input(&idi);
 
+		if (result == IDO_OK) {
+			if (ido2db_db_tx_commit(&idi) != IDO_OK) {
+				syslog(LOG_ERR, "IDO2DB commit failed. Some data may have been lost.\n");
+			}
+		}
 
 		/* should we disconnect the client? */
 		if (idi.disconnect_client == IDO_TRUE) {





More information about the icinga-checkins mailing list