[rrd4j] fixed oom when requesting data and boundary=true (#14292)
* Fixed end date when requesting data using rrd4j and boundary=true Signed-off-by: Boris Krivonog <boris.krivonog@inova.si>
This commit is contained in:
parent
c162e6668d
commit
93d871a88f
|
@ -252,6 +252,12 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<HistoricItem> query(FilterCriteria filter) {
|
public Iterable<HistoricItem> query(FilterCriteria filter) {
|
||||||
|
ZonedDateTime filterBeginDate = filter.getBeginDate();
|
||||||
|
ZonedDateTime filterEndDate = filter.getEndDate();
|
||||||
|
if (filterBeginDate != null && filterEndDate != null && filterBeginDate.isAfter(filterEndDate)) {
|
||||||
|
throw new IllegalArgumentException("begin (" + filterBeginDate + ") before end (" + filterEndDate + ")");
|
||||||
|
}
|
||||||
|
|
||||||
String itemName = filter.getItemName();
|
String itemName = filter.getItemName();
|
||||||
|
|
||||||
RrdDb db = null;
|
RrdDb db = null;
|
||||||
|
@ -280,14 +286,11 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
|
||||||
}
|
}
|
||||||
|
|
||||||
long start = 0L;
|
long start = 0L;
|
||||||
// set end to {@link Instant#MAX} instead of current timestamp to enable requesting future time ranges including
|
long end = filterEndDate == null ? System.currentTimeMillis() / 1000
|
||||||
// boundary values via REST API
|
: filterEndDate.toInstant().getEpochSecond();
|
||||||
// see discussion in https://github.com/openhab/openhab-addons/pull/14238
|
|
||||||
long end = filter.getEndDate() == null ? Instant.MAX.getEpochSecond()
|
|
||||||
: filter.getEndDate().toInstant().getEpochSecond();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (filter.getBeginDate() == null) {
|
if (filterBeginDate == null) {
|
||||||
// as rrd goes back for years and gets more and more
|
// as rrd goes back for years and gets more and more
|
||||||
// inaccurate, we only support descending order
|
// inaccurate, we only support descending order
|
||||||
// and a single return value
|
// and a single return value
|
||||||
|
@ -296,7 +299,7 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
|
||||||
// query, which we want to support
|
// query, which we want to support
|
||||||
if (filter.getOrdering() == Ordering.DESCENDING && filter.getPageSize() == 1
|
if (filter.getOrdering() == Ordering.DESCENDING && filter.getPageSize() == 1
|
||||||
&& filter.getPageNumber() == 0) {
|
&& filter.getPageNumber() == 0) {
|
||||||
if (filter.getEndDate() == null) {
|
if (filterEndDate == null) {
|
||||||
// we are asked only for the most recent value!
|
// we are asked only for the most recent value!
|
||||||
double lastValue = db.getLastDatasourceValue(DATASOURCE_STATE);
|
double lastValue = db.getLastDatasourceValue(DATASOURCE_STATE);
|
||||||
if (!Double.isNaN(lastValue)) {
|
if (!Double.isNaN(lastValue)) {
|
||||||
|
@ -315,13 +318,13 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
|
||||||
"rrd4j does not allow querys without a begin date, unless order is descending and a single value is requested");
|
"rrd4j does not allow querys without a begin date, unless order is descending and a single value is requested");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
start = filter.getBeginDate().toInstant().getEpochSecond();
|
start = filterBeginDate.toInstant().getEpochSecond();
|
||||||
}
|
}
|
||||||
|
|
||||||
// do not call method {@link RrdDb#createFetchRequest(ConsolFun, long, long, long)} if start > end to avoid
|
// do not call method {@link RrdDb#createFetchRequest(ConsolFun, long, long, long)} if start > end to avoid
|
||||||
// an IAE to be thrown
|
// an IAE to be thrown
|
||||||
if (start > end) {
|
if (start > end) {
|
||||||
logger.warn("Could not query rrd4j database for item '{}': start ({}) > end ({})", itemName, start,
|
logger.debug("Could not query rrd4j database for item '{}': start ({}) > end ({})", itemName, start,
|
||||||
end);
|
end);
|
||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue