diff --git a/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java b/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java index c085111574012..b0d309560490a 100644 --- a/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java +++ b/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java @@ -205,6 +205,16 @@ private synchronized void internalStore(String name, double value, long now, boo return; } + try { + if (now < db.getLastUpdateTime()) { + logger.warn("RRD4J does not support adding past value this={}, last update={}. Discarding {} - {}", now, + db.getLastUpdateTime(), name, value); + return; + } + } catch (IOException ignored) { + // we can ignore that here, we'll fail again later. + } + ConsolFun function = getConsolidationFunction(db); if (function != ConsolFun.AVERAGE) { try { @@ -231,8 +241,8 @@ private synchronized void internalStore(String name, double value, long now, boo Sample sample = db.createSample(); sample.setTime(now); double storeValue = value; - if (db.getDatasource(DATASOURCE_STATE).getType() == DsType.COUNTER) { // counter values must be - // adjusted by stepsize + if (db.getDatasource(DATASOURCE_STATE).getType() == DsType.COUNTER) { + // counter values must be adjusted by stepsize storeValue = value * db.getRrdDef().getStep(); } sample.setValue(DATASOURCE_STATE, storeValue); @@ -247,8 +257,7 @@ private synchronized void internalStore(String name, double value, long now, boo job.cancel(true); scheduledJobs.remove(name); } - job = scheduler.schedule(() -> internalStore(name, value, now + 1, false), 1, TimeUnit.SECONDS); - scheduledJobs.put(name, job); + internalStore(name, value, now + 1, false); } else { logger.warn("Could not persist '{}' to rrd4j database: {}", name, e.getMessage()); }