]> git.basschouten.com Git - openhab-addons.git/commitdiff
[influxdb] Improve connection handling (#15879)
authorJ-N-K <github@klug.nrw>
Sat, 11 Nov 2023 22:15:21 +0000 (23:15 +0100)
committerGitHub <noreply@github.com>
Sat, 11 Nov 2023 22:15:21 +0000 (23:15 +0100)
* [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 <github@klug.nrw>
bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/InfluxDBPersistenceService.java
bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/internal/influx2/InfluxDB2RepositoryImpl.java

index 358bd778a2eb2b3a6c14362c09ae44869e083c07..ee2ba5190facbf95fcdb361c2fc92791b52d4485 100644 (file)
@@ -286,6 +286,7 @@ public class InfluxDBPersistenceService implements ModifiablePersistenceService
             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());
             }
index 862ecf4c2ba31d3e353e7f903b0622f15387ab82..77ef198009a2b43e45b247145eeddd34866ed800 100644 (file)
@@ -44,6 +44,7 @@ import com.influxdb.client.InfluxDBClientFactory;
 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 class InfluxDB2RepositoryImpl implements InfluxDBRepository {
 
     @Override
     public boolean isConnected() {
-        return client != null;
+        InfluxDBClient client = this.client;
+        return client != null && client.health().getStatus() == HealthCheck.StatusEnum.PASS;
     }
 
     @Override