Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

Commit

Permalink
Add config dump in progress to program status table.
Browse files Browse the repository at this point in the history
Refs #5080
  • Loading branch information
Michael Friedrich authored and Michael Friedrich committed Nov 15, 2013
1 parent 6df2cee commit 5145dbb
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 19 deletions.
4 changes: 4 additions & 0 deletions base/icinga.c
Expand Up @@ -786,6 +786,10 @@ int main(int argc, char **argv, char **env) {


#ifdef USE_EVENT_BROKER
/* forcibly send a program status update
* for later updates of PROCESS_* */
broker_program_status(NEBTYPE_PROGRAMSTATUS_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, NULL);

/* send program data to broker */
broker_program_state(NEBTYPE_PROCESS_START, NEBFLAG_NONE, NEBATTR_NONE, NULL);
#endif
Expand Down
3 changes: 2 additions & 1 deletion module/idoutils/db/mysql/mysql.sql
Expand Up @@ -917,6 +917,7 @@ CREATE TABLE IF NOT EXISTS icinga_programstatus (
modified_service_attributes int default 0,
global_host_event_handler TEXT character set latin1 default '',
global_service_event_handler TEXT character set latin1 default '',
config_dump_in_progress smallint default 0,
PRIMARY KEY (programstatus_id),
UNIQUE KEY instance_id (instance_id)
) ENGINE=InnoDB COMMENT='Current program status information';
Expand Down Expand Up @@ -1526,6 +1527,6 @@ CREATE INDEX sla_idx_obj ON icinga_objects (objecttype_id, is_active, name1);
-- -----------------------------------------
-- set dbversion
-- -----------------------------------------
INSERT INTO icinga_dbversion (name, version, create_time, modify_time) VALUES ('idoutils', '1.10.0', NOW(), NOW()) ON DUPLICATE KEY UPDATE version='1.10.0', modify_time=NOW();
INSERT INTO icinga_dbversion (name, version, create_time, modify_time) VALUES ('idoutils', '1.11.0', NOW(), NOW()) ON DUPLICATE KEY UPDATE version='1.11.0', modify_time=NOW();


21 changes: 21 additions & 0 deletions module/idoutils/db/mysql/upgrade/mysql-upgrade-1.11.0.sql
@@ -0,0 +1,21 @@
-- -----------------------------------------
-- upgrade path for Icinga IDOUtils 1.11.0
--
-- -----------------------------------------
-- Copyright (c) 2013 Icinga Development Team (http://www.icinga.org)
--
-- Please check http://docs.icinga.org for upgrading information!
-- -----------------------------------------

-- -----------------------------------------
-- config dump in progress
-- -----------------------------------------

ALTER TABLE icinga_programstatus ADD COLUMN config_dump_in_progress SMALLINT DEFAULT 0;

-- -----------------------------------------
-- update dbversion
-- -----------------------------------------

INSERT INTO icinga_dbversion (name, version, create_time, modify_time) VALUES ('idoutils', '1.11.0', NOW(), NOW()) ON DUPLICATE KEY UPDATE version='1.11.0', modify_time=NOW();

6 changes: 2 additions & 4 deletions module/idoutils/db/oracle/create_icinga_objects_oracle.sql
Expand Up @@ -6,9 +6,6 @@
--
-- Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
--
-- initial version: 2008-02-20 David Schmidt
-- 2011-01-17 Michael Friedrich <michael.friedrich(at)univie.ac.at>
-- current version: 2012-10-31 Thomas Dressler
-- -- --------------------------------------------------------
*/
-- -----------------------------------------
Expand Down Expand Up @@ -1276,7 +1273,8 @@ CREATE TABLE programstatus (
modified_host_attributes integer default 0 ,
modified_service_attributes integer default 0 ,
global_host_event_handler varchar2(1024),
global_service_event_handler varchar2(1024)
global_service_event_handler varchar2(1024),
config_dump_in_progress integer default 0
)tablespace &&DATATBS;

alter table programstatus add constraint programstatus_pk PRIMARY KEY (id)
Expand Down
6 changes: 1 addition & 5 deletions module/idoutils/db/oracle/oracle.sql
Expand Up @@ -14,14 +14,10 @@
-- CAUTION: THIS WILL DROP EXISTING USER AND TABLESPACE WITH SAME NAME
-- # export TWO_TASK=<instance>; cd <this_sql_dir>; sqlplus "sys as sysdba" @ oracle.sql
--
-- initial version: 2008-02-20 David Schmidt
-- 2011-01-17 Michael Friedrich <michael.friedrich(at)univie.ac.at>
-- current version: 2012-03-03 Thomas Dressler
--
-- -- --------------------------------------------------------
*/

DEFINE ICINGA_VERSION=1.10.0
DEFINE ICINGA_VERSION=1.11.0

-- -----------------------------------------
-- set defines
Expand Down
62 changes: 62 additions & 0 deletions module/idoutils/db/oracle/upgrade/oracle-upgrade-1.11.0.sql
@@ -0,0 +1,62 @@
-- -----------------------------------------
-- upgrade path for Icinga IDOUtils 1.11.0
--
-- run it as icinga database user from whithin current directory
-- sqlplus icinga@<instance> @ oracle-upgrade-1.11.0.sql

-- -----------------------------------------
-- Copyright (c) 2013 Icinga Development Team (http://www.icinga.org)
--
-- Please check http://docs.icinga.org for upgrading information!
-- -----------------------------------------
set sqlprompt "&&_USER@&&_CONNECT_IDENTIFIER SQL>"
set pagesize 200;
set linesize 200;
set heading on;
set echo on;
set feedback on;

define ICINGA_VERSION=1.11.0

-- --------------------------------------------------------
-- warning: edit this script to define existing tablespaces
-- this particular step can be skipped safely if no new
-- table or index included
-- --------------------------------------------------------
/* set real TBS names on which you have quota, no checks are implemented!*/
define DATATBS='ICINGA_DATA1';
define LOBTBS='ICINGA_LOB1';
define IDXTBS='ICINGA_IDX1';

/* load defines from file, if any */
@icinga_defines.sql

/* script will be terminated on the first error */
whenever sqlerror exit failure
spool oracle-upgrade-&&ICINGA_VERSION..log

-- -----------------------------------------
-- #5080 config dump in progress
-- -----------------------------------------

ALTER TABLE programstatus ADD config_dump_in_progress integer default 0;

-- -----------------------------------------
-- finally update dbversion
-- -----------------------------------------

MERGE INTO dbversion
USING DUAL ON (name='idoutils')
WHEN MATCHED THEN
UPDATE SET version='&&ICINGA_VERSION', modify_time=CURRENT_TIMESTAMP
WHEN NOT MATCHED THEN
INSERT (id, name, version, create_time, modify_time) VALUES ('1', 'idoutils', '&&ICINGA_VERSION', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
commit;

/* last check */
select object_name,object_type,status from user_objects where status !='VALID';

/* goodbye */
spool off
exit;

6 changes: 2 additions & 4 deletions module/idoutils/db/pgsql/pgsql.sql
Expand Up @@ -4,9 +4,6 @@
--
-- Copyright (c) 2009-2013 Icinga Development Team (http://www.icinga.org)
--
-- initial version: 2009-05-13 Markus Manzke
-- current version: 2012-04-19 Michael Friedrich <michael.friedrich@univie.ac.at>
--
-- --------------------------------------------------------

--
Expand Down Expand Up @@ -947,6 +944,7 @@ CREATE TABLE icinga_programstatus (
modified_service_attributes INTEGER default 0,
global_host_event_handler TEXT default '',
global_service_event_handler TEXT default '',
config_dump_in_progress INTEGER default 0,
CONSTRAINT PK_programstatus_id PRIMARY KEY (programstatus_id) ,
CONSTRAINT UQ_programstatus UNIQUE (instance_id)
) ;
Expand Down Expand Up @@ -1557,5 +1555,5 @@ CREATE INDEX sla_idx_obj ON icinga_objects (objecttype_id, is_active, name1);
-- set dbversion
-- -----------------------------------------

SELECT updatedbversion('1.10.0');
SELECT updatedbversion('1.11.0');

21 changes: 21 additions & 0 deletions module/idoutils/db/pgsql/upgrade/pgsql-upgrade-1.11.0.sql
@@ -0,0 +1,21 @@
-- -----------------------------------------
-- upgrade path for Icinga IDOUtils 1.11.0
--
-- -----------------------------------------
-- Copyright (c) 2013 Icinga Development Team (http://www.icinga.org)
--
-- Please check http://docs.icinga.org for upgrading information!
-- -----------------------------------------

-- -----------------------------------------
-- #5050 config dump in progress
-- -----------------------------------------

ALTER TABLE icinga_programstatus ADD config_dump_in_progress INTEGER DEFAULT 0;

-- -----------------------------------------
-- update dbversion
-- -----------------------------------------

SELECT updatedbversion('1.11.0');

1 change: 1 addition & 0 deletions module/idoutils/include/db.h
Expand Up @@ -167,6 +167,7 @@ void ido2db_db_txbuf_flush(ido2db_idi *idi, ido2db_txbuf *txbuf);

int ido2db_db_tx_begin(ido2db_idi *idi);
int ido2db_db_tx_commit(ido2db_idi *idi);
int ido2db_db_update_config_dump(ido2db_idi *idi, int in_progress);

#ifdef USE_ORACLE /* Oracle ocilib specific */
#define OCI_VARCHAR_SIZE 4096 /* max allowed string size for varchar2 (+1) */
Expand Down
1 change: 1 addition & 0 deletions module/idoutils/include/ido2db.h
Expand Up @@ -256,6 +256,7 @@ typedef struct ido2db_input_data_info_struct{
ido2db_mbuf mbuf[IDO2DB_MAX_MBUF_ITEMS];
ido2db_dbconninfo dbinfo;
ido2db_txbuf txbuf;
int in_transaction;
}ido2db_idi;

typedef struct ido2db_proxy_struct {
Expand Down
35 changes: 35 additions & 0 deletions module/idoutils/src/db.c
Expand Up @@ -2850,6 +2850,9 @@ int ido2db_db_tx_begin(ido2db_idi *idi) {

result = ido2db_db_query(idi, "BEGIN");
dbi_result_free(idi->dbinfo.dbi_result);

idi->in_transaction = IDO_TRUE;

return result;
#else /* USE_LIBDBI */
return IDO_OK;
Expand All @@ -2866,12 +2869,44 @@ int ido2db_db_tx_commit(ido2db_idi *idi) {

result = ido2db_db_query(idi, "COMMIT");
dbi_result_free(idi->dbinfo.dbi_result);

idi->in_transaction = IDO_FALSE;

return result;
#else /* USE_LIBDBI */
return IDO_OK;
#endif /* USE_LIBDBI */
}

int ido2db_db_update_config_dump(ido2db_idi *idi, int in_progress) {
int result = IDO_ERROR;
char * buf = NULL;

ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_update_config_dump() in_progress=%d\n", in_progress);

/* commit before query if within transaction*/
if (idi->in_transaction == IDO_TRUE)
ido2db_db_tx_commit(idi);

if (asprintf(&buf, "UPDATE %s SET config_dump_in_progress=%d WHERE instance_id=%lu",
ido2db_db_tablenames[IDO2DB_DBTABLE_PROGRAMSTATUS],
(in_progress == IDO_TRUE) ? 1 : 0,
idi->dbinfo.instance_id) == -1)
buf = NULL;

result = ido2db_db_query(idi, buf);
dbi_result_free(idi->dbinfo.dbi_result);

free(buf);

if (result == IDO_OK) {
/* force commit */
result = ido2db_db_tx_commit(idi);
}

return result;
}

/************************************/
/* check database driver (libdbi) */
/************************************/
Expand Down
17 changes: 12 additions & 5 deletions module/idoutils/src/ido2db.c
Expand Up @@ -1625,26 +1625,30 @@ int ido2db_handle_client_connection(int sd, ido2db_proxy *proxy) {

result = IDO_OK;

if (!in_transaction)
if (in_transaction == IDO_FALSE)
result = ido2db_db_tx_begin(&idi);

/* check for client input */
ido2db_check_for_client_input(&idi);

if (result == IDO_OK) {
in_transaction = (proxy && ido2db_proxy_get_size_left(proxy) > 16 * 1024);
in_transaction = (proxy && ido2db_proxy_get_size_left(proxy) > 16 * 1024) ? IDO_TRUE : IDO_FALSE;

if (io_since_last_commit > 1024 * 1024)
in_transaction = 0;
in_transaction = IDO_FALSE;

if (!in_transaction) {
if (in_transaction == IDO_FALSE) {
io_since_last_commit = 0;
printf("Committing...\n");
}

if (!in_transaction && ido2db_db_tx_commit(&idi) != IDO_OK)
if (in_transaction == IDO_FALSE && ido2db_db_tx_commit(&idi) != IDO_OK)
syslog(LOG_ERR, "IDO2DB commit failed. Some data may have been lost.\n");
}

/* store in_transaction for later */
idi.in_transaction = in_transaction;

/* should we disconnect the client? */
if (idi.disconnect_client == IDO_TRUE) {

Expand Down Expand Up @@ -1716,6 +1720,7 @@ int ido2db_idi_init(ido2db_idi *idi) {
idi->data_start_time = 0L;
idi->data_end_time = 0L;
idi->tables_cleared = IDO_FALSE;
idi->in_transaction = IDO_FALSE;

ido2db_db_txbuf_init(&(idi->txbuf));

Expand Down Expand Up @@ -1930,9 +1935,11 @@ int ido2db_handle_client_input(ido2db_idi *idi, char *buf) {
/* config dumps */
case IDO_API_STARTCONFIGDUMP:
idi->current_input_data = IDO2DB_INPUT_DATA_CONFIGDUMPSTART;
ido2db_db_update_config_dump(idi, IDO_TRUE);
break;
case IDO_API_ENDCONFIGDUMP:
idi->current_input_data = IDO2DB_INPUT_DATA_CONFIGDUMPEND;
ido2db_db_update_config_dump(idi, IDO_FALSE);
idi->tables_cleared = IDO_FALSE;
syslog(LOG_USER | LOG_INFO, "Config dump completed");
break;
Expand Down

0 comments on commit 5145dbb

Please sign in to comment.