Commit 5fc045ca authored by Claes Sjofors's avatar Claes Sjofors

Sev mysql, policy when selecting values with deadband changed

parent 6618e0c6
...@@ -1482,6 +1482,7 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo ...@@ -1482,6 +1482,7 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo
char orderby_part[80]; char orderby_part[80];
char jumpstr[40]; char jumpstr[40];
char where_part[200]; char where_part[200];
int rows;
if ( starttime && starttime->tv_sec == 0 && starttime->tv_nsec == 0) if ( starttime && starttime->tv_sec == 0 && starttime->tv_nsec == 0)
starttime = 0; starttime = 0;
...@@ -1620,7 +1621,7 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo ...@@ -1620,7 +1621,7 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo
strcpy( column_part, "time,value"); strcpy( column_part, "time,value");
if ( options & pwr_mSevOptionsMask_UseDeadBand) if ( options & pwr_mSevOptionsMask_UseDeadBand)
strcpy( jumpstr, "or jump = 1"); strcpy( jumpstr, ""); // "or jump = 1" removed
else else
strcpy( jumpstr, ""); strcpy( jumpstr, "");
...@@ -1634,6 +1635,7 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo ...@@ -1634,6 +1635,7 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo
strcpy( orderby_part, "time"); strcpy( orderby_part, "time");
} }
for ( int k = 0; k < 2; k++) {
// 'where' part // 'where' part
if ( options & pwr_mSevOptionsMask_ReadOptimized) { if ( options & pwr_mSevOptionsMask_ReadOptimized) {
if ( starttime && endtime) { if ( starttime && endtime) {
...@@ -1711,8 +1713,8 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo ...@@ -1711,8 +1713,8 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo
strcpy( where_part, ""); strcpy( where_part, "");
} }
sprintf( query, "select %s from %s %s order by %s", sprintf( query, "select %s from %s %s order by %s limit %d",
column_part, item.tablename, where_part, orderby_part); column_part, item.tablename, where_part, orderby_part, maxsize*2);
rc = mysql_query( m_env->con(), query); rc = mysql_query( m_env->con(), query);
if (rc) { if (rc) {
...@@ -1729,9 +1731,23 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo ...@@ -1729,9 +1731,23 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo
*sts = SEV__DBERROR; *sts = SEV__DBERROR;
return 0; return 0;
} }
int rows = mysql_num_rows( result); rows = mysql_num_rows( result);
int bufrows = rows;
if ( k == 0 &&
options & pwr_mSevOptionsMask_UseDeadBand &&
rows < maxsize / 3 &&
rows != 0 &&
div != 1) {
// Try another read with smaller div
printf( "Retry: %d old dev: %d, new div %d\n", rows, div, div * rows / maxsize + 1);
if ( div == div * rows / maxsize + 1)
break;
div = div * rows / maxsize + 1;
mysql_free_result( result);
}
else break;
}
int bufrows = rows;
if ( options & pwr_mSevOptionsMask_ReadOptimized) { if ( options & pwr_mSevOptionsMask_ReadOptimized) {
...@@ -4062,10 +4078,10 @@ void sev_dbms::add_cache( int item_idx) ...@@ -4062,10 +4078,10 @@ void sev_dbms::add_cache( int item_idx)
case pwr_eType_Int32: case pwr_eType_Int32:
if ( m_items[item_idx].options & pwr_mSevOptionsMask_DeadBandMeanValue) if ( m_items[item_idx].options & pwr_mSevOptionsMask_DeadBandMeanValue)
m_items[item_idx].cache = new sev_valuecache_double( sev_eCvType_Mean, m_items[item_idx].deadband, m_items[item_idx].cache = new sev_valuecache_double( sev_eCvType_Mean, m_items[item_idx].deadband,
m_items[item_idx].scantime); m_items[item_idx].scantime/2);
else else
m_items[item_idx].cache = new sev_valuecache_double( sev_eCvType_Point, m_items[item_idx].deadband, m_items[item_idx].cache = new sev_valuecache_double( sev_eCvType_Point, m_items[item_idx].deadband,
m_items[item_idx].scantime); m_items[item_idx].scantime/2);
m_items[item_idx].cache->set_write_cb( write_db_cb, this, item_idx); m_items[item_idx].cache->set_write_cb( write_db_cb, this, item_idx);
break; break;
case pwr_eType_Boolean: case pwr_eType_Boolean:
......
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