Commit bb9d9bf8 authored by Claes Sjofors's avatar Claes Sjofors

Sev event storage, check that event is not already stored added

parent 943d2968
...@@ -489,7 +489,6 @@ int sev_server::mainloop() ...@@ -489,7 +489,6 @@ int sev_server::mainloop()
m_stat.dataget_msg_cnt++; m_stat.dataget_msg_cnt++;
break; break;
case sev_eMsgType_EventsStore: case sev_eMsgType_EventsStore:
printf( "sev_server Events received\n");
receive_events( (sev_sMsgEventsStore *) mp, get.size); receive_events( (sev_sMsgEventsStore *) mp, get.size);
m_stat.eventstore_msg_cnt++; m_stat.eventstore_msg_cnt++;
break; break;
...@@ -704,7 +703,6 @@ int sev_server::check_histitems( sev_sMsgHistItems *msg, unsigned int size) ...@@ -704,7 +703,6 @@ int sev_server::check_histitems( sev_sMsgHistItems *msg, unsigned int size)
} }
else { else {
// SevHistEvents item // SevHistEvents item
printf( "Event item received\n");
if ( !m_db->check_item( &m_sts, msg->Items[i].oid, msg->Items[i].oname, (char *)"Events", if ( !m_db->check_item( &m_sts, msg->Items[i].oid, msg->Items[i].oname, (char *)"Events",
storagetime, (pwr_eType)0, 0, storagetime, (pwr_eType)0, 0,
...@@ -718,7 +716,6 @@ int sev_server::check_histitems( sev_sMsgHistItems *msg, unsigned int size) ...@@ -718,7 +716,6 @@ int sev_server::check_histitems( sev_sMsgHistItems *msg, unsigned int size)
} }
} }
} }
printf( "---- Node up (%d) ----\n", nid);
return 1; return 1;
} }
...@@ -902,8 +899,6 @@ int sev_server::receive_events( sev_sMsgEventsStore *msg, unsigned int size) ...@@ -902,8 +899,6 @@ int sev_server::receive_events( sev_sMsgEventsStore *msg, unsigned int size)
for ( unsigned int i = 0; i < msg->NumEvents; i++) { for ( unsigned int i = 0; i < msg->NumEvents; i++) {
sev_event ev; sev_event ev;
printf( "Event Type %d Id %d text \"%s\"\n", ep->type, ep->eventid_idx, ep->eventtext);
ev.type = ep->type; ev.type = ep->type;
ev.eventprio = ep->eventprio; ev.eventprio = ep->eventprio;
ev.eventid.Nix = ep->eventid_nix; ev.eventid.Nix = ep->eventid_nix;
......
...@@ -1814,12 +1814,68 @@ int sev_dbms::store_event( pwr_tStatus *sts, int item_idx, sev_event *ep) ...@@ -1814,12 +1814,68 @@ int sev_dbms::store_event( pwr_tStatus *sts, int item_idx, sev_event *ep)
{ {
char query[400]; char query[400];
char timstr[40]; char timstr[40];
int rc;
*sts = time_AtoAscii( &ep->time, time_eFormat_NumDateAndTime, timstr, sizeof(timstr)); *sts = time_AtoAscii( &ep->time, time_eFormat_NumDateAndTime, timstr, sizeof(timstr));
if ( EVEN(*sts)) return 0; if ( EVEN(*sts)) return 0;
timstr[19] = 0; timstr[19] = 0;
// Check if event already exist
if ( m_items[item_idx].options & pwr_mSevOptionsMask_PosixTime) {
if ( m_items[item_idx].options & pwr_mSevOptionsMask_HighTimeResolution)
// Posix time, high resolution
sprintf( query, "select eventid_nix,eventid_idx,ntime from %s where time = %ld", m_items[item_idx].tablename, (long int)ep->time.tv_sec);
else
// Posix time, low resolution
sprintf( query, "select eventid_nix,eventid_idx from %s where time = %ld", m_items[item_idx].tablename, (long int)ep->time.tv_sec);
}
else {
if ( m_items[item_idx].options & pwr_mSevOptionsMask_HighTimeResolution)
// Sql time, high resolution
sprintf( query, "select eventid_nix,eventid_idx,ntime from %s where time = '%s'", m_items[item_idx].tablename, timstr);
else
// Sql time, low resolution
sprintf( query, "select eventid_nix,eventid_idx from %s where time = '%s'", m_items[item_idx].tablename, timstr);
}
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()));
}
MYSQL_RES *result = mysql_store_result( m_env->con());
if ( !result) {
printf("In %s row %d:\n", __FILE__, __LINE__);
printf( "%s Result Error\n", __FUNCTION__);
}
int rows = mysql_num_rows( result);
int found = 0;
unsigned int idx, nix, ntime;
for ( int i = 0; i < rows; i++) {
MYSQL_ROW row;
ntime = 0;
row = mysql_fetch_row( result);
if(row[0] != NULL) {
nix = strtoul(row[0], 0, 10);
idx = strtoul(row[1], 0, 10);
if ( m_items[item_idx].options & pwr_mSevOptionsMask_HighTimeResolution)
ntime = strtoul(row[2], 0, 10);
}
if ( ep->eventid.Nix == nix && ep->eventid.Idx == idx) {
if ( m_items[item_idx].options & pwr_mSevOptionsMask_HighTimeResolution) {
if ( ntime == ep->time.tv_nsec)
found = 1;
}
else
found = 1;
break;
}
}
mysql_free_result( result);
if ( found)
return 1;
if ( m_items[item_idx].options & pwr_mSevOptionsMask_PosixTime) { if ( m_items[item_idx].options & pwr_mSevOptionsMask_PosixTime) {
if ( m_items[item_idx].options & pwr_mSevOptionsMask_HighTimeResolution) { if ( m_items[item_idx].options & pwr_mSevOptionsMask_HighTimeResolution) {
// Posix time, high resolution // Posix time, high resolution
...@@ -1846,7 +1902,7 @@ int sev_dbms::store_event( pwr_tStatus *sts, int item_idx, sev_event *ep) ...@@ -1846,7 +1902,7 @@ int sev_dbms::store_event( pwr_tStatus *sts, int item_idx, sev_event *ep)
sprintf( query, "insert into %s (time, ntime, eventtype, eventprio, eventid_nix, eventid_birthtime," sprintf( query, "insert into %s (time, ntime, eventtype, eventprio, eventid_nix, eventid_birthtime,"
"eventid_idx, eventtext, eventname) values ('%s',%ld,%d,%d,%d,%d,%d,'%s','%s')", "eventid_idx, eventtext, eventname) values ('%s',%ld,%d,%d,%d,%d,%d,'%s','%s')",
m_items[item_idx].tablename, m_items[item_idx].tablename,
timstr, (long int)ep->time.tv_sec, timstr, (long int)ep->time.tv_nsec,
ep->type, ep->eventprio, ep->eventid.Nix, ep->eventid.BirthTime.tv_sec, ep->eventid.Idx, ep->eventtext, ep->type, ep->eventprio, ep->eventid.Nix, ep->eventid.BirthTime.tv_sec, ep->eventid.Idx, ep->eventtext,
ep->eventname); ep->eventname);
} }
...@@ -1861,7 +1917,7 @@ int sev_dbms::store_event( pwr_tStatus *sts, int item_idx, sev_event *ep) ...@@ -1861,7 +1917,7 @@ int sev_dbms::store_event( pwr_tStatus *sts, int item_idx, sev_event *ep)
} }
} }
int rc = mysql_query( m_env->con(), query); rc = mysql_query( m_env->con(), query);
if (rc) { if (rc) {
// printf( "Store value: %s \"%s\"\n", mysql_error(m_env->con()), query); // printf( "Store value: %s \"%s\"\n", mysql_error(m_env->con()), query);
*sts = SEV__DBERROR; *sts = SEV__DBERROR;
......
...@@ -1088,7 +1088,6 @@ pwr_tStatus rt_sevhistmon::mh_ack_bc( mh_sAck *msg) ...@@ -1088,7 +1088,6 @@ pwr_tStatus rt_sevhistmon::mh_ack_bc( mh_sAck *msg)
if ( shm->m_sevhistevents) if ( shm->m_sevhistevents)
shm->m_sevhistevents->evbuf_insert( &ed); shm->m_sevhistevents->evbuf_insert( &ed);
printf( "Ack\n");
return 1; return 1;
} }
...@@ -1108,7 +1107,6 @@ pwr_tStatus rt_sevhistmon::mh_return_bc( mh_sReturn *msg) ...@@ -1108,7 +1107,6 @@ pwr_tStatus rt_sevhistmon::mh_return_bc( mh_sReturn *msg)
if ( shm->m_sevhistevents) if ( shm->m_sevhistevents)
shm->m_sevhistevents->evbuf_insert( &ed); shm->m_sevhistevents->evbuf_insert( &ed);
printf( "Return\n");
return 1; return 1;
} }
...@@ -1128,7 +1126,6 @@ pwr_tStatus rt_sevhistmon::mh_alarm_bc( mh_sMessage *msg) ...@@ -1128,7 +1126,6 @@ pwr_tStatus rt_sevhistmon::mh_alarm_bc( mh_sMessage *msg)
if ( shm->m_sevhistevents) if ( shm->m_sevhistevents)
shm->m_sevhistevents->evbuf_insert( &ed); shm->m_sevhistevents->evbuf_insert( &ed);
printf( "Alarm\n");
return 1; return 1;
} }
...@@ -1148,7 +1145,6 @@ pwr_tStatus rt_sevhistmon::mh_block_bc( mh_sBlock *msg) ...@@ -1148,7 +1145,6 @@ pwr_tStatus rt_sevhistmon::mh_block_bc( mh_sBlock *msg)
if ( shm->m_sevhistevents) if ( shm->m_sevhistevents)
shm->m_sevhistevents->evbuf_insert( &ed); shm->m_sevhistevents->evbuf_insert( &ed);
printf( "Block\n");
return 1; return 1;
} }
...@@ -1168,7 +1164,6 @@ pwr_tStatus rt_sevhistmon::mh_cancel_bc( mh_sReturn *msg) ...@@ -1168,7 +1164,6 @@ pwr_tStatus rt_sevhistmon::mh_cancel_bc( mh_sReturn *msg)
if ( shm->m_sevhistevents) if ( shm->m_sevhistevents)
shm->m_sevhistevents->evbuf_insert( &ed); shm->m_sevhistevents->evbuf_insert( &ed);
printf( "Cancel\n");
return 1; return 1;
} }
...@@ -1188,19 +1183,16 @@ pwr_tStatus rt_sevhistmon::mh_info_bc( mh_sMessage *msg) ...@@ -1188,19 +1183,16 @@ pwr_tStatus rt_sevhistmon::mh_info_bc( mh_sMessage *msg)
if ( shm->m_sevhistevents) if ( shm->m_sevhistevents)
shm->m_sevhistevents->evbuf_insert( &ed); shm->m_sevhistevents->evbuf_insert( &ed);
printf( "Info\n");
return 1; return 1;
} }
pwr_tStatus rt_sevhistmon::mh_clear_alarmlist_bc( pwr_tNodeIndex nix) pwr_tStatus rt_sevhistmon::mh_clear_alarmlist_bc( pwr_tNodeIndex nix)
{ {
printf( "Clearalarmlist\n");
return 1; return 1;
} }
pwr_tStatus rt_sevhistmon::mh_clear_blocklist_bc( pwr_tNodeIndex nix) pwr_tStatus rt_sevhistmon::mh_clear_blocklist_bc( pwr_tNodeIndex nix)
{ {
printf( "Clearblocklist\n");
return 1; return 1;
} }
...@@ -1212,8 +1204,6 @@ void sev_sevhistevents::evbuf_insert( sev_sEvent *ev) ...@@ -1212,8 +1204,6 @@ void sev_sevhistevents::evbuf_insert( sev_sEvent *ev)
if ( event_buffer[idx].eventid_idx == ev->eventid_idx && if ( event_buffer[idx].eventid_idx == ev->eventid_idx &&
event_buffer[idx].eventid_nix == ev->eventid_nix && event_buffer[idx].eventid_nix == ev->eventid_nix &&
event_buffer[idx].eventid_birthtime == ev->eventid_birthtime) { event_buffer[idx].eventid_birthtime == ev->eventid_birthtime) {
printf( "Rejected type %d id %d \"%s\"\n", ev->type,
ev->eventid_idx, ev->eventtext);
return; return;
} }
if ( idx == evbuf_oldest) if ( idx == evbuf_oldest)
...@@ -1241,8 +1231,6 @@ void sev_sevhistevents::evbuf_insert( sev_sEvent *ev) ...@@ -1241,8 +1231,6 @@ void sev_sevhistevents::evbuf_insert( sev_sEvent *ev)
} }
memcpy( &event_buffer[evbuf_last], ev, sizeof(event_buffer[0])); memcpy( &event_buffer[evbuf_last], ev, sizeof(event_buffer[0]));
} }
printf( "Insert last %d oldest %d type %d id %d \"%s\"\n", evbuf_last, evbuf_oldest, event_buffer[evbuf_last].type,
event_buffer[evbuf_last].eventid_idx, event_buffer[evbuf_last].eventtext);
} }
void sev_sevhistevents::evbuf_send() void sev_sevhistevents::evbuf_send()
...@@ -1280,7 +1268,6 @@ void sev_sevhistevents::evbuf_send() ...@@ -1280,7 +1268,6 @@ void sev_sevhistevents::evbuf_send()
unsigned int ev_cnt = 0; unsigned int ev_cnt = 0;
if ( evbuf_sent == ev_cInit) { if ( evbuf_sent == ev_cInit) {
for ( unsigned int idx = evbuf_oldest;;) { for ( unsigned int idx = evbuf_oldest;;) {
printf("Send idx %d id %d\n", idx, event_buffer[idx].eventid_idx);
memcpy( &((sev_sMsgEventsStore *)put.data)->Events[ev_cnt], &event_buffer[idx], sizeof(sev_sEvent)); memcpy( &((sev_sMsgEventsStore *)put.data)->Events[ev_cnt], &event_buffer[idx], sizeof(sev_sEvent));
ev_cnt++; ev_cnt++;
evbuf_sent = idx; evbuf_sent = idx;
...@@ -1293,7 +1280,6 @@ void sev_sevhistevents::evbuf_send() ...@@ -1293,7 +1280,6 @@ void sev_sevhistevents::evbuf_send()
unsigned int start_idx = evbuf_sent; unsigned int start_idx = evbuf_sent;
evbuf_next_idx(start_idx); evbuf_next_idx(start_idx);
for ( unsigned int idx = start_idx;;) { for ( unsigned int idx = start_idx;;) {
printf("Send idx %d id %d\n", idx, event_buffer[idx].eventid_idx);
memcpy( &((sev_sMsgEventsStore *)put.data)->Events[ev_cnt], &event_buffer[idx], sizeof(sev_sEvent)); memcpy( &((sev_sMsgEventsStore *)put.data)->Events[ev_cnt], &event_buffer[idx], sizeof(sev_sEvent));
ev_cnt++; ev_cnt++;
evbuf_sent = idx; evbuf_sent = idx;
...@@ -1302,7 +1288,6 @@ void sev_sevhistevents::evbuf_send() ...@@ -1302,7 +1288,6 @@ void sev_sevhistevents::evbuf_send()
evbuf_next_idx(idx); evbuf_next_idx(idx);
} }
} }
printf( "Send num: %d cnt: %d\n", num, ev_cnt);
tgt.nid = monitor->m_hs[event_thread_idx].nid; tgt.nid = monitor->m_hs[event_thread_idx].nid;
tgt.qix = sev_eProcSevServer; tgt.qix = sev_eProcSevServer;
...@@ -1445,7 +1430,6 @@ int rt_sevhistmon::mainloop() ...@@ -1445,7 +1430,6 @@ int rt_sevhistmon::mainloop()
send_itemlist( get.sender.nid); send_itemlist( get.sender.nid);
break; break;
case sev_eMsgType_HistItemsRequest: case sev_eMsgType_HistItemsRequest:
printf("rt_sevhistmon: HistitemsRequest received\n");
send_itemlist( get.sender.nid); send_itemlist( get.sender.nid);
break; break;
case sev_eMsgType_ServerStatus: case sev_eMsgType_ServerStatus:
......
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