Skip to content

Commit

Permalink
[influxdb] Improve connection handling (openhab#15879)
Browse files Browse the repository at this point in the history
* [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]>
Signed-off-by: Jørgen Austvik <[email protected]>
  • Loading branch information
J-N-K authored and austvik committed Mar 27, 2024
1 parent 4766b39 commit c9b281a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c9b281a

Please sign in to comment.