Skip to content

Commit 2892731

Browse files
authored
[influxdb] Improve connection handling (openhab#15879)
* [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 <[email protected]>
1 parent 1b466fb commit 2892731

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/InfluxDBPersistenceService.java

+1
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ private void commit() {
286286
if (!influxDBRepository.write(points)) {
287287
logger.warn("Re-queuing {} elements, failed to write batch.", points.size());
288288
pointsQueue.addAll(points);
289+
influxDBRepository.disconnect();
289290
} else {
290291
logger.trace("Wrote {} elements to database", points.size());
291292
}

bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/internal/influx2/InfluxDB2RepositoryImpl.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.influxdb.client.InfluxDBClientOptions;
4545
import com.influxdb.client.QueryApi;
4646
import com.influxdb.client.WriteApi;
47+
import com.influxdb.client.domain.HealthCheck;
4748
import com.influxdb.client.domain.Ready;
4849
import com.influxdb.client.domain.WritePrecision;
4950
import com.influxdb.client.write.Point;
@@ -76,7 +77,8 @@ public InfluxDB2RepositoryImpl(InfluxDBConfiguration configuration,
7677

7778
@Override
7879
public boolean isConnected() {
79-
return client != null;
80+
InfluxDBClient client = this.client;
81+
return client != null && client.health().getStatus() == HealthCheck.StatusEnum.PASS;
8082
}
8183

8284
@Override

0 commit comments

Comments
 (0)