From c9b281a25002b79c54b5e604b487b2ddd62030ee Mon Sep 17 00:00:00 2001 From: J-N-K Date: Sat, 11 Nov 2023 23:15:21 +0100 Subject: [PATCH] [influxdb] Improve connection handling (#15879) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [influxdb] Improve connection handling Especially for InfluxDB2 the connection check was not properly implemented. It only checked if a connections was ever successfully established. Since we removed the full crash when a write error occured, this lead to a situation where a broken connection was not detected. A ping is now implemented and also a failed write results in a disconnect. --------- Signed-off-by: Jan N. Klug Signed-off-by: Jørgen Austvik --- .../persistence/influxdb/InfluxDBPersistenceService.java | 1 + .../influxdb/internal/influx2/InfluxDB2RepositoryImpl.java | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/InfluxDBPersistenceService.java b/bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/InfluxDBPersistenceService.java index 358bd778a2eb2..ee2ba5190facb 100644 --- a/bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/InfluxDBPersistenceService.java +++ b/bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/InfluxDBPersistenceService.java @@ -286,6 +286,7 @@ private void commit() { if (!influxDBRepository.write(points)) { logger.warn("Re-queuing {} elements, failed to write batch.", points.size()); pointsQueue.addAll(points); + influxDBRepository.disconnect(); } else { logger.trace("Wrote {} elements to database", points.size()); } diff --git a/bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/internal/influx2/InfluxDB2RepositoryImpl.java b/bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/internal/influx2/InfluxDB2RepositoryImpl.java index 862ecf4c2ba31..77ef198009a2b 100644 --- a/bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/internal/influx2/InfluxDB2RepositoryImpl.java +++ b/bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/internal/influx2/InfluxDB2RepositoryImpl.java @@ -44,6 +44,7 @@ import com.influxdb.client.InfluxDBClientOptions; import com.influxdb.client.QueryApi; import com.influxdb.client.WriteApi; +import com.influxdb.client.domain.HealthCheck; import com.influxdb.client.domain.Ready; import com.influxdb.client.domain.WritePrecision; import com.influxdb.client.write.Point; @@ -76,7 +77,8 @@ public InfluxDB2RepositoryImpl(InfluxDBConfiguration configuration, @Override public boolean isConnected() { - return client != null; + InfluxDBClient client = this.client; + return client != null && client.health().getStatus() == HealthCheck.StatusEnum.PASS; } @Override