[icinga-checkins] icinga.org: icinga-core/mfriedrich/core: Added config option for SQL transactions

git at icinga.org git at icinga.org
Thu Feb 21 19:32:09 CET 2013


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

Author: Markus Frosch <markus at lazyfrosch.de>
Date:   Thu Jan 10 09:46:18 2013 +0100

Added config option for SQL transactions

---

 module/idoutils/config/ido2db.cfg-sample.in |   12 ++++++++++++
 module/idoutils/include/db.h                |    1 +
 module/idoutils/include/ido2db.h            |    1 +
 module/idoutils/src/ido2db.c                |    9 +++++++--
 4 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/module/idoutils/config/ido2db.cfg-sample.in b/module/idoutils/config/ido2db.cfg-sample.in
index 03ec80f..6eddb48 100644
--- a/module/idoutils/config/ido2db.cfg-sample.in
+++ b/module/idoutils/config/ido2db.cfg-sample.in
@@ -352,3 +352,15 @@ oracle_trace_level=0
 # occur, remark that you are explicitely using it. You've been warned.
 
 enable_sla=0
+
+# ENABLE TRANSACTIONS - EXPERIMENTAL!
+# This setting enables a SQL transaction around the data processing
+# block. The feature ist mostly useful for the config dump at start
+# of a big Icinga instance - or every other big chunk of data coming
+# from the Idomod. (In normal operation every event is still a single
+# transaction)
+#
+# WARNING: uses BEGIN / COMMIT for the transactions - make sure this
+# works with your DBMS!
+
+use_transactions=0
diff --git a/module/idoutils/include/db.h b/module/idoutils/include/db.h
index 73d3288..997f65c 100644
--- a/module/idoutils/include/db.h
+++ b/module/idoutils/include/db.h
@@ -39,6 +39,7 @@ typedef struct ido2db_dbconfig_struct{
         unsigned long clean_config_tables_on_core_startup;
 	unsigned long oci_errors_to_syslog;
 	unsigned int oracle_trace_level;
+	unsigned int use_transactions;
         }ido2db_dbconfig;
 
 /*************** DB server types ***************/
diff --git a/module/idoutils/include/ido2db.h b/module/idoutils/include/ido2db.h
index 8a02e92..9828875 100644
--- a/module/idoutils/include/ido2db.h
+++ b/module/idoutils/include/ido2db.h
@@ -225,6 +225,7 @@ typedef struct ido2db_dbconninfo_struct{
 	unsigned long clean_realtime_tables_on_core_startup;
 	unsigned long clean_config_tables_on_core_startup;
 	unsigned long oci_errors_to_syslog;
+	unsigned int use_transactions;
 	time_t last_table_trim_time;
 	time_t last_logentry_time;
 	char *last_logentry_data;
diff --git a/module/idoutils/src/ido2db.c b/module/idoutils/src/ido2db.c
index 076b620..10b6042 100644
--- a/module/idoutils/src/ido2db.c
+++ b/module/idoutils/src/ido2db.c
@@ -613,6 +613,8 @@ int ido2db_process_config_var(char *arg) {
 		enable_sla = (atoi(val) > 0) ? IDO_TRUE : IDO_FALSE;
 	} else if (!strcmp(var, "debug_readable_timestamp")) {
 		ido2db_debug_readable_timestamp = (atoi(val) > 0) ? IDO_TRUE : IDO_FALSE;
+	} else if (!strcmp(var, "use_transactions")) {
+		ido2db_db_settings.use_transactions = (atoi(val) > 0) ? IDO_TRUE : IDO_FALSE;
 	}
 	else if (!strcmp(var, "libdbi_driver_dir")) {
 		if ((libdbi_driver_dir = strdup(val)) == NULL)
@@ -656,6 +658,7 @@ int ido2db_initialize_variables(void) {
 	ido2db_db_settings.clean_config_tables_on_core_startup = IDO_TRUE;
 	ido2db_db_settings.oci_errors_to_syslog = DEFAULT_OCI_ERRORS_TO_SYSLOG;
 	ido2db_db_settings.oracle_trace_level = ORACLE_TRACE_LEVEL_OFF;
+	ido2db_db_settings.use_transactions = IDO_FALSE;
 
 	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_initialize_variables() end\n");
 	return IDO_OK;
@@ -1391,10 +1394,12 @@ 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);
+		if(ido2db_db_settings.use_transactions == IDO_TRUE) {
+			result = ido2db_db_tx_begin(&idi);
+		}
 		ido2db_check_for_client_input(&idi);
 
-		if (result == IDO_OK) {
+		if (ido2db_db_settings.use_transactions == IDO_TRUE && result == IDO_OK) {
 			if (ido2db_db_tx_commit(&idi) != IDO_OK) {
 				syslog(LOG_ERR, "IDO2DB commit failed. Some data may have been lost.\n");
 			}





More information about the icinga-checkins mailing list