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
char orderby_part[80];
char jumpstr[40];
char where_part[200];
int rows;
if ( starttime && starttime->tv_sec == 0 && starttime->tv_nsec == 0)
starttime = 0;
......@@ -1620,7 +1621,7 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo
strcpy( column_part, "time,value");
if ( options & pwr_mSevOptionsMask_UseDeadBand)
strcpy( jumpstr, "or jump = 1");
strcpy( jumpstr, ""); // "or jump = 1" removed
else
strcpy( jumpstr, "");
......@@ -1634,6 +1635,7 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo
strcpy( orderby_part, "time");
}
for ( int k = 0; k < 2; k++) {
// 'where' part
if ( options & pwr_mSevOptionsMask_ReadOptimized) {
if ( starttime && endtime) {
......@@ -1711,8 +1713,8 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo
strcpy( where_part, "");
}
sprintf( query, "select %s from %s %s order by %s",
column_part, item.tablename, where_part, orderby_part);
sprintf( query, "select %s from %s %s order by %s limit %d",
column_part, item.tablename, where_part, orderby_part, maxsize*2);
rc = mysql_query( m_env->con(), query);
if (rc) {
......@@ -1729,9 +1731,23 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo
*sts = SEV__DBERROR;
return 0;
}
int rows = mysql_num_rows( result);
int bufrows = rows;
rows = mysql_num_rows( result);
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) {
......@@ -4062,10 +4078,10 @@ void sev_dbms::add_cache( int item_idx)
case pwr_eType_Int32:
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].scantime);
m_items[item_idx].scantime/2);
else
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);
break;
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