Commit d9c8bf86 authored by Claes Sjofors's avatar Claes Sjofors

Sev check/repair program for mysql history database

parent 45980764
include $(pwre_dir_symbols)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(hw_name)/$(type_name)_generic.mk
ifeq ($($(type_name)_generic_mk),)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(type_name)_generic.mk
endif
ifeq ($($(type_name)_generic_mk),)
include $(pwre_kroot)/tools/bld/src/$(type_name)_generic.mk
endif
ifndef link_rule_mk
link_rule_mk := 1
link = $(ldxx) $(elinkflags) $(domap) -o $(export_exe) \
$(export_obj) $(objects) $(wb_msg_eobjs) $(rt_msg_eobjs) \
$(pwr_eobj)/rt_io_user.o \
$(pwre_conf_libdir) $(pwre_conf_libpwrsev) $(pwre_conf_libpwrrt) $(pwre_conf_lib)
endif
/*
* Proview $Id$
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#if defined PWRE_CONF_MYSQL
#include "pwr.h"
#include "co_cdh.h"
#include "co_dcli.h"
#include "co_time.h"
#include "sev_repair.h"
#include "sev_dbms.h"
#include "rt_sev_msg.h"
int sev_repair::init()
{
sev_dbms_env *env;
pwr_tFileName envname;
sprintf( envname, "$pwrp_db/%s.db", sev_dbms_env::dbName());
dcli_translate_filename( envname, envname);
env = new sev_dbms_env( envname);
env->open( envname);
if ( !env->exists()) {
printf( "** Error: Database environment doesn't exist\n");
exit(0);
}
if ( !env->openDb()) {
printf("Failed to connect to database '%s'", sev_dbms_env::dbName());
exit(0);
}
m_db = new sev_dbms( env);
printf("-- Database opened '%s'\n", sev_dbms_env::dbName());
m_db->get_items( &m_sts);
m_db->get_objectitems(&m_sts);
return 1;
}
int sev_repair::check()
{
pwr_tStatus sts;
int fail_cnt = 0;
printf( "-- Number of tables to check: %u\n", m_db->m_items.size());
for ( unsigned int i = 0; i < m_db->m_items.size(); i++) {
m_db->repair_table( &sts, m_db->m_items[i].tablename);
if ( EVEN(sts))
fail_cnt++;
}
if ( fail_cnt)
printf( "** Repair failed on %d tables\n", fail_cnt);
else
printf( "-- Tables successfully repaired\n");
return 1;
}
int main (int argc, char *argv[])
{
sev_repair rep;
rep.init();
rep.check();
}
#else
int main(){}
#endif
/*
* Proview $Id$
* Copyright (C) 2005 SSAB Oxelösund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef sev_repair_h
#define sev_repair_h
#include <vector>
#include <map>
#include "pwr.h"
#include "pwr_class.h"
#include "rt_sev_net.h"
#include "sev_db.h"
class sev_repair {
public:
sev_repair() {}
pwr_tStatus m_sts;
sev_db *m_db;
int init();
int check();
};
#endif
......@@ -116,7 +116,7 @@ class sev_db {
unsigned int size, pwr_tTime *starttime, pwr_tTime *endtime,
int maxsize, pwr_tTime **tbuf, void **vbuf, unsigned int *bsize) { return 0;}
virtual int handle_objectchange(pwr_tStatus *sts, char *tablename, unsigned int item_idx, bool newObject) { return 0;}
virtual int repair_table( pwr_tStatus *sts, char *tablename) { return 0;}
};
#endif
......@@ -3294,6 +3294,104 @@ int sev_dbms::handle_objectchange(pwr_tStatus *sts, char *tablename, unsigned in
return 1;
}
int sev_dbms::repair_table( pwr_tStatus *sts, char *tablename)
{
char query[200];
int rc;
int repair_table;
int repair_failed;
// Check table
printf( "-- Checking table %s...\n", tablename);
sprintf( query, "check table %s", tablename);
rc = mysql_query( m_env->con(), query);
if (rc) {
printf("In %s row %d:\n", __FILE__, __LINE__);
printf( "%s: %s\n", __FUNCTION__,mysql_error(m_env->con()));
*sts = SEV__DBERROR;
return 0;
}
else {
MYSQL_ROW row;
MYSQL_RES *result = mysql_store_result( m_env->con());
if ( !result) {
printf("In %s row %d:\n", __FILE__, __LINE__);
printf( "%s Status Result Error\n", __FUNCTION__);
*sts = SEV__DBERROR;
return 0;
}
int rows = mysql_num_rows( result);
for ( int i = 0; i < rows; i++) {
row = mysql_fetch_row( result);
if (!row) break;
printf( "-- Check result '%s %s %s %s'\n", row[0], row[1], row[2], row[3]);
}
if ( cdh_NoCaseStrcmp( row[3], "ok") == 0)
repair_table = 0;
else
repair_table = 1;
mysql_free_result( result);
}
if ( !repair_table) {
*sts = SEV__SUCCESS;
return *sts;
}
// Repair table
printf( "-- Repairing %s...\n", tablename);
sprintf( query, "repair table %s", tablename);
rc = mysql_query( m_env->con(), query);
if (rc) {
printf("In %s row %d:\n", __FILE__, __LINE__);
printf( "%s: %s\n", __FUNCTION__,mysql_error(m_env->con()));
*sts = SEV__DBERROR;
return 0;
}
else {
MYSQL_ROW row;
MYSQL_RES *result = mysql_store_result( m_env->con());
if ( !result) {
printf("In %s row %d:\n", __FILE__, __LINE__);
printf( "%s Status Result Error\n", __FUNCTION__);
*sts = SEV__DBERROR;
return 0;
}
int rows = mysql_num_rows( result);
for ( int i = 0; i < rows; i++) {
row = mysql_fetch_row( result);
if (!row) break;
printf( "-- Repair result '%s %s %s %s'\n", row[0], row[1], row[2], row[3]);
}
if ( cdh_NoCaseStrcmp( row[3], "ok") != 0) {
printf( "** Error, repair failure %s\n", row[0]);
repair_failed = 1;
}
else
repair_failed = 0;
mysql_free_result( result);
}
if ( repair_failed)
*sts = SEV__REPAIR_FAILED;
else
*sts = SEV__SUCCESS;
return ODD(*sts);
}
sev_dbms::~sev_dbms()
......
......@@ -171,6 +171,7 @@ class sev_dbms : public sev_db {
pwr_tUInt64 get_nextAutoIncrement( char *tablename );
int handle_itemchange(pwr_tStatus *sts, char *tablename, unsigned int item_idx);
int handle_objectchange(pwr_tStatus *sts, char *tablename, unsigned int item_idx, bool newObject);
int repair_table( pwr_tStatus *sts, char *tablename);
inline char* create_colName(unsigned int index, char *attributename) {
static char colName[constMaxColNameLength];
strncpy(colName, attributename, constMaxColNameLength);
......
......@@ -30,6 +30,7 @@ noitems <No items found> /error
unknownnode <Unknown server nodename> /error
init <Initialization done> /info
exportfile <Unable to open export file> /error
repair_failed <Repair failed> /error
.end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment