Commit 42923b6c authored by Claes Sjofors's avatar Claes Sjofors

sev_server reconnect if database connection is lost and dynamic mount fix

parent 7936638f
...@@ -354,6 +354,7 @@ int sev_import::check_exportitems(sev_sMsgExportItems* msg, unsigned int size) ...@@ -354,6 +354,7 @@ int sev_import::check_exportitems(sev_sMsgExportItems* msg, unsigned int size)
m_sts = tree_update(); m_sts = tree_update();
if (EVEN(m_sts)) if (EVEN(m_sts))
printf("Tree error %d\n", m_sts); printf("Tree error %d\n", m_sts);
m_sts = gdh_MountDynClients();
return 1; return 1;
} }
......
...@@ -856,6 +856,7 @@ int sev_server::check_histitems(sev_sMsgHistItems* msg, unsigned int size) ...@@ -856,6 +856,7 @@ int sev_server::check_histitems(sev_sMsgHistItems* msg, unsigned int size)
m_sts = m_db->tree_update(); m_sts = m_db->tree_update();
if (EVEN(m_sts)) if (EVEN(m_sts))
printf("Tree error %d\n", m_sts); printf("Tree error %d\n", m_sts);
m_sts = gdh_MountDynClients();
} }
return 1; return 1;
...@@ -1483,7 +1484,17 @@ void* sev_server::receive_histdata_thread(void* arg) ...@@ -1483,7 +1484,17 @@ void* sev_server::receive_histdata_thread(void* arg)
dp = (sev_sHistData*)&msg->data; dp = (sev_sHistData*)&msg->data;
sev->m_db->begin_transaction(th->db_ctx); sts = sev->m_db->begin_transaction(th->db_ctx);
if (sts == SEV__NOCONNECTION) {
if ( th->reconnect_cnt < 50) {
errh_Error("Database connection lost, thread %d, reconnecting",th->key);
th->db_ctx = sev->m_db->new_thread();
th->reconnect_cnt++;
sts = sev->m_db->begin_transaction(th->db_ctx);
}
if (EVEN(sts))
break;
}
while ((char*)dp - (char*)msg->data < data_size) { while ((char*)dp - (char*)msg->data < data_size) {
sev_sRefid* rp; sev_sRefid* rp;
...@@ -1513,8 +1524,14 @@ void* sev_server::receive_histdata_thread(void* arg) ...@@ -1513,8 +1524,14 @@ void* sev_server::receive_histdata_thread(void* arg)
+ dp->size); + dp->size);
} }
sev->m_db->commit_transaction(th->db_ctx); sts = sev->m_db->commit_transaction(th->db_ctx);
if (sts == SEV__NOCONNECTION) {
if ( th->reconnect_cnt < 50) {
errh_Error("Database connection lost, thread %d, reconnecting",th->key);
th->db_ctx = sev->m_db->new_thread();
th->reconnect_cnt++;
}
}
break; break;
} }
case sev_eQMsgType_Event: { case sev_eQMsgType_Event: {
......
...@@ -72,6 +72,7 @@ typedef struct { ...@@ -72,6 +72,7 @@ typedef struct {
int alloc; int alloc;
void* db_ctx; void* db_ctx;
int conf_idx; int conf_idx;
unsigned int reconnect_cnt;
} sev_sThread; } sev_sThread;
typedef struct { typedef struct {
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <mysql/mysqld_error.h> #include <mysql/mysqld_error.h>
#include <mysql/errmsg.h>
#include "pwr_names.h" #include "pwr_names.h"
...@@ -4863,7 +4864,9 @@ int sev_dbms::begin_transaction(void* thread) ...@@ -4863,7 +4864,9 @@ int sev_dbms::begin_transaction(void* thread)
if (rc) { if (rc) {
printf("In %s row %d:\n", __FILE__, __LINE__); printf("In %s row %d:\n", __FILE__, __LINE__);
printf("Begin transaction: %s\n", mysql_error(con)); printf("Begin transaction: %s\n", mysql_error(con));
return 0; if ( con->net.last_errno == CR_SERVER_GONE_ERROR)
return SEV__NOCONNECTION;
return SEV__DBERROR;
} }
return 1; return 1;
} }
...@@ -4883,8 +4886,10 @@ int sev_dbms::commit_transaction(void* thread) ...@@ -4883,8 +4886,10 @@ int sev_dbms::commit_transaction(void* thread)
rc = mysql_query(con, query); rc = mysql_query(con, query);
if (rc) { if (rc) {
printf("In %s row %d:\n", __FILE__, __LINE__); printf("In %s row %d:\n", __FILE__, __LINE__);
printf("Begin transaction: %s\n", mysql_error(con)); printf("Commit transaction: %s\n", mysql_error(con));
return 0; if ( con->net.last_errno == CR_SERVER_GONE_ERROR)
return SEV__NOCONNECTION;
return SEV__DBERROR;
} }
return 1; return 1;
} }
......
...@@ -5302,7 +5302,7 @@ pwr_tStatus gdh_MountDynClients(void) ...@@ -5302,7 +5302,7 @@ pwr_tStatus gdh_MountDynClients(void)
gdh_ScopeLock gdh_ScopeLock
{ {
op = vol_OidToObject(&sts, oid, gdb_mLo_native, vol_mTrans_all, op = vol_OidToObject(&sts, oid, gdb_mLo_native, vol_mTrans_none,
cvol_eHint_none); cvol_eHint_none);
if (cdh_ObjidIsNull(op->g.soid)) if (cdh_ObjidIsNull(op->g.soid))
vol_MountDynObject(&sts, op); vol_MountDynObject(&sts, op);
......
...@@ -535,6 +535,7 @@ mvol_sAttribute* vol_BlockNameToAttribute(pwr_tStatus* sts, mvol_sAttribute* ap, ...@@ -535,6 +535,7 @@ mvol_sAttribute* vol_BlockNameToAttribute(pwr_tStatus* sts, mvol_sAttribute* ap,
strcpy(aname, ""); strcpy(aname, "");
for (i = 0; i < pn->nObject; i++) { for (i = 0; i < pn->nObject; i++) {
strcat(aname, pn->object[i].name.orig); strcat(aname, pn->object[i].name.orig);
if (pn->nAttribute != 0)
strcat(aname, "-"); strcat(aname, "-");
} }
for (i = 0; i < pn->nAttribute; i++) { for (i = 0; i < pn->nAttribute; i++) {
...@@ -543,7 +544,7 @@ mvol_sAttribute* vol_BlockNameToAttribute(pwr_tStatus* sts, mvol_sAttribute* ap, ...@@ -543,7 +544,7 @@ mvol_sAttribute* vol_BlockNameToAttribute(pwr_tStatus* sts, mvol_sAttribute* ap,
strcat(aname, "-"); strcat(aname, "-");
} }
strcat(aname, ".Value"); strcat(aname, ".Value");
if (pn->hasIndex[pn->nAttribute-1]) if (pn->nAttribute != 0 && pn->hasIndex[pn->nAttribute-1])
sprintf(&aname[strlen(aname)], "[%d]", pn->index[pn->nAttribute-1]); sprintf(&aname[strlen(aname)], "[%d]", pn->index[pn->nAttribute-1]);
cdh_ParseName(sts, pn, pn->poid, aname, pn->parseFlags.m); cdh_ParseName(sts, pn, pn->poid, aname, pn->parseFlags.m);
...@@ -579,7 +580,7 @@ mvol_sAttribute* vol_NameToAttribute(pwr_tStatus* sts, mvol_sAttribute* ap, ...@@ -579,7 +580,7 @@ mvol_sAttribute* vol_NameToAttribute(pwr_tStatus* sts, mvol_sAttribute* ap,
if (op == NULL) if (op == NULL)
return NULL; return NULL;
if (op->g.cid == pwr_eClass_Block) { if (op->g.cid == pwr_eClass_Block && pn->nAttribute != 0) {
return vol_BlockNameToAttribute(sts, ap, pn, op, lo_flags, trans); return vol_BlockNameToAttribute(sts, ap, pn, op, lo_flags, trans);
} }
......
...@@ -56,6 +56,7 @@ unknowntype <Unknown data type> /error ...@@ -56,6 +56,7 @@ unknowntype <Unknown data type> /error
nosuchtable <Table doesn't exist> /error nosuchtable <Table doesn't exist> /error
norows <No rows found> /error norows <No rows found> /error
nowrite <Nothings written> /info nowrite <Nothings written> /info
noconnection <Connection has gone> /error
.end .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