From 497f999b7777e2328750c182342c01890a565c39 Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Thu, 21 Jan 2021 14:05:05 +0100 Subject: [PATCH] Try to be more resilient to influx write errors. --- gradle.properties | 2 +- .../java/biz/nellemann/hmci/InfluxClient.java | 22 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/gradle.properties b/gradle.properties index aaa63c4..7fe6ca1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ id = hmci group = biz.nellemann.hmci -version = 1.1.0 +version = 1.1.1 diff --git a/src/main/java/biz/nellemann/hmci/InfluxClient.java b/src/main/java/biz/nellemann/hmci/InfluxClient.java index 32d6ba2..b1a2d76 100644 --- a/src/main/java/biz/nellemann/hmci/InfluxClient.java +++ b/src/main/java/biz/nellemann/hmci/InfluxClient.java @@ -16,7 +16,6 @@ package biz.nellemann.hmci; import biz.nellemann.hmci.Configuration.InfluxObject; -import org.influxdb.BatchOptions; import org.influxdb.InfluxDB; import org.influxdb.InfluxDBFactory; import org.influxdb.dto.BatchPoints; @@ -36,8 +35,8 @@ class InfluxClient { private final static Logger log = LoggerFactory.getLogger(InfluxClient.class); - private static final int BATCH_ACTIONS_LIMIT = 5000; - private static final int BATCH_INTERVAL_DURATION = 1000; + //private static final int BATCH_ACTIONS_LIMIT = 5000; + //private static final int BATCH_INTERVAL_DURATION = 1000; final private String url; @@ -47,6 +46,7 @@ class InfluxClient { private InfluxDB influxDB; private BatchPoints batchPoints; + private int errorCounter = 0; InfluxClient(InfluxObject config) { @@ -64,7 +64,7 @@ class InfluxClient { } boolean connected = false; - int errors = 0; + int loginErrors = 0; do { try { @@ -75,7 +75,7 @@ class InfluxClient { connected = true; } catch(Exception e) { sleep(15 * 1000); - if(errors++ > 3) { + if(loginErrors++ > 3) { log.error("login() error, giving up - " + e.getMessage()); throw new RuntimeException(e); } else { @@ -105,11 +105,15 @@ class InfluxClient { synchronized void writeBatchPoints() throws Exception { log.debug("writeBatchPoints()"); try { - influxDB.writeWithRetry(batchPoints); + influxDB.write(batchPoints); } catch(Exception e) { - log.error("writeBatchPoints() error - " + e.getMessage()); - logoff(); - login(); + log.error("writeBatchPoints() error - " + e.getMessage(), e); + if(++errorCounter > 3) { + log.info("writeBatchPoints() trying to logout / login"); + errorCounter = 0; + logoff(); + login(); + } } }